Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a sort of "loop" with cron.

Status
Not open for further replies.

Geek8

Programmer
Apr 23, 2003
31
US
Hi.
The subject may be a bit odd, but what I want to do is create a cron job that will run every evening on the hour from 7pm till 2am. The job will go out and get a file from our server and check this file against counts that already exist on our current machine. If the file matches the counts then the cron job should stop, else keep going till it gets the correct file. If it makes it through 2am and still has not gotten a file, then send me an email letting me know this. I know this may sound like a lot of stuff, but I was basically wondering if anyone has any idea on how to perhaps setup something like this. I am not sure if there is someway to do this in a loop or something similar. Any help or direction you guys/gals may have would be much appreciated. I have been trying to rack my brain all day on how to do something like this.

Thanks in advance,

Geek8
 
something like that. Schedule this in cron like so - '7' stands for 7 hours (between 7pm and 2am):
0 7 * * * /path2GeekSript 7


And here's the script - you'll have to implement some of the 'pseudo-code' - that's left as an exercise:

Code:
#!/bin/ksh

typeset -i numHours="${1}"
typeset -i cnt=1;

# sleep - 1 hour
typeset -i sleepTime=$(( 60 * 60 ))

while [ "${cnt}" -le "${numHours}" ]
do
    # get your file
    # compare against 'counts' - what ever it means
    if [ FILE is as the 'counts' ];
       exit 0;
    fi;
    cnt=$((cnt + 1))
    sleep "${sleepTime}"
done

# do your emailing here - something like that

mailx -s 'Count Failed for File" myAddress@foo.com <<EOF
.
EOF

exit 1;

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top