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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] How to make the script jump to sleep?
# 1  
Old 01-17-2014
[Solved] How to make the script jump to sleep?

Hi Gurus,

I am working one below script. I am stuck at the else condition.
Code:
#!/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

Last edited by ken6503; 01-17-2014 at 01:14 PM..
# 2  
Old 01-17-2014
is it a elseif or else before your red patching...
# 3  
Old 01-17-2014
Quote:
Originally Posted by vbe
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.
# 4  
Old 01-17-2014
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=...

Last edited by vbe; 01-17-2014 at 01:12 PM..
This User Gave Thanks to vbe For This Post:
# 5  
Old 01-17-2014
Quote:
Originally Posted by vbe
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=...
Thanks for your reply. you mean as below, right?
Code:
# 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


Last edited by vbe; 01-17-2014 at 01:44 PM..
# 6  
Old 01-17-2014
yes...
This User Gave Thanks to vbe For This Post:
# 7  
Old 01-17-2014
Quote:
Originally Posted by vbe
yes...
Thanks, it works.

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run script when computer resume from being sleep state

I use this as a startup program. Is there a way that it could run when my computer returns from a sleep state? Cpu_LogFile="/home/andy/bin/CPU_Fan_Info.txt" date +"%Y-%m-%d-%H:%M:%S" >> $Cpu_LogFile sensors -f | grep "temp4" >> $Cpu_LogFile sensors -f | grep "fan1" >> $Cpu_LogFile (5 Replies)
Discussion started by: drew77
5 Replies

2. Shell Programming and Scripting

Sleep then start over from beginning of script

Hi all, I have a bash script in which it runs multiple if conditions if a word count from a grep is equal to a number. When this number is not reached I want to sleep for very few seconds (let's say 3) and start over again, till it matches the word count of 8. Here's a sample of the code so... (6 Replies)
Discussion started by: nms
6 Replies

3. Shell Programming and Scripting

Notify when the script run(hourly)on my jump-box only when there is a failure on my remote-box

Team, Presently I have a script, which i have set up cron on one of my Jump-boxes,and gives me the output on every hourly basis,fetching the data from the remote machine.Basically it gives me the list of all active users logged and its count once we execute the script.Here the count is... (6 Replies)
Discussion started by: whizkidash
6 Replies

4. Shell Programming and Scripting

Alternate to SLEEP for EXPECT within BASH script?

Fairly new to the System Admin world, and this is my first post here, hoping to get some clarification. I am using a BASH script to automate some Logfile Archiving (into .tars). The actual logfiles are accessed through an SSH, so I have used the following EXPECT sub-script within my main BASH... (8 Replies)
Discussion started by: Goatfarmer03
8 Replies

5. Shell Programming and Scripting

How to make the script to sleep for 30 min..?

Hi I have a script 'A' after it runs i want to sleep this for 30 min, after 30 min it should re run. How do i do that ..! thanks in advance (1 Reply)
Discussion started by: happydays
1 Replies

6. Shell Programming and Scripting

script to check for existence of file (or else sleep for x time)

Hi Forum. I have a script that accepts 3 input parameters (source directory, list file text, sleep time) and checks for the presence of files. If not there, script goes to sleep for certain amount of time provided by 3rd input. list file text contains 1 entry but may contain more (file... (13 Replies)
Discussion started by: pchang
13 Replies

7. Shell Programming and Scripting

Kill a Script based on the pid and sleep

I would want to run a code for 1 min and if it doesnt succeed in 1 min..I would want to exit it..I am using the following code...But the script is not going into my code part.It is waiting for 60 secs and then getting killed. The code which is in the while loop actually takes less than 60 secs...... (6 Replies)
Discussion started by: infernalhell
6 Replies

8. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

9. Shell Programming and Scripting

help - script can check jump sequence?

Hi, if I have a lot of files like (AABBCC0010, AABBCC0011, AABBCC0012....AABBCC1000), can I write a small script to check any sequence number jump and show me the result which sequence number? #The first sequence may start from 0010 or 0101... :confused: Thank you!! (10 Replies)
Discussion started by: happyv
10 Replies

10. Shell Programming and Scripting

how to start a process and make it sleep for 5 mins and then kill that process

how to start a process and make it sleep for 5 mins and then kill that process (6 Replies)
Discussion started by: shrao
6 Replies
Login or Register to Ask a Question