Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2566176
  • 博文数量: 315
  • 博客积分: 3901
  • 博客等级: 少校
  • 技术积分: 3640
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-08 15:32
个人简介

知乎:https://www.zhihu.com/people/monkey.d.luffy Android高级开发交流群2: 752871516

文章分类

全部博文(315)

文章存档

2019年(2)

2018年(1)

2016年(7)

2015年(32)

2014年(39)

2013年(109)

2012年(81)

2011年(44)

分类: LINUX

2015-05-05 13:17:41

我也是无奈,本来用python的,但是各种尝试不行啊。。。。找了很多办法,就是不执行;  改成shell,一个德性,肯定是哪配置错了!
也是时间太仓促,又不想花太多时间,想想能跑就行。  就整了个php的。。。凑合用吧。。。。还行。。

用在定时执行【crontab】任务里面
copyPicFixTime.php

点击(此处)折叠或打开

  1. <?php
  2. $dst = date('Y-m-d', time());
  3. $src = date('Y-m-d', strtotime('-1 day'));
  4. copy("{$src}1.png", "{$dst}1.png");
  5. copy("{$src}2.png", "{$dst}2.png");
  6. copy("{$src}3.png", "{$dst}3.png");
  7. //echo $src;
  8. //echo $dst;
  9. file_put_contents('/home/heyclock_run_pullcopy.log', "时间: ".date('Y-m-d H:i:s')."\t".$src."->".$dst."\r\n", FILE_APPEND);
  10. ?>
配置定时执行:
  crontab -e
    
每天凌晨12点1分执行..

点击(此处)折叠或打开

  1. # Edit this file to introduce tasks to be run by cron.
  2. #
  3. # Each task to run has to be defined through a single line
  4. # indicating with different fields when the task will be run
  5. # and what command to run for the task
  6. #
  7. # To define the time you can provide concrete values for
  8. # minute (m), hour (h), day of month (dom), month (mon),
  9. # and day of week (dow) or use '*' in these fields (for 'any').#
  10. # Notice that tasks will be started based on the cron's system
  11. # daemon's notion of time and timezones.
  12. #
  13. # Output of the crontab jobs (including errors) is sent through
  14. # email to the user the crontab file belongs to (unless redirected).
  15. #
  16. # For example, you can run a backup of all your user accounts
  17. # at 5 a.m every week with:
  18. # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
  19. #
  20. # For more information see the manual pages of crontab(5) and cron(8)
  21. #
  22. # m h dom mon dow command
  23. #* * * * * sleep 10; . /etc/profile;/bin/sh /opt/tomcat7_heyclock/webapps/examples/copyPicFixTime.sh
  24. 1 0 * * * php /opt/tomcat7_heyclock/webapps/examples/copyPicFixTime.php

问题来了:我今天早上起来,打开客户端,查看了一下,卧槽,图片不显示。。。 看来我按照时间获取图片失败了,那肯定就是后台服务没跑起来。   来试了下,原来脚本的里面的代码也得写成绝对路径才行。。。。【我原本想的是脚本搁在哪个目录,就默认是当前目录就可以。。其实不然; 之前说是配置crontab的时候需要绝对路径,现在看来脚本里面也需要注意

点击(此处)折叠或打开

  1. <?php
  2. $dst = date('Y-m-d', time());
  3. $src = date('Y-m-d', strtotime('-1 day'));
  4. copy("/opt/tomcat7_heyclock/webapps/examples/"."{$src}1.png", "/opt/tomcat7_heyclock/webapps/examples/"."{$dst}1.png");
  5. copy("/opt/tomcat7_heyclock/webapps/examples/"."{$src}2.png", "/opt/tomcat7_heyclock/webapps/examples/"."{$dst}2.png");
  6. copy("/opt/tomcat7_heyclock/webapps/examples/"."{$src}3.png", "/opt/tomcat7_heyclock/webapps/examples/"."{$dst}3.png");
  7. //echo $src;
  8. //echo $dst;
  9. file_put_contents('/home/heyclock_run_pullcopy.log', "时间: ".date('Y-m-d H:i:s')."\t".$src."->".$dst."\r\n", FILE_APPEND);
  10. ?>



阅读(3068) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~