- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Running One Instance of Script at a TIme via Cronj...
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
тАО12-13-2006 05:37 PM
тАО12-13-2006 05:37 PM
I am coming again with one more query,
We are scheduling the cronjob to run a script once in five minutes.
But now the issue is:
Sometimes the script takes more than 5 minutes to complete and the other instance of the same script started from the cron.
We don't know how to overcome from this issue.,
We want once the script completed then it needd to wait for 5 minutes and start the script again.
So the Time interval between the script_complete & Script_start is 5 Minutes.
----------------------
Is there any way to achieve this task
Regards
Suseendran .A
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2006 05:43 PM
тАО12-13-2006 05:43 PM
Re: Running One Instance of Script at a TIme via Cronjob
You could insert at the end of the script a:
sleep 300
line when the script's job is done.
So they will always be just one instance.
More difficult is to stay with cron but insert a proof at the beginning of the script:
ps -eaf | grep your_script_name || start your script's job... not with that syntax, but this way.
greetings,
alexander meyer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2006 05:45 PM
тАО12-13-2006 05:45 PM
Re: Running One Instance of Script at a TIme via Cronjob
my first solution has to be inserted in a while true loop.
script:
while true
do
your script's job
sleep 300
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2006 06:57 PM
тАО12-13-2006 06:57 PM
SolutionStop the cron or for time being remove this
script from crontab,
Set a flag say 'export STATUS=0' indicating previous instance
of script has finished in some files say file1.
through ur script at the beginning
modify ur script as follows
##Check for this flag at the beginning
. file1
if [ $STATUS -eq 0 ]
then
## Now set STATUS=1 indicating script is running.
echo "export STATUS=1" > file1
< part of ur script>
## After finishing set STATUS=0
echo "export STATUS=0" > file1
else
exit
fi
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2006 07:00 PM
тАО12-13-2006 07:00 PM
Re: Running One Instance of Script at a TIme via Cronjob
Forget to tell to restart cron / add ur script in crontab.
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2006 07:54 PM
тАО12-13-2006 07:54 PM
Re: Running One Instance of Script at a TIme via Cronjob
you can achieve this using "at":
at -f /path_to_script/script.sh +5 minutes > /dev/null
regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2006 08:04 PM
тАО12-13-2006 08:04 PM
Re: Running One Instance of Script at a TIme via Cronjob
Your points are true & acceptable But When The server is restarted then we need to start the task again..
But Santhosh is Right,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2006 08:10 PM
тАО12-13-2006 08:10 PM
Re: Running One Instance of Script at a TIme via Cronjob
I didn't fully understood the concept.,Where Do I insert the STATUS flag on my script and how will it work..
Regards
Suseendran ,A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2006 08:59 PM
тАО12-13-2006 08:59 PM
Re: Running One Instance of Script at a TIme via Cronjob
when the server is restarted, you will have a startup script that will start the at job.
create the script in /sbin/init.d/xxx
then configure it to start at the appropriate run level.
should not be something too complex!
hope this helps!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-14-2006 03:15 AM
тАО12-14-2006 03:15 AM
Re: Running One Instance of Script at a TIme via Cronjob
I didn't fully understood the concept.,Where Do I insert the STATUS flag on my script and how will it work
Ok, Let's go through Santosh's script. First off, in the example a file "file1" exists in the current directory. The contents of "file1" is either:
export STATUS=1
or
export STATUS=0
the contents will depend upon whether or not another copy of the script is already running.
1) ##Check for this flag at the beginning
2)
3) . file1
4) if [ $STATUS -eq 0 ]
5) then
6) ## Now set STATUS=1 indicating script is running.
7) echo "export STATUS=1" > file1
8) < part of ur script>
9) ## After finishing set STATUS=0
10) echo "export STATUS=0" > file1
11) else
12) exit
Line 3, "file1" is sourced, which makes the value of STATUS available to the rest of the script.
Line 4, check the current value of STATUS, if 0 continue executing the "then" block, begining in line 5
Line 7, update "file1" to indicate that a copy of the script is *now* running
Line 8, insert your commands/script here and it will run only one copy at a time
Line 10, update "file1" to reflect the job is complete and another job may run.
Line 11, null else *no action*
and finally, Line 12 exits.
==================================================
Now the issue is, do you really want the jobs to start every 5 minutes w/o running multiples concurrently? If so, "cron" and the Santosh's script using a lockfile will do this quite nicely.
If however; the goal is to have a 5 minute separation between the end of one job and the start of another, then insert the "at" command Yogeeraj noted at the end of your existing script. NOTE: this will cause the actual start times to vary, as it will be based on the end-time of the previous job, and as Yogeeraj also noted, you will need some kind of start-up/shutdown script to cope w/ reboots and shutdowns.
Hope this helps......