2014-11-06 82 views
0

我需要检查我是否正确执行此操作。通过cron运行脚本的正确语法

已经创建了两个脚本来关闭和打开一个网站

close.sh

mv /path/public_html/.htaccess /path/public_html/.htaccess.bak 
mv /path/public_html/.htaccess.temp /path/public_html/.htaccess 

open.sh

mv /path/public_html/.htaccess /path/public_html/.htaccess.temp 
mv /path/public_html/.htaccess.bak /path/public_html/.htaccess 

这将使.htaccess.temp文件,然后不久禁用它之后。

我然后跑的crontab -e并建立

0 11 11 11 * /bin/sh /root/close.sh 
02 11 11 11 * /bin/sh /root/open.sh 

我是正确的我的crontab?我看到一些有/ bin/sh的条目,有些则没有,所以不确定。

我对我的两个脚本充满信心,我只需要确保它们在每年11月11日上午11点分开运行。

非常感谢。

回答

0

你是正确的,即使0是可选的分钟左:

0 11 11 11 * /bin/sh /root/close.sh 
2 11 11 11 * /bin/sh /root/open.sh 

维基百科:

# * * * * * command to execute 
# │ │ │ │ │ 
# │ │ │ │ │ 
# │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0) 
# │ │ │ └────────── month (1 - 12) 
# │ │ └─────────────── day of month (1 - 31) 
# │ └──────────────────── hour (0 - 23) 
# └───────────────────────── min (0 - 59) 

小心正确的权限设置为你的.htaccess:

mv /path/public_html/.htaccess /path/public_html/.htaccess.temp 
mv /path/public_html/.htaccess.bak /path/public_html/.htaccess 
chown www-data:www-data /path/public_html/.htaccess 
+0

谢谢 - 我不熟悉www-data:www-data - 这涉及到什么? – Ian 2014-11-06 11:25:55

+0

'www-data'是可以访问你的'public_html'目录的用户。如果你把一个crontab作为root用户,并把文件放入'public_html','www-data'可能无法访问它们。我们使用'www-data:www-data',因为'www-data'用户属于'www-data'组。 [更多信息](https://wiki.archlinux.org/index.php/users_and_groups) – 2014-11-06 11:31:00

0

您可以使用以下命令验证您的“sh”二进制文件的路径:

which sh 

如果返回的路径是“/ bin/sh”,那么你可以让这个路径在你的crontab中。

+0

谢谢。路径是正确的,更多的是一个人是否应该包括它。我会留下。 – Ian 2014-11-06 11:21:22