我也是无奈,本来用python的,但是各种尝试不行啊。。。。找了很多办法,就是不执行; 改成shell,一个德性,肯定是哪配置错了!
也是时间太仓促,又不想花太多时间,想想能跑就行。 就整了个php的。。。凑合用吧。。。。还行。。
用在定时执行【crontab】任务里面
copyPicFixTime.php
-
<?php
-
$dst = date('Y-m-d', time());
-
$src = date('Y-m-d', strtotime('-1 day'));
-
copy("{$src}1.png", "{$dst}1.png");
-
copy("{$src}2.png", "{$dst}2.png");
-
copy("{$src}3.png", "{$dst}3.png");
-
//echo $src;
-
//echo $dst;
-
file_put_contents('/home/heyclock_run_pullcopy.log', "时间: ".date('Y-m-d H:i:s')."\t".$src."->".$dst."\r\n", FILE_APPEND);
-
?>
配置定时执行:
crontab -e
每天凌晨12点1分执行..
-
# Edit this file to introduce tasks to be run by cron.
-
#
-
# Each task to run has to be defined through a single line
-
# indicating with different fields when the task will be run
-
# and what command to run for the task
-
#
-
# To define the time you can provide concrete values for
-
# minute (m), hour (h), day of month (dom), month (mon),
-
# and day of week (dow) or use '*' in these fields (for 'any').#
-
# Notice that tasks will be started based on the cron's system
-
# daemon's notion of time and timezones.
-
#
-
# Output of the crontab jobs (including errors) is sent through
-
# email to the user the crontab file belongs to (unless redirected).
-
#
-
# For example, you can run a backup of all your user accounts
-
# at 5 a.m every week with:
-
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
-
#
-
# For more information see the manual pages of crontab(5) and cron(8)
-
#
-
# m h dom mon dow command
-
#* * * * * sleep 10; . /etc/profile;/bin/sh /opt/tomcat7_heyclock/webapps/examples/copyPicFixTime.sh
-
1 0 * * * php /opt/tomcat7_heyclock/webapps/examples/copyPicFixTime.php
问题来了:我今天早上起来,打开客户端,查看了一下,卧槽,图片不显示。。。 看来我按照时间获取图片失败了,那肯定就是后台服务没跑起来。 来试了下,原来脚本的里面的代码也得写成绝对路径才行。。。。【我原本想的是脚本搁在哪个目录,就默认是当前目录就可以。。其实不然; 之前说是配置crontab的时候需要绝对路径,现在看来脚本里面也需要注意】
-
<?php
-
$dst = date('Y-m-d', time());
-
$src = date('Y-m-d', strtotime('-1 day'));
-
copy("/opt/tomcat7_heyclock/webapps/examples/"."{$src}1.png", "/opt/tomcat7_heyclock/webapps/examples/"."{$dst}1.png");
-
copy("/opt/tomcat7_heyclock/webapps/examples/"."{$src}2.png", "/opt/tomcat7_heyclock/webapps/examples/"."{$dst}2.png");
-
copy("/opt/tomcat7_heyclock/webapps/examples/"."{$src}3.png", "/opt/tomcat7_heyclock/webapps/examples/"."{$dst}3.png");
-
//echo $src;
-
//echo $dst;
-
file_put_contents('/home/heyclock_run_pullcopy.log', "时间: ".date('Y-m-d H:i:s')."\t".$src."->".$dst."\r\n", FILE_APPEND);
-
?>
阅读(3122) | 评论(0) | 转发(0) |