Help reuired regarding the script

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
mashkoor.qadir
Lance Naik
Posts: 32
Joined: Mon Dec 20, 2010 10:27 pm
Location: Karachi
Contact:

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

azfar
Captain
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
Location: Karachi
Contact:

Re: Help reuired regarding the script

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

Azfar Hashmi
Email : azfarhashmi@hotmail.com

mashkoor.qadir
Lance Naik
Posts: 32
Joined: Mon Dec 20, 2010 10:27 pm
Location: Karachi
Contact:

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

azfar
Captain
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
Location: Karachi
Contact:

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests