树莓派2学习笔记4(定时cronTab任务并同步时间)

2017-01-08  本文已影响332人  旅行家John

自动断网重新连接,主要是linux下的定时认识crontab实现的,树莓派的官方地址。

http://www.raspberrypi.org/documentation/linux/usage/cron.md

官网上的说明方法比较准确。

# m h dom mon dow command

# * * * * * command to execute

# ┬ ┬ ┬ ┬ ┬

# │ │ │ │ │

# │ │ │ │ │

# │ │ │ │ └─day of week(0-7)(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)

使用方法:进入root用户:

输入:

crontab -e在文件尾添加:

*/20  *  *   *   *   /etc/network/if-down.d/net_restart.sh

0    17   */1  *   *   /etc/network/if-down.d/net_reboot.sh

表示每20分钟执行一次net_restart.sh脚本,检查网络是否连通。每天的17:00执行net_reboot.sh,如网络断开则重启一次树莓派。

最后,还要使cron定时任务生效:

/etc/init.d/cron restart

树莓派的时间跟我们时间差8个时区,需要自己动手设置下

4.设置当前时间

date -s 07/16/2012#设置当前日期为2012年7月16日

date -s 14:05#设置当前时间为14:05分

hwclock --systohc#使BIOS硬件时间与本地系统时间同步

至此,Debian 6.0.5解决系统时间与北京时间相差8小时问题完成

上一篇下一篇

猜你喜欢

热点阅读