#!/bin/ksh
while :
do
cat /dev/null > srcfile
exit_time=`TZ=GMT-20 date +%Y%m%d1950`
cur_time=`date +%Y%m%d%H%M`
flag=1
if [ ! -f unprocessed ]; then
echo "FILE CHECKING STARTING" > unprocessed
fi
while IFS="," read code desc file
do
echo $file
echo $code
if [ -f $file* ] ; then
ofile=`ls -1tr|head -1`
mth=`ls -l $ofile* |awk '{print $6}'`
dy=`ls -l $ofile* |awk '{print $7}'`
time=`ls -l $ofile* |awk '{print $8}'`
echo "$code, $file, $mth, $dy, $time, FOUND"
echo "$code, $file, $mth, $dy, $time" >> srcfile
else
flag=0
echo "$code, $file , NOT FOUND" >>notexist
fi
done < list
echo "Variable flag values is " $flag
end_time=`date +"%m-%d-%Y:%T"`
if [ $flag -eq 1 ]; then
echo "ALL FEED FOUND" >notexist
echo "File checking complete. All files arrived before $end_time" > filecheckingstatus
exit 0
else
if [ $cur_time -ge $exit_time ]; then
cat unprocessed >> filecheckingstatus
exit 20
fi
fi
echo "Current day and time is " `date +%d%H%M`
sleep 120
echo "Current day and time is " `date +%d%H%M`
done
in my file "list" only one record and there is no this file in current dir.
Code:
abc,aaa,file1
when running debug, I got below:
Code:
+ cat /dev/null
+ date +%Y%m%d1950
TZ=GMT-20
exit_time=201310171950
+ date +%Y%m%d%H%M
cur_time=201310161238
flag=1
+ [ ! -f unprocessed ]
IFS=,
+ read code desc file
+ echo file1
file1
+ echo abc
abc
+ [ -f file1* ]
+ cat /dev/null
flag=0
+ echo abc, file1 , NOT FOUND
IFS=,
+ read code desc file
+ echo Variable flag values is 1
Variable flag values is 1
+ date +%m-%d-%Y:%T
end_time=10-16-2013:12:38:40
+ [ 1 -eq 1 ]
+ echo ALL FEED FOUND
+ echo File checking complete. All files arrive on time
File checking complete. All files arrive on time
+ echo File checking complete. All files arrived before 10-16-2013:12:38:40
+ exit 0
for the value of $flag, it should be 0, but it return 1 in my current script.
Is this because the while loop has one more read (see highlighted in blue) which causes the variable has no value been assigned, so it pick up ini value?
any body can help this
At first glance, the reversion in $flag's value suggests that the inner while-loop is running in a subshell environment, but that shouldn't be the case.
Exactly which shell version and operating system is this script run on?
At first glance, the reversion in $flag's value suggests that the inner while-loop is running in a subshell environment, but that shouldn't be the case.
Exactly which shell version and operating system is this script run on?
Can you be more specific regarding the source of the problem and the solution? As it stands, your last post would not be of any help to someone else confronted with the same problem. And, personally, I'm curious how that while-loop landed in a subshell (if that is indeed what happened).
Can you be more specific regarding the source of the problem and the solution? As it stands, your last post would not be of any help to someone else confronted with the same problem. And, personally, I'm curious how that while-loop landed in a subshell (if that is indeed what happened).
Regards,
Alister
to be honest, I don't know why.
when I first run the script I use:
sh scriptname
it gave me error.
when using ksh scriptname
I got correct result
Would you please explain what is different sh xxx and ksh xxx.