Help reuired regarding the script

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

Help reuired regarding the script

Post by mashkoor.qadir »

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
Kind Regards,
Mashkoor Qadir,
mashkoor.qadir@yahoo.com
http://www.redmath.com
azfar
Captain
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
Location: Karachi
Contact:

Re: Help reuired regarding the script

Post by azfar »

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
mashkoor.qadir
Lance Naik
Posts: 32
Joined: Mon Dec 20, 2010 10:27 pm
Location: Karachi
Contact:

Re: Help reuired regarding the script

Post by mashkoor.qadir »

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

Thanks
dear Azfar Hashmi
Kind Regards,
Mashkoor Qadir,
mashkoor.qadir@yahoo.com
http://www.redmath.com
azfar
Captain
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
Location: Karachi
Contact:

Re: Help reuired regarding the script

Post by azfar »

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
Post Reply