Help reuired regarding the script

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

Help reuired regarding the script

Postby mashkoor.qadir » Fri Jan 27, 2012 4:19 pm

Dear All,


I'im new in bash scripting and i have to make script that cat the files from a folder and its sub folders and redirect its out put with same name in destination folder, so for i have written code that only shows all the files inside folders and its sub folders but neither it cat the files nor send it to the destination, can any body let me know where is the mistake here is code

#!/bin/bash

SRC=/var/log
DEST=/home/aar/log

IFS=$'\n'

for dir in `ls "$SRC/"`
do
if [ -d "$DEST/$dir" ] ; then
for f in `ls "$SRC/$dir"`
do
if [ -f "$DEST/$dir/$f" ] ; then
cat "$SRC/${f}" > "$DEST/${f}"
fi
done
fi
done
echo
echo "DONE"
echo
mashkoor.qadir
Lance Naik
 
Posts: 32
Joined: Mon Dec 20, 2010 10:27 pm
Yahoo Messenger: mashkoor.qadir@yahoo.com
Location: Karachi

Re: Help reuired regarding the script

Postby azfar » Wed Feb 01, 2012 9:57 pm

Code: Select all


#!/bin/sh

SRC=/root/scripts/input/
DEST=/root/scripts/output/
cd $SRC
for dir in `find -type d | cut -d"." -f 2`
do
mkdir -p $DEST/$dir
done

for file in `find -type f`
do
cat $file > $DEST/$file
done



Let me know if it suit you.
Azfar Hashmi
Email : azfarhashmi@hotmail.com
azfar
Captain
 
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
WLM: azfarhashmi@hotmail.com
Yahoo Messenger: azfarhusain@yahoo.com
Location: Karachi

Re: Help reuired regarding the script

Postby mashkoor.qadir » Thu Feb 02, 2012 3:48 pm

Waaaooooo Great it works for me,,,,,,,

Thanks
dear Azfar Hashmi
mashkoor.qadir
Lance Naik
 
Posts: 32
Joined: Mon Dec 20, 2010 10:27 pm
Yahoo Messenger: mashkoor.qadir@yahoo.com
Location: Karachi

Re: Help reuired regarding the script

Postby azfar » Thu Feb 02, 2012 6:27 pm

glad your problem is solved. btw i feel stupid after making the script because in general it is just copying all files and folders to a another directory which can be done by 'cp' command simply :)

what was your exact scenario?
Azfar Hashmi

Email : azfarhashmi@hotmail.com
azfar
Captain
 
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
WLM: azfarhashmi@hotmail.com
Yahoo Messenger: azfarhusain@yahoo.com
Location: Karachi


Return to “%s” Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron