You may want to schedule some programs to run at later time (at) or want them to run on a regular, repeating schedule (crontab).
Unix has a facility for running scheduled tasks called cron, but users do run cron directly. It is always running in the background to run scheduled commands at the appropriate times. We call system programs, such as cron, that run in the backgroud daemons.
The programs that users use to schedule programs are crontab and at.
$ at 2350 -f query.sh# run query.sh at 23:50# in the file, use absolute paths$ at 2340echo abc# (ctrl-D)job 3 at Sun Jan 12 23:00:00 2020# input scheduled command in terminal$ atq# show all scheduled work, same as at -l2 Sun Jan 12 23:40:00 20201 Sun Jan 12 23:50:00 2020$ atrm 2# remove job #2, same as at -r 2$ atq1 Sun Jan 12 23:50:00 2020# job #2 has been removed
at understands noon, midnight, teatime (4PM), tomorrow (10AM), now + 1 hour, 4pm + 3 days, etc. (more examples here)
$ crontab -e# edit (add/remove) scheduled jobs (time + script)# for time format, see https://crontab.guru/# for script, again, use absolute path# (in the script also)# in vim6 10 19 11 * /Users/davidfeng/query.sh# :wq save and quitcrontab: installing new crontab# alternatively# task.crontab# 6 10 19 11 * /Users/davidfeng/query.sh$ crontab task.crontab$ crontab -l# list all scheduled jobs6 10 19 11 * /Users/davidfeng/query.sh$ crontab -r# Remove your crontab# effectively un-scheduling all crontab jobs