Operating System - HP-UX
1830940 Members
1932 Online
110017 Solutions
New Discussion

How to wite a unix shell script to execute a unix script at 8:00 PM

 
SOLVED
Go to solution
Suman_7
Frequent Advisor

How to wite a unix shell script to execute a unix script at 8:00 PM

Can someone send me a simple sample script that helps to kick off a unix script exec.sh automatically at 8:00 PM at 08-31-2005 only.

Thanks a lot!!
11 REPLIES 11
Suman_7
Frequent Advisor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

I don't have access to crontab file so I can't use unix cron job
Alan Meyer_4
Respected Contributor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

Do you have access to the at command?

at -f /filesystem/script -t200508312000.00

that command runs the script /filesystem/script at 8:00pm on 08/31/2005
" I may not be certified, but I am certifiable... "
James R. Ferguson
Acclaimed Contributor
Solution

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

Hi Suman:

The simplest approach is to use 'at' given that your account has been granted permission in '/var/adm/cron/at.allow'. Then, simply do:

# at -f /your_script -t 08312000

If you don't have permisssion to do 'at' jobs (nor 'cron' tasks) then for a one time script you could launch this:

#!/usr/bin/sh
typeset CMD=date #...replace with your executable name
while true
do
WHEN=`date +"%H%M`
echo ${WHEN}
[ "${WHEN}" -ge 2000 ] && { ${CMD}; exit 0; }
sleep 60
done

Regards!

...JRF...
Suman_7
Frequent Advisor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

Unfortunately I don't have access to at command either. Can you send me an infinite loop that check for condition 08-31-2005 8:00:00 PM every 30 minutes and kicks off the jobs and then exits the loop.

Thanks
Tim Nelson
Honored Contributor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

I guess if you really cannot use the cron scheduler then something like the below would work. (warning the below is simplistic and somewhat lame but the idea is there)

DONE=0
while [[ $DONE != 1 ]]
if [[ `date` = "Wed Aug 31 20:00:00 CDT 2005"]]
then
#execute script
DONE=1
else
sleep 5
fi
Tim Nelson
Honored Contributor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

you may have to change the sleep to 1 so you do not miss the half seconds.

Suman_7
Frequent Advisor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

Tim I am getting syntax error at line 9
I am on sun box.

DONE=0
while [[ $DONE != 1 ]]
if [[ `date` = "Wed Aug 31 16:00:00 CDT 2005"]]
then
exec1.sh
DONE=1
else
sleep 5
fi
Tim Nelson
Honored Contributor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

Sun, HP forums ?

#!/usr/bin/ksh
DONE=0
while [[ $DONE != 1 ]]
do
if [[ `date` = "Wed Aug 31 16:00:00 CDT 2005"]]
then
exec1.sh
DONE=1
else
sleep 5
fi
done

(SORRY, forgot to close the while loop)

you might also have to watch the date format on solaris. We are lamely looking at the textual date format and there are much better ways to do this.

You can even just go after the time i.e. date +%T or some fashion of that.

I hope this gives you the idea.
Suman_7
Frequent Advisor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

Got it to work . thanks to both of you guys
Tim Nelson
Honored Contributor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

ur welcome
Sandman!
Honored Contributor

Re: How to wite a unix shell script to execute a unix script at 8:00 PM

Suman,

It can be done if you have access to "at" otherwise not. Here's a template you can use to create a script that schedules another:

=============================================
#!/bin/sh

echo Schedules another script to run on August 31st at 800pm

at 8:00 pm August 31 <