Notes
  • Notes
  • JavaScript
    • URL processing
    • Numbers
  • Python
    • python random notes
    • Python Resources
  • Setup
    • Mac Setup
  • Command Line
    • Basics
    • Linux basics
    • Bash script
    • Create temp files
    • awk
    • sed
    • make
    • ssh
    • gzip
    • Command line tools
    • ffmpeg
    • at and crontab - scheduling commands
  • Web Developement
    • Chrome Dev Tools
    • HTML
    • Markdown
    • CSS
    • Rails
    • Hugo
    • REST APIs
  • Soft Skills
    • Listening Skills
    • Public Speaking
  • Containers
  • Career
    • Resume
    • Interview
    • Promotion
    • Keeping Track of Your Work
    • Decide What to Work On
  • Ergonomics
    • Work Env Setup
    • Pain Relieve
  • Digest / Writing Ideas
    • Books
      • Antifragile
      • Anti-Intellectualism in American Life 美国的反智传统
    • Economy / Society
    • How to spend your time
    • Life
    • Higher education
  • Misc
    • Regex
    • Don't Make Me Think
    • Microsoft Excel
    • AdTech 101
  • Resources
    • web
    • Vim
    • Tools
    • System Design
    • Design Pattern
    • Load Balancer
    • References
    • Hardware
    • Algorithm Resources
    • Command Line Resources
  • Git
    • Pro Git
  • Non-Tech
    • 化学科普 - 拿破仑的纽扣
    • 人生经验 - If I Knew Then
    • 哲学
      • Harvard - Justice
    • 宗教
      • Introduction to the New Testament History and Literature
      • 蔡志忠 - 漫画东方圣经
    • 人文
      • Open Yale Course - 心理学导论
  • Spark
  • VS Code
Powered by GitBook
On this page
  • at
  • crontab

Was this helpful?

  1. Command Line

at and crontab - scheduling commands

PreviousffmpegNextWeb Developement

Last updated 5 years ago

Was this helpful?

Ref:

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

$ at 2350 -f query.sh
# run query.sh at 23:50
# in the file, use absolute paths

$ at 2340
echo 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 -l
2	Sun Jan 12 23:40:00 2020
1	Sun Jan 12 23:50:00 2020

$ atrm 2
# remove job #2, same as at -r 2

$ atq
1	Sun Jan 12 23:50:00 2020
# job #2 has been removed

crontab

$ 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 vim
6 10 19 11 * /Users/davidfeng/query.sh
# :wq save and quit
crontab: installing new crontab

# alternatively
# task.crontab
# 6 10 19 11 * /Users/davidfeng/query.sh
$ crontab task.crontab

$ crontab -l
# list all scheduled jobs
6 10 19 11 * /Users/davidfeng/query.sh

$ crontab -r
# Remove your crontab
# effectively un-scheduling all crontab jobs

at understands noon, midnight, teatime (4PM), tomorrow (10AM), now + 1 hour, 4pm + 3 days, etc. (more examples )

http://faculty.salina.k-state.edu/tim/unix_sg/advanced/schedule.html
here