版权声明:歡迎转載 https://blog.csdn.net/jinjianghai/article/details/80676117
1 : 安装定时工具
sudo apt-get install cron;
2 : 写 Shell
#!/bin/bash
#以下是 tomcat 开启服务的命令
sudo service tomcat7 start
保存文件 xxx.sh 到 root 的目录下(su root) *如果不知道 root 密码,sudo passwd root 可以进行密码修改*;
xxx.sh 必须要有执行权限,ls 显示绿色,如果不是可以用 chmod +x xxx.sh 加入执行权限;
3 : 把这条需要执行的 shell加入到定时任务里面.
crontab -e (初次执行会让选择编辑工具,选择自己熟悉的工具,)
按照 cron 的格式写入需要执行的命令
如: 第周12345的5:55 执行 某个目录下的.sh 文件
55 09 * * 1,2,3,4,5 /root/shellDir/tomcat_restart.sh
输入完成,按下 [ESC] 输入 :wq 保存退出