问题
I have a simple shell script that just checks the contents of a directory and if anything was added during the day makes a copy of it to a backup folder. I'd like to execute this script at the end of each day (let's assume at 23:55).
The system(Debian) which this scripts reside on it, is always on (kind of server)
How can I do that?
回答1:
You want to edit your crontab file using
crontab -e
Then you want to add
55 23 * * * COMMAND TO BE EXECUTED
for more info look at this
回答2:
To add a crontab job, type the following command at a UNIX/Linux shell prompt:
$ sudo crontab -e
Add the following line:
1 2 3 4 5 /path/to/script
where
1: Minutes (0-59)
2: Hours (0-23)
3: Days (1-31)
4: Month (1-12)
5: Day of the week(1-7)
/path/to/script - your own shell script
In your case it would be:
55 23 * * * /path/to/yourShellScript
回答3:
I'm anything, but a linux expert, but a quick Google search conjured up this:
watch -n <your time> <your command/script>
This should do the trick. For more information, check this out: http://www.linfo.org/watch.html
回答4:
sudo crontab -e
55 23 * * * some_shell_script.sh
回答5:
Check out the Cron task scheduler built in to Debian. Simply add an entry for your script to your crontab file (see: https://help.ubuntu.com/community/CronHowto).
来源:https://stackoverflow.com/questions/34753831/execute-a-shell-script-everyday-at-specific-time