①开机自动运行:
先写了测试脚本,在/usr下,trans.sh
gedit /etc/init.d/rc.local
在最后加上脚本的地址就OK了
②定时运行脚本:
以下部分转自:http://hi.baidu.com/michaelxdt/item/a8e4fec22a59867388ad9e62
cron,是一个Linux定时执行工具,可以在无需人工干预的情况下运行作业。 1. 关于crontab
在Ubuntu server 9.10下,cron是被默认安装并启动的。通过/etc/crontab文件,可以看到以下内容:
-----------------------------------------------------------------------------------------------------------------------
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
-----------------------------------------------------------------------------------------------------------------------
ununtu 通过调用 run-parts 命令,定时运行四个目录下的所有脚本。
1)/etc/cron.hourly,目录下的脚本会每个小时让执行一次,在每小时的17分钟时运行;
2)/etc/cron.daily,目录下的脚本会每天让执行一次,在每天的6点25分时运行;
3)/etc/cron.weekly,目录下的脚本会每周让执行一次,在每周第七天的6点47分时运行;
4)/etc/cron.mouthly,目录下的脚本会每月让执行一次,在每月1号的6点52分时运行;
当然,以上的时间均是系统默认时间,可以根据自己的需求进行修改。 2. cron 服务的启动与停止
在Ubuntu 9.10下,cron是被默认安装并启动的。而 ubuntu 下启动,停止与重启cron,均是通过调用/etc/init.d/中的脚本进行。命令如下:
1)/sbin/service crond start // 启动服务
2)/sbin/service crond stop // 关闭服务
3)/sbin/service crond restart // 重启服务