Name: Kalyan_Unix Date: January 31, 2008 at 07:21:06 Pacific Subject: Can someone help wid KSH script err OS: Unix CPU/Ram: Intel
Comment:
Hi All:
I am a newbie for ksh scripting.My code doesn't work. Can someone help? I am trying to automate the process of file read from a directory. The files older than 3 days are supposed to be archived. If they are in the three day limit, then they can be processed as a comand lien to a C program. Here is the script:
#!/usr/bin/ksh checkduration=259200 # 3 days in seconds cur_timestamp=`date +%s` #current time in seconds
cd /home/roab/toc/; # change dir for i in /home/roab/toc/*; do if [ -f $i ]; then # if the file is there filename=${i#/home/roab/toc};# get file name last_mod=$(stat -c "%Y" ${i#/home/roab/toc}); # get last mod time of file in seconds last_mod=$(stat -c "%Y" filename) #above line gathers file modified time in seconds from epoch
if [ $last_mod ] then time_diff=`expr $cur_timestamp - $last_mod`; #cal time difference 3 days or more if [ $time_diff -lt $checkduration ] # file modified three days or less back then mv ${i#/home/roab/toc} /home/roab/old_data; #if more then move to a new folder else /root/home/source/programs/abc.out filename; # if not call c program with filename as argument cat filename>>log; #append this file name to log sheet fi fi fi
the following are the errors: stat: cannot stat `/22018-000181': No such file or directory stat: cannot stat `/22018-000182': No such file or directory stat: cannot stat `/22018-000183': No such file or directory stat: cannot stat `/22018-000184': No such file or directory stat: cannot stat `/22018-000185': No such file or directory stat: cannot stat `/22018-000186': No such file or directory stat: cannot stat `/22018-000187': No such file or directory