Running a simple shell script as a cronjob

后端 未结 5 1758
伪装坚强ぢ
伪装坚强ぢ 2020-12-16 11:57

I have a very simple shell script I need to run as a cronjob but I can\'t get even the test scripts to run. Here\'s and example script:

/home/myUser/scripts/test.sh<

5条回答
  •  Happy的楠姐
    2020-12-16 12:10

    The easiest way would be to use a GUI:

    For Gnome use gnome-schedule (universe)

    sudo apt-get install gnome-schedule 
    

    For KDE use kde-config-cron

    It should be pre installed on Kubuntu
    

    But if you use a headless linux or don´t want GUI´s you may use:

    crontab -e
    

    If you type it into Terminal you´ll get a table.
    You have to insert your cronjobs now.
    Format a job like this:

    *     *     *     *     *  YOURCOMMAND
    -     -     -     -     -
    |     |     |     |     |
    |     |     |     |     +----- Day in Week (0 to 7) (Sunday is 0 and 7)
    |     |     |     +------- Month (1 to 12)
    |     |     +--------- Day in Month (1 to 31)
    |     +----------- Hour (0 to 23)
    +------------- Minute (0 to 59)
    

    There are some shorts, too (if you don´t want the *):

    @reboot --> only once at startup
    @daily ---> once a day
    @midnight --> once a day at midnight
    @hourly --> once a hour
    @weekly --> once a week
    @monthly --> once a month
    @annually --> once a year
    @yearly --> once a year
    

    If you want to use the shorts as cron (because they don´t work or so):

    @daily --> 0 0 * * *
    @midnight --> 0 0 * * *
    @hourly --> 0 * * * *
    @weekly --> 0 0 * * 0
    @monthly --> 0 0 1 * *
    @annually --> 0 0 1 1 *
    @yearly --> 0 0 1 1 *
    

提交回复
热议问题