2012-12-18 53 views
1

Crontab在Amazon EC2 Linux服務器上無法正常工作。Crontab無法在Amazon EC2服務器上工作

我在/ etc/crontab文件保存在下面的代碼

crontab 
# For details see man 4 crontabs 
# Example of job definition: 
# .---------------- minute (0 - 59) 
# | .------------- hour (0 - 23) 
# | | .---------- day of month (1 - 31) 
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat 
# | | | | | 
# * * * * * user-name command to be executed 
* 10 * * * tar cvfpz /home/backup/web_$(date +%Y%m%d).tar.gz /home/web 

我已經開始crontab命令,但是這一次沒有奏效。

我也在「crontab -e」中保存了這行,但cron不起作用。

* 10 * * * tar cvfpz /home/backup/web_$(date +%Y%m%d).tar.gz /home/web 

有沒有像我這樣的經歷的人?

謝謝。

+0

你是否也嘗試了命令完整的[路徑](http://stackoverflow.com/questions/2388087/how-to-get-cron-to-call-in-the-correct-paths)tar ? – pce

+0

是的,它是完整路徑 – Jake

+0

如果將輸出重定向到某個文件,它會說什麼?像這樣:'* 10 * * * tar cvfpz/home/backup/web _ $(date +%Y%m%d).tar.gz/home/web >> /tmp/output.txt 2>&1' – metalheart

回答

1

解決了這個問題。

我用這個代碼,它的工作原理!

* 2 * * * root tar cvfpz /home/backup/web_`date +\%Y\%m\%d`.tar.gz /home/web 
+1

我用ec2用戶,它沒有工作。當我使用root時它工作。以防萬一,這有助於某個人。 –

+0

在我的命令前添加「根」也魔術般地工作.... @Jake:你可以標記爲「接受」你自己的答案。 (多一點說明會有所幫助) –

+0

當我這樣做,它說:'/ bin/sh:root:command not found' – daniel

0

我最近使用的EC2實例,並嘗試各種東西的cron所有我需要經過亞馬遜的Linux發行版開始爲:
sudo service crond start
crontab -e
這讓我設置一個cron作業作爲「ec2-user」沒有指定用戶。例如:
0 12 * * * python3 example.py
實際上,在此處指定用戶會阻止其運行。

相關問題