测试cronjobb:
* * * * * /bin/echo Test >> /user/ubuntu/test.txt
我尝试在多个地方包含它,但没有成功:
- 添加
crontab -e
- 添加
sudo crontab -e
- 添加
sudo vim /etc/crontab
- 此命令略有变化,以包括用户:
* * * * * root /bin/echo Test >> /user/ubuntu/test.txt
注意:我已经在本地机器上测试了此命令并且它有效。
我还尝试启动/重新启动我的 cron。以下是状态:
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2020-01-29 16:50:04 UTC; 35min ago
Docs: man:cron(8)
Main PID: 3996 (cron)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/cron.service
└─3996 /usr/sbin/cron -f
Jan 29 17:23:01 ip-172-31-36-72 cron[3996]: (*system*) RELOAD (/etc/crontab)
Jan 29 17:23:01 ip-172-31-36-72 CRON[5379]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 29 17:23:01 ip-172-31-36-72 CRON[5379]: pam_unix(cron:session): session closed for user root
Jan 29 17:24:01 ip-172-31-36-72 cron[3996]: (*system*) RELOAD (/etc/crontab)
Jan 29 17:24:01 ip-172-31-36-72 CRON[5392]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 29 17:24:01 ip-172-31-36-72 CRON[5393]: (root) CMD (/bin/echo Test >> /user/ubuntu/test.txt)
Jan 29 17:24:01 ip-172-31-36-72 CRON[5392]: pam_unix(cron:session): session closed for user root
Jan 29 17:25:01 ip-172-31-36-72 CRON[5399]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 29 17:25:01 ip-172-31-36-72 CRON[5400]: (root) CMD (/bin/echo Test >> /user/ubuntu/test.txt)
Jan 29 17:25:01 ip-172-31-36-72 CRON[5399]: pam_unix(cron:session): session closed for user root
编辑:主目录:
ubuntu@ip-172-31-36-72:~$ pwd
/home/ubuntu
答案1
根据您的pwd
结果,您的主目录是/home/ubuntu
。但您正尝试将结果重定向至/user/ubuntu
。
你能添加
* * * * * /bin/echo Test >> /home/ubuntu/test.txt
到crontab -e
另外,给出命令的输出ls /user/ubuntu