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
Help reuired regarding the script
-
- Lance Naik
- Posts: 32
- Joined: Mon Dec 20, 2010 10:27 pm
- Location: Karachi
- Contact:
Re: Help reuired regarding the script
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
Azfar Hashmi
Email : azfarhashmi@hotmail.com
Email : azfarhashmi@hotmail.com
-
- Lance Naik
- Posts: 32
- Joined: Mon Dec 20, 2010 10:27 pm
- Location: Karachi
- Contact:
Re: Help reuired regarding the script
Waaaooooo Great it works for me,,,,,,,
Thanks
dear Azfar Hashmi
Thanks
dear Azfar Hashmi
Re: Help reuired regarding the script
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?
what was your exact scenario?
Azfar Hashmi
Email : azfarhashmi@hotmail.com
Email : azfarhashmi@hotmail.com