HI
I have a requirement to find the last updated files from a directory whcih has subdirectories and inside them we have files with .txt,.doc,.xls .. extensions. i have to find those files which were updated in the last 1hr and rename the files with respective <sub-directory>_<filename> and copy them to another directory.
i'm able to browse the threads of this forum and found the code to find the last updated files.. but don't know how to find and rename in the mentioned format.
Main directory:
/dataserver/
subdirectories:200906024502,200906024503,200906024520 etc,;
inside /dataserver/200906024502/abc.txt
/dataserver/200906024520 /sample.doc
etc;
ts=`date +%m%d%H%M`; ts=`expr $ts - 250`;touch -t 0$ts stamp1
find /dataserver/200906024502/ -type f -newer stamp1 -print
please help me with the script.
Thanks in advance.
-Ramesh
ts=`date +%m%d%H%M`; ts=`expr $ts - 250`;touch -t 0$ts stamp1
for file in $(find /dataserver -type f -newer stamp1 -print)
do
Newfile=$(echo $file |awk -F \/ '{for (i=3;i<=NF-1;i++) printf $i "_" ; printf $NF"\n"}' )
if [ ! -f /Other_folder/$Newfile ] then
echo cp $Newfile /Other_folder
fi
done
If the code is succesful, remove echo from the code.
I tried like this.. and it gives erros..
#!/bin/ksh
ts=`date +%m%d%H%M`;
ts=`expr $ts - 250`;
touch -t 0$ts stamp1
for file in $(find /dataserver/apps/upload/CARcomment/ -type f -newer stamp1 -print)
do
Newfile=$(echo $file | awk -F \/ '{for (i=3;i<=$NF-1;i++) printf $i "_" ; printf $NF"\n"}' )
if [ ! -f /dataserver/apps/upload/tempcopy/$Newfile ]
then
echo cp $Newfile /dataserver/apps/upload/tempcopy/
fi
done
#Remove time_stamp
rm stamp1
exit 0
error:
awk: syntax error near line 1
awk: bailing out near line 1
cp /dataserver/apps/upload/tempcopy/
awk: syntax error near line 1
awk: bailing out near line 1