I recently did a fresh install of Ubuntu. I am trying to setup some cron jobs using sudo crontab -e
My crontab is as follows:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
# Task #1 - Start up local service for noips (dynamic DNS provider), and change permissions of mounted drive so another service can access said files
@reboot /usr/local/bin/noip2 && chown -R ikaros:plex /home/ikaros/mnt/ > /dev/null
# Task #2 - Shutdown the server every day at 0 10
0 10 * * * /sbin/shutdown -r +5 > /dev/null
# Task #3 - Dump postgreSQL databases to a file at 0 11
0 11 * * * (pg_dumpall > /home/ikaros/postgres_backups/"backup_$(date +%F)".sql) >> /home/ikaros/logs/pg_dump.log 2>&1
# Task #4 - Make sure only the last 5 backup files are stored on the disc every day at 0 9
0 9 * * * (cd /home/ikaros/postgres_backups/ && ls -tp | grep -v '/$' | tail -n +5 | xargs -d '\n' -r rm -- ) >> /home/ikaros/logs/pg_clear_backups.log 2>&1
Task #1 seems to work fine.
Task #2 seems to work fine.
Task #3 NEVER runs, despite when I paste this command (pg_dumpall > /home/ikaros/postgres_backups/"backup_$(date +%F)".sql) >> /home/ikaros/logs/pg_dump.log 2>&1
when logged in as user ikaros
, it works fine.
Task #4 also NEVER runs, despite when I paste the command (cd /home/ikaros/postgres_backups/ && ls -tp | grep -v '/$' | tail -n +5 | xargs -d '\n' -r rm -- ) >> /home/ikaros/logs/pg_clear_backups.log 2>&1
while logged in as ikaros
, everything works as expected.
What am I doing wrong here? Any advice?
Much appreciated!