- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help with writing a cron script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2004 10:48 AM
тАО06-20-2004 10:48 AM
Help with writing a cron script
I need to write an Inifinite Loop in Korn Sheel. This script is supposed to kick off every day at around 12:00 PM.
I wrote the script like this:
###################################################################
export FILE_DIR=$TOP/bin
if [ $# = 0 ]; then
interval=86400
elif [ "${1}" = "fast" ]; then
interval=900
else echo "Incorrect usage........."
echo "Execute without parmeter or with parameter 'fast' to execute in fast mode"
exit 1
fi
t=1000
while [ ${t} -le 1001 ];
do
switch_val=`head -1 auto_on_off.txt | awk '{print $1}'`
if [ "${switch_val}" = "on" ]; then
${FILE_DIR}/run_load_A_B.ksh db1 db2 db3
${FILE_DIR}/run_load_C.ksh db1 db2 db3
#sleep 86400
sleep ${interval}
echo "condition not yet fulfilled run again after 24 hrs"
else
a=1
#exit 1
fi
done
My Problem is that the scripts:
run_load_A_B.ksh
run_load_C.ksh
take 4-5 hours to run .
once they complete the script sleeps for 24 hours. and next dat it executes at the finish time of previois day.
How do I make sure it runs at a specific time each day provided previous day's run was completed.
The script runs in 2 modes normal and fast mode. I am concerned abt the normal mode ( every 24 hours )
Please suggest any good logic for this.
Thank You,
- Tags:
- sleep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2004 11:53 AM
тАО06-20-2004 11:53 AM
Re: Help with writing a cron script
0 12 * * * command
- Tags:
- crontab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2004 11:55 AM
тАО06-20-2004 11:55 AM
Re: Help with writing a cron script
You can download caljd.sh or caljd.pl from here:
http://www.cmve.net/~merijn/#Contrib
It is at the bottom of the page.
YESTERDAY_DATE=$(caljd.sh -s -y $(caljd.sh -p 1))
echo "Yesterday = ${YESTERDAY_DATE}"
TOMORROW_DATE=$(caljd.sh -s -y $(caljd.sh -n 1))
echo "Tomorrow = ${TOMORROW_DATE}"
Invoke as caljd.sh -u for full usage and many examples (like previous date plus skip over weekends).
- Tags:
- caljd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2004 12:01 PM
тАО06-20-2004 12:01 PM
Re: Help with writing a cron script
command1 &
command2 &
sleep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2004 12:05 PM
тАО06-20-2004 12:05 PM
Re: Help with writing a cron script
I can't let it run in the background because the users want the ability to turn it on and off as desitred by updating the auto_on_off.txt file to "on" or "off"
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2004 12:15 PM
тАО06-20-2004 12:15 PM
Re: Help with writing a cron script
Now, the executing of the script 1000 times can also be gotten rid of.
Simply, you could shorten the entire routine to something like this:
###########
# Start here
export FILE_DIR=$TOP/bin
LOCK_FILE=$0.lock
if [ ! -f "$LOCK_FILE" ]
then
touch "$LOCK_FILE"
switch_val=`head -1 auto_on_off.txt | awk '{print $1}'`
if [ "${switch_val}" = "on" ]; then
${FILE_DIR}/run_load_A_B.ksh db1 db2 db3
${FILE_DIR}/run_load_C.ksh db1 db2 db3
##
# Insert logic here checking for failures. If failed, don't do the next line:
if [ ..
then
rm -f "$LOCK_FILE"
fi
else
echo "Lock file still in place. Either a previous execution failed, or I was run multiple times."
fi
######################
And cron it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2004 09:08 PM
тАО06-20-2004 09:08 PM
Re: Help with writing a cron script
You are in need to start the script execution at 12.00 PM Everyday.But the application execution time (3-4hours) + the sleep time 24 hours (86400 seconds or 900 seconds) may leed to execute the execution on next day after 12.00 PM limit.
You have to use different logic for fast mode. It is good to use the log files to know the execution time and other informations.
Attached script will be helpful for this.
Regards,
Muthukumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2004 05:28 AM
тАО06-24-2004 05:28 AM
Re: Help with writing a cron script
elapsed=0
while :
do
head -1 auto_on_off.txt | read switch_val therest
if [[ "${switch_val}" = "on" ]]
then
${FILE_DIR}/run_load_A_B.ksh db1 db2 db3
${FILE_DIR}/run_load_C.ksh db1 db2 db3
sleep $((interval - elapsed))
elapsed=0
echo "condition not yet fulfilled run again after 24 hrs"
else
a=1
sleep 60
((elapsed += 60))
fi
done