如何使用 crontab 执行脚本
How to execute a script using crontab
我正在尝试通过 crontab 文件执行位于 /logann/myFile 中的特定脚本。
我已经尝试了很多方法,但没有人做出任何结果。
我在 crontab 文件中添加了这一行来调用我的脚本
26 10 * * * root cd /logann && ./apagar_temp_tomcat
(我改测试的时间)
我的剧本是
#!/bin/sh
rm /tmp/tomcat7-tomcat7-tmp/*.tmp
rm /tmp/tomcat7-tomcat7-tmp/*.xml
我只想执行这个脚本。此脚本将删除文件夹 tomcat7-tomcat7-tmp.
中的每个 .tmp/.xml 文件
有什么想法吗?
谢谢大家!
cron
工作将 运行 在他们自己的 shell 中。所以你不能指望在你的控制台上看到 tedvs
。
尝试在文件中写入一些内容,例如
* * * * * echo tedvs > file_in_your_directory.txt
只需在文件中创建一个函数,然后根据您的时间间隔在 cron 中调用该文件或函数。
我在 PHP
中做到了这一点
shell_exec(\'(crontab -l ; echo "* * * * * curl www-data http://localhost/sp/delete.php") | crontab -\');
我正在尝试通过 crontab 文件执行位于 /logann/myFile 中的特定脚本。
我已经尝试了很多方法,但没有人做出任何结果。
我在 crontab 文件中添加了这一行来调用我的脚本
26 10 * * * root cd /logann && ./apagar_temp_tomcat
(我改测试的时间)
我的剧本是
#!/bin/sh
rm /tmp/tomcat7-tomcat7-tmp/*.tmp
rm /tmp/tomcat7-tomcat7-tmp/*.xml
我只想执行这个脚本。此脚本将删除文件夹 tomcat7-tomcat7-tmp.
中的每个 .tmp/.xml 文件有什么想法吗?
谢谢大家!
cron
工作将 运行 在他们自己的 shell 中。所以你不能指望在你的控制台上看到 tedvs
。
尝试在文件中写入一些内容,例如
* * * * * echo tedvs > file_in_your_directory.txt
只需在文件中创建一个函数,然后根据您的时间间隔在 cron 中调用该文件或函数。 我在 PHP
中做到了这一点shell_exec(\'(crontab -l ; echo "* * * * * curl www-data http://localhost/sp/delete.php") | crontab -\');