我已设置anacron
运行多个任务,但由于某种奇怪的权限错误,它似乎失败了。
这是我的anacrontab
:
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
@daily 1 bashrc.daily rsync -aAX $HOME/.bashrc /run/media/MYUSER/samsung/home/MYUSER/.bashrc
@daily 1 bash_aliases.daily rsync -aAX $HOME/.bash_aliases /run/media/MYUSER/samsung/home/MYUSER/.bash_aliases
@daily 5 variety.daily rsync -aAX $HOME/.config/variety/ /run/media/MYUSER/samsung/home/MYUSER/.config/variety/
@daily 3 testfile.daily rsync -aAX $HOME/Documents/flag.hs /run/media/MYUSER/samsung/flag.hs
@weekly 5 st_apps.daily rsync -aAX $HOME/.local/share/Steam/steamapps/ /run/media/MYUSER/samsung/home/MYUSER/.local/share/Steam/steamapps/
@weekly 15 st_ud.daily rsync -aAX $HOME/.local/share/Steam/userdata/ /run/media/MYUSER/samsung/home/MYUSER/.local/share/Steam/userdata/
@weekly 1 anacrontab.weekly rsync -aAX /etc/anacrontab /run/media/MYUSER/samsung/home/anacrontab
这是的输出journalctl -b --no-pager --catalog | grep anacron
jan. 14 00:02:09 MYPC anacron[73073]: Anacron started on 2022-01-14
jan. 14 00:02:09 MYPC anacron[73073]: Can't open timestamp file for job cron.daily: Permission denied
jan. 14 00:02:09 MYPC anacron[73073]: Aborted
jan. 14 00:02:42 MYPC sudo[73113]: MYUSER : TTY=pts/0 ; PWD=/home/MYUSER ; USER=root ; COMMAND=/usr/bin/dd bs=4k of=/etc/anacrontab
jan. 14 00:02:50 MYPC sudo[73124]: MYUSER : TTY=pts/0 ; PWD=/home/MYUSER ; USER=root ; COMMAND=/usr/bin/dd bs=4k of=/etc/anacrontab
有人可以吗请促使我朝正确的方向前进?
系统:Fedora 35
答案1
我anacron
之前工作过,但现在不再工作了,所以我决定采取不同的方法。为了能够在不升级权限的情况下运行它,您需要执行以下操作:
- 使用以下命令在您的主目录中创建一个
.anacron
文件夹和两个子目录(etc
和) 。spool
mkdir -p ~/.anacron/{etc,spool}
etc
通过运行touch $HOME/.anacron/etc/anacrontab
与原始文件类似的内容在目录中创建一个新文件/etc/anacrontab
。例如:
# Personal anacrontab
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#period in days delay in minutes job-identifier command
@daily 1 bashrc.daily rsync -aAXr $HOME/.bashrc /run/media/myuser/samsung/home/myuser/.bashrc
@daily 1 bash_aliases.daily rsync -aAXr $HOME/.bash_aliases /run/media/myuser/samsung/home/myuser/.bash_aliases
- 在终端中,输入
crontab -e
并添加以下内容:
@hourly /usr/sbin/anacron -s -t $HOME/.anacron/etc/anacrontab -S $HOME/.anacron/spool
您可以测试等待 cron 执行每小时任务,也可以anacron
通过运行 强制立即运行anacron -fnd -t $HOME/.anacron/etc/anacrontab -S $HOME/.anacron/spool/
。
希望这对将来的其他人有帮助!