System1
November 23, 2011, 8:46pm
1
Hi All,
I want to write a shell script that will find all the files modified
within 24 hours and copy those files into a new directory.
I have written the script but it is not working, it return me with all
the files instead of only those that modified within 24 hours.
Below is my script, appreciated if some one can help…
#!/bin/sh
DATE=date +%y%m%d
#################################################################################
Part 1 : Move IDM log files to log archive directory
#################################################################################
cd /var/opt/novell/log/
mkdir /data/daily_log_archive/IDM_log_$DATE
for i in ls
do
if find ./$i -mtime -1 -type f
then
cp $i /data/daily_log_archive/IDM_log_$DATE
fi
done
tar cvzfp /data/daily_log_archive/IDM_log_$DATE.tar.gz
/data/daily_log_archive/IDM_log_$DATE
rm -rf /data/daily_log_archive/IDM_log_$DATE
#################################################################################
–
kaylayap
kaylayap’s Profile: http://forums.novell.com/member.php?userid=94293
View this thread: http://forums.novell.com/showthread.php?t=448641
system
November 23, 2011, 9:03pm
2
On Wed, 23 Nov 2011 18:46:02 GMT
kaylayap kaylayap@no-mx.forums.novell.com wrote:
[color=blue]
Hi All,
I want to write a shell script that will find all the files modified
within 24 hours and copy those files into a new directory.
I have written the script but it is not working, it return me with all
the files instead of only those that modified within 24 hours.
Below is my script, appreciated if some one can help…
#!/bin/sh
DATE=date +%y%m%d
#################################################################################
Part 1 : Move IDM log files to log archive directory
#################################################################################
cd /var/opt/novell/log/
mkdir /data/daily_log_archive/IDM_log_$DATE
for i in ls
do
if find ./$i -mtime -1 -type f
then
cp $i /data/daily_log_archive/IDM_log_$DATE
fi
done
tar cvzfp /data/daily_log_archive/IDM_log_$DATE.tar.gz
/data/daily_log_archive/IDM_log_$DATE
rm -rf /data/daily_log_archive/IDM_log_$DATE
#################################################################################
[/color]
Hi
Do it all on one line, eg;
find . -type f -mtime -1 -exec ls {} \\;
You might be better of using rsync?
–
Cheers Malcolm °¿° (Linux Counter #276890 )
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.32.46-0.3-default
up 19:40, 2 users, load average: 0.00, 0.02, 0.00
GPU GeForce 8600 GTS Silent - Driver Version: 290.10
system
November 24, 2011, 5:06am
3
command "find ./$i -mtime -1 -type f " would return 0 even if it didn’t
find the file.
using “find … -exec” or “find … | xarg …” instead.
–
sammyjeep
sammyjeep’s Profile: http://forums.novell.com/member.php?userid=120054
View this thread: http://forums.novell.com/showthread.php?t=448641