- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to prevent multiple sessions of a cron job
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
Forums
Discussions
Discussions
Discussions
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
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
07-23-2001 10:02 AM
07-23-2001 10:02 AM
Help is appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 10:07 AM
07-23-2001 10:07 AM
SolutionAt the start of the job, test for the existence of the file (say, /var/run/cron.whatever). If it exists, exit. If not, create it, perform primary task, and remove it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 10:58 AM
07-23-2001 10:58 AM
Re: How to prevent multiple sessions of a cron job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 11:10 AM
07-23-2001 11:10 AM
Re: How to prevent multiple sessions of a cron job
Not able to get to doc.id A5456417. :-(
May be I do not have access to it. Could you copy paste here.. thanks, appreciate it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 11:11 AM
07-23-2001 11:11 AM
Re: How to prevent multiple sessions of a cron job
Jordan's answer is almost perfect and it is the standard idiom. However, if this is a critical process, I would do one more thing.
When you create the lock file write the PID of the process as the contents of the lock file.
When you try to start the job, it the file is there and a ps -e finds that PID then exit otherwise start the process. This prevents a critical process from running when the last invocation died for some reason and did not remove the lock file.
My 2 cents, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 11:17 AM
07-23-2001 11:17 AM
Re: How to prevent multiple sessions of a cron job
Do you have a sample code for reference.. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 11:19 AM
07-23-2001 11:19 AM
Re: How to prevent multiple sessions of a cron job
Here is the original document(id:A5456417):
Problem Description
I have about 40 jobs on two different systems that are started by cron. Many of the jobs start at similar times. I want to know which
job has finished without having to go to the cronlog on each system.
How do I set up cron to identify jobs when it sends me mail?
Configuration Info
Operating System - HP-UX
Version - 10.20
Hardware System - HP9000
Series - K460
Solution
When cron sends mail, it is generally mailing the stdout and stderr of the job that has executed. If you want specific information, the best way is to redirect your stdout and stderr into a file that has a header containing the job name. After the job is complete, make the script that runs the job e-mail the file.
Example cron entry:
* * * * * /usr/local/bin/myscript.sh > /tmp/myscript.out 2>&1
Example lines in myscript.sh:
#!/usr/bin/sh
echo "this is myscript.sh running at `date`"
mailx -s myscript.sh root < /tmp/myscript.out
rm /tmp/myscript.out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 11:41 AM
07-23-2001 11:41 AM
Re: How to prevent multiple sessions of a cron job
You were lucky, I had something very close and spent about 2 minutes altering it. Since this will be a cron job make sure that you have PATH set early in your script if you are calling anything not in /usr/bin.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 11:57 AM
07-23-2001 11:57 AM
Re: How to prevent multiple sessions of a cron job
Sorry about that, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 12:24 PM
07-23-2001 12:24 PM
Re: How to prevent multiple sessions of a cron job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 12:43 PM
07-23-2001 12:43 PM
Re: How to prevent multiple sessions of a cron job
great tip, tnx Clay.
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 01:50 PM
07-23-2001 01:50 PM
Re: How to prevent multiple sessions of a cron job
I created a script file called run.sh from your sample code with process I want to run next your comment line 'put your processing here'. When ran the script this is the error i am getting
run.sh: function: not found
rub.sh: cannot return when not in function
What wrong am I doing?..
your help is appreciated..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 02:03 PM
07-23-2001 02:03 PM
Re: How to prevent multiple sessions of a cron job
Sorry, I've been coding in too many languages today. I should have left out the word function
decclare the function simply as
locked()
{
....
....
return ${LSTAT}
}
That will fix you. My mistake not yours.
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 02:12 PM
07-23-2001 02:12 PM
Re: How to prevent multiple sessions of a cron job
Actually the function locked syntax does work in POSIX shell but locked() works in bourne,POSIX, and Korn shell.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2001 09:56 PM
07-23-2001 09:56 PM
Re: How to prevent multiple sessions of a cron job
Have the job reschedule itself AFTER it finished it's work.