Score:0

'sudo crontab -e' Jobs Are Not Running on Fresh Install of Ubuntu 21.10 (Gnu/Linux 5.13.0-30-Generic X86_64)

br flag

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!

hr flag
For #3, see [Command with percent symbols not running in crontab](https://askubuntu.com/questions/433866/command-with-percent-symbols-not-running-in-crontab)
br flag
@steeldriver, ok, I have just edited task #3 to now be `0 11 * * * (pg_dumpall > /home/ikaros/postgres_backups/"backup_$(date +\%F)".sql) >> /home/ikaros/logs/pg_dump.log 2>&1` -- I will let it run tonight and see the result. Thanks so much.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.