[SOLVED] How to: Script run every 1 hour between 18h and 7h every day
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to: Script run every 1 hour between 18h and 7h every day
Hey guys, how can I make a script run every 1 hour between 18h and 7h every day using cron?
Or... Is there other way without using cron on ubuntu based distros?
The script sends a mensage to the user saying that the PC will shutdown in 10 minutes, but the user can cancel and one hour later the script will ask again...
If you have any sugestions about how can I make this easier I would be happy to know!
Looks like you're right. The man page says "The specified range is inclusive. For example, 8-11 for an "hours" entry specifies execution at hours 8, 9, 10 and 11".
To console you, I spend 20% of my time reading manual pages. I can only remember the the stuff I use often.
I let laziness aside and read the manual ...
from what I understand, I would look something like this:
Code:
0 18-7 * * * root echo "HI!"
Cron may not understand that the range is supposed to wrap around midnight, and all versions of cron may not interpret that consistently. You should write that as
Also, while the format of that entry is correct for the system's /etc/crontab, where a user name is required for each entry, an individual user's crontab does not have that field:
Code:
0 0-7,18-23 * * * echo "HI!"
It's fortunate that you said you want to do this "every day." Doing it, e.g., "every day except Saturday night / Sunday morning" would be more complicated.
Last edited by rknichols; 12-08-2015 at 09:00 AM.
Reason: Add format for individual user's crontab
To console you, I spend 20% of my time reading manual pages. I can only remember the the stuff I use often.
berndbausch,
I never read much about CRON because never needed something very specific, but now I read, I believe that I can think of something in the future...
Quote:
Cron may not understand that the range is supposed to wrap around midnight, and all versions of cron may not interpret that consistently.
rknichols,
Man, thank you! I had not thought about it!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.