我最近刚刚安装了 Ubuntu。我尝试使用以下方法设置一些 cron 任务:sudo crontab -e
我的crontab如下:
# 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
任务#1 看起来运行良好。
任务#2 看起来运行良好。
任务#3 从未运行,尽管当我(pg_dumpall > /home/ikaros/postgres_backups/"backup_$(date +%F)".sql) >> /home/ikaros/logs/pg_dump.log 2>&1
以用户身份登录时粘贴此命令时ikaros
,它运行良好。
(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
任务#4 也从未运行过,尽管当我以 身份登录时粘贴命令时ikaros
,一切都按预期工作。
我在这里做错了什么?有什么建议吗?
非常感激!