- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell sleep question.
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
09-23-2004 05:03 AM
09-23-2004 05:03 AM
shell sleep question.
I have a very small shell program that does this:
while `sleep 86400`
do
..
..
echo "Something"
...
...
done
(86400 is one day).. The program does not seem to wake up after 1 day, and process what I want it to do everyday.
If I change 86400 to some smaller number, it seems to work fine. Could anyone tell why something like this happens?
Thanks
Brian.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 05:09 AM
09-23-2004 05:09 AM
Re: shell sleep question.
while true
do
...
echo "Something"
...
sleep 86400
done
But you may seriously consider using crontab.
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 06:23 AM
09-23-2004 06:23 AM
Re: shell sleep question.
while `sleep 86400`
while expects a condition that evaluates to "true" or "false".
WHILE executes the sleep 86400 and waits for the completion.
sleep command completes after one day and returns the exit code (should be 0) to while. Now WHILE will go ahead and execute the body.
Clearly, this is not good scripting but I cannot think of a reason why this was not working for you. It should have echoed "Something" after one day :-).
Also understand, the above while loop is infinite. There is no exit condition. Not a very good scripting practise either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 06:29 AM
09-23-2004 06:29 AM
Re: shell sleep question.
sleep exits with one of the following values:
0 The execution was successfully suspended for time seconds, or a SIGALRM signal was received.
>0 If the time operand is missing, is not a decimal integer, is negative, or is greater than UINT_MAX, sleep returns with exit status 2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 06:58 AM
09-23-2004 06:58 AM
Re: shell sleep question.
Thanks
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 07:17 AM
09-23-2004 07:17 AM
Re: shell sleep question.
If the time operand is missing, is not a decimal integer, is negative, or is greater than UINT_MAX, sleep returns with exit status 2.
Could 86400 be greater than UINT_MAX?
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 07:29 AM
09-23-2004 07:29 AM
Re: shell sleep question.
According to /usr/include/limits.h UINT_MAX is either 4,294,967,295 ...or... 37,777,777,777 depending on how STDC is defined.
But these are values *IF* UINT_MAX is undefined.
I suspect that sleep may define it.
At what value does the behavior begin - i.e. does it not happen at 86399? If so I'd suspect that UINT_MAX is indeed being set to 86400.
My $0.02,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 07:30 AM
09-23-2004 07:30 AM
Re: shell sleep question.
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 03:44 PM
09-23-2004 03:44 PM
Re: shell sleep question.
# getconf UINT_MAX ( 11.00)
4294967295
It may not be the problem.
Try to check script as,
while true
do
sleep 86400
if [[ $? -eq 2 ]]
then
echo "`date`problem with UINT_MAX `getconf UINT_MAX`"
else
echo "`date`Sleep returns $?"
fi
done
Redirect to another log file to analyse results later.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 09:21 PM
09-23-2004 09:21 PM
Re: shell sleep question.
How are you executing the script?
If all you do is run it as a background job (script &), when you log out your session, the script will receive a SIGHUP and terminate.
To prevent this, there are several possibilities:-
1. Run it as a batch job (batch or at now)
2. Start it with nohup.
3. Include 'trap "" 1' in the script.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2004 01:21 PM
09-29-2004 01:21 PM
Re: shell sleep question.
When you use while `sleep 86400`, you are first oputting it to sleep. So, there is no way you could see what is happening. Whereas, if you say sleep 180, you will notice it works after 3 minutes.