GoAdmio

cronjob

Run your own daily, weekly, and monthly shell scripts from /var/go/cron/, with email and WhatsApp notices

On this page: Overview · Quick start · Syntax · Output · Examples · Troubleshooting · Details · See also


Overview

/go/cronjob runs the shell scripts you place in three folders, one per schedule:

Folder Scripts run
/var/go/cron/daily Every time the command runs.
/var/go/cron/weekly Only when the command runs on a Saturday.
/var/go/cron/monthly Only when the command runs on the 1st of the month.

Before a group of scripts starts, the command sends an email and a WhatsApp message saying that it is running. It is a simple way to add your own maintenance scripts to the server without writing cron entries.

The command doesn't schedule itself. Something has to run it once a day. It is also not the command that manages the cron jobs of hosting accounts. For that, see cron.


Quick start

# Create a daily script
mkdir -p /var/go/cron/daily
printf '#!/bin/bash\n/go/clean\n' > /var/go/cron/daily/10-clean.sh

# Run the scripts now
/go/cronjob

[!WARNING] The scripts run as the user who runs /go/cronjob, normally root. Anyone who can add or change files in /var/go/cron/ can run commands as root, so keep these folders writable by root only. Running /go/cronjob by hand starts every daily script immediately.


Syntax

/go/cronjob

The command takes no options or arguments. Any you pass are ignored (they are only written to the log).


Output

The command prints a heading before each group it runs, followed by whatever the scripts print:

Group Heading
Daily Daily Scheduling Files...
Weekly Weekly Scheduling...
Monthly Monthly Scheduling Files... followed by Weekly Scheduling...

The second line under the monthly heading is a typo in the script. It doesn't mean the weekly scripts ran.

If a folder is missing or empty, or it isn't the right day, that group prints nothing.

Output from your scripts isn't saved by this command. If you run it from cron, redirect its output to a file. Every run is also logged with a timestamp, for example [Nov 20 02:00:01]# cronjob, to /var/log/go/cronjob.log.


Examples

# Folder layout
/var/go/cron/daily/10-clean.sh
/var/go/cron/weekly/20-check-ssl.sh
/var/go/cron/monthly/30-report.sh
# A script needs only a first line that names the shell and the commands to run
#!/bin/bash
/go/checkssl
# Run the command every day at 02:00 and keep its output
0 2 * * * root /go/cronjob >> /var/log/go/cron/cronjob.log 2>&1
# See which scripts will run, in order
ls /var/go/cron/daily

Troubleshooting

Symptom Likely cause Fix
A script doesn't run Its name doesn't end in .sh, or it isn't directly inside the folder. Rename it, for example backup.sh. Names are case-sensitive.
A notice was sent, but no script ran The folder has files, but none ends in .sh. Rename the scripts. The notice is sent whenever the folder isn't empty.
Weekly scripts didn't run The command didn't run on a Saturday, or the server's language isn't English, so the weekday isn't Sat. Run it every day, and check date +%a.
Monthly scripts didn't run The command didn't run on the 1st. Run it every day.
Scripts run several times a day The command is started more than once a day. Schedule it once a day. Daily scripts run on every start, and weekly scripts run on every start on a Saturday.
A script with spaces in its name fails The file name isn't quoted when it is run. Use names without spaces.
A script fails and nobody is told Exit codes aren't checked, and the notice is sent before the scripts run. Make the script report its own errors, for example by email.
Scripts run in an unexpected order They run in alphabetical order. Start names with numbers, such as 10-first.sh and 20-second.sh.
A long script delays the others Scripts run one at a time, and the weekly and monthly groups wait for the daily scripts. Start slow work in the background inside the script, or split it up.
No email or WhatsApp notice arrives Notices are sent by /go/sendmail and /go/sendwhatsapp, which depend on your notification settings. Check those settings. Those commands aren't in the command index.
The command pauses before doing anything It looks up the server's public IP first, and the server may have no internet access. Check the server's connection.

Details

Steps

  1. Reads the current weekday and day of the month.
  2. Looks up the admin contact details and the server's public IP address. The script doesn't use these values.
  3. For each of daily, weekly, and monthly, in this order:
    1. Skips the group if the folder doesn't exist or is empty.
    2. For weekly, skips it unless today is Saturday. For monthly, skips it unless today is the 1st.
    3. Sends an email and a WhatsApp message with the text <Daily, Weekly, or Monthly> Scheduling Files Running Now.
    4. For each file in the folder whose name ends in .sh, makes it executable and runs it.

Each script runs from inside its own folder, so relative paths in a script start there. The date is the server's own, so it follows the server's time zone.

Rules for scripts


See also

Command Description
cron Rebuild GoAdmio's cron jobs, server-wide or for one domain, and restart or stop the cron service
clean Delete old backups, trash, session files, and expired mail to free up disk space
backup Create a backup for all GoAdmio accounts (local and remote)
checkssl Check if SSL certificates are installed for all domains
update Update GoAdmio to the latest version via the command line