[Solved] How to make the script jump to sleep?

Hi Gurus,

I am working one below script. I am stuck at the else condition.

#!/bin/ksh
        while :
        do
        cur_date=`date |cut -d"," -f 1`
		cur_time=`date +"%H%M"
        if [ "$cur_date" != "Saturday" ]||[ "$cur_date" != "Sunday" ]; then
                if [ ! -f $FIRST_FILE ] && [ $cur_time -ge 2200 ]; then
                                echo "File " $FIRST_FILE " doesn't exist!"
                                        exit 30
                elif
			   [ ! -f $FIRST_FILE ] && [ $cur_time -le 2200 ]; then
			      "here I want to the script jump to sleep directly without execute the below loop."
	        else
                                fyr=`ls -e $FIRST_FILE |awk '{print $9}'`
                                echo $fyr
                                mth=`ls -e $FIRST_FILE |awk '{print $6}'`
                                dy=`ls -e $FIRST_FILE |awk '{printf "%0.2d\n", $7}'`
                                time=`ls -e $FIRST_FILE |awk '{print $8}'`
                                echo "arr, start_file, $file, $fyr, $mth, $dy, $time" >> "$SRCDIR"/arr_code_list
                fi
        fi
                while IFS="," read code folder file suffix
                do
                        filedir="$SRCDIR"/"$folder"
                        inputfile="$filedir"/"$file"
                        suffix=$suffix

                        if [ -f ${inputfile}[0-9]*${suffix} ] ; then
                                ofile=`ls -1tr $inputfile*|head -1`
                                mth=`ls -e $ofile |awk '{print $6}'`
                                dy=`ls -e $ofile |awk '{printf "%0.2d\n", $7}'`
                                time=`ls -e $ofile |awk '{print $8}'`
                                yr=`ls -e $ofile|awk '{print $9}'`
                                echo "$code, $file, $yr, $mth, $dy, $time" >> "$SRCDIR"/arr_code_list
                        else
                                echo "$code, $folder, $file, NOT FOUND" >>"$TGTDIR"/not_arrival_list
                        fi

                done < $FEED_LIST

                sleep 900
done

the script checks file every 15 minutes
the requirement as like below
for weekday, then check $FIRST_FILE first,
if $FIRST_FILE arrived before 10:00Pm, then checking rest file,
if $FIRST_FILE not arrive before 10:00pm then sleep 15 minutes then start loopping again.
if $FIRST_FILE not found after 10:00pm, script exit with error code.
for weekend only checking other files without checking $FIRST_FILE;

in above script, I don't know how to jump to sleep if the $FIRST_FILE not arrival but time is early then 10:00 PM. (highlited in red)

Anybody can give me some idea.

Thanks in advance

is it a elseif or else before your red patching...

Thansk for catching, there is type. it is elseif, I want to add something after elseif then jump to sleep.

Difficult for me to visualise, wondering if a break would do the the trick, with the elsif rather than a else if I am a bit lost with your indentation... ( and I have a poor eyesight...)
(changed glasses...)
seems not... You would have to add a flag in that if, then add an extra if condition for the second part using the flag (just before while IFS=...

1 Like

Thanks for your reply. you mean as below, right?

# in my elif 
[ ! -f $FIRST_FILE ] && [ $cur_time -le 2200 ]; then
flag==0
...
# in my second while add
if [ flag -eq 1]; then 
   while IFS=",", read ...
   .
   .
   done < $FEED_LIST
fi
sleep 900

yes...

1 Like

Thanks, it works.

:b:

How about

sleep 900; continue

?

:cool: