Cron

    Source: https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

    Open file to edit πŸ”—

    crontab -e
    

    Format πŸ”—

    a b c d e /path/command
    
    • a: Minute (0-59)
    • b: Hours (0-23)
    • c: Day (0-31)
    • d: Month (0-12 [12 == December])
    • e: Day of the week(0-7 [7 or 0 == sunday])
    • /path/command – Script or command name to schedule

    Special @ shortcuts πŸ”—

    Source: https://www.linode.com/docs/guides/schedule-tasks-with-cron/#special-cron-syntaxes

    Test Cron πŸ”—

    • @reboot statement runs the specified command once, at start up.
    • @yearly and @annually both run the specified task every year at 12:00am on the 1st of January. This is equivalent to specifying 0 0 1 1 * in the crontab line.
    • @daily and @midnight both run the cronjob every day at 12:00am. This is equivalent to the following cron syntax: 0 0 * * *.
    • @monthly runs the job once a month, on the 1st, at 12:00am. In standard cron syntax this is equivalent to: 0 0 1 * *.
    • @weekly runs the job once a week at 12:00am on Sunday. This is the same as specifying 0 0 * * 0 on the crontab line.
    • @hourly runs the job at the top of every hour. In standard cron syntax this is equivalent to: 0 * * * *.

    Example Usage

    @reboot date >> ~/test_cron.txt
    

    Simple Test πŸ”—

    Open Crontab

    crontab -e
    

    Add line to bottom and save (Ensure there is a new line at the end of the line)

    * * * * * date >> ~/date.txt
    

    Wait one minute and confirm that it works

    Move involved test that uses a script πŸ”—

    Create test script and set cron to run script

    Create temp folder

    mkdir ~/tmp
    

    Create test script πŸ”—

    echo 'date >> ~/tmp/cron_result.txt' > ~/tmp/cron_test.sh
    chmod 700 ~/tmp/cron_test.sh
    ls -l ~/tmp
    

    Open Crontab

    crontab -e
    

    Add line to bottom and save (Ensure there is a new line at the end of the line)

    * * * * * ~/tmp/cron_test.sh
    

    Wait one minute and confirm that it works

    cat ~/tmp/cron_result.txt