简体   繁体   中英

How to create a relative linux crontab in bash: NOW (date) + 24 hrs

I need a way to create an entry on the crontab that executes a script only once in 24h.

Steps:

  • Run a bash script to configure a crontab to run a script in 24h (with command date ?). This will run only ONCE 24 hs after .
  • 24h later the script runs.
  • At the end of the script execution, the crontab must be left clean. This means to remove the entry from the crontab. I don´t want to pollute the crontab with deprecated entries.

If you don't want to pollute the crontab, you can use "at" eg

at now + 24 hours

now you will get "at>" prompt, and you'll be able to enter the code which will be executed in 24 hours

You can also execute a shell script using:

at -f shell_script now + 24 hours

additional info can be found here: https://en.wikipedia.org/wiki/At_(Unix)

and here: http://www.tldp.org/LDP/GNU-Linux-Tools-Summary/html/scheduling.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM