Crontab and Shell executables

If you need to create crontab format easily, the best option is to use cronitor it will interactively help you to understand and create a working cron format
i.e: https://crontab.guru/every-day-at-1am

Editing crontab:

crontab cheatsheet

To edit:

  1. crontab -e
    
  2. Add this command line:
    30 2 * * * /your/command
    
    • Crontab Format:

      MIN HOUR DOM MON DOW CMD

    • Format Meanings and Allowed Value:
    • MIN Minute field 0 to 59
    • HOUR Hour field 0 to 23
    • DOM Day of Month 1-31
    • MON Month field 1-12
    • DOW Day Of Week 0-6
    • CMD Command Any command to be executed.
  3. Restart cron with latest data:
    From the cron man page:

    …cron will then examine the modification time on all crontabs and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified

    But if you just want to make sure its done anyway,

    sudo service cron reload

    or

    /etc/init.d/cron reload

    or

    service crond restart

https://stackoverflow.com/questions/14710257/running-a-cron-job-at-230-am-everyday
If you need to better understand crontab check this link:
https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it

Making a sh or shell script exectuable:

You may want to run a script in crontab, so before adding it, you need to create one and making it exectuable.
Give execute permission to your script:

chmod +x /path/to/yourscript.sh

And to run your script:

/path/to/yourscript.sh

Since . refers to the current directory: if yourscript.sh is in the current directory, you can simplify this to:

./yourscript.sh

https://askubuntu.com/questions/38661/how-do-i-run-sh-scripts

0 thoughts on “Crontab and Shell executables