linux java定时关机,[原]linux下定时关机:crontab

linux下定时关机

1.添加或者编辑一个计划任务:

crontab -e

2.进入编辑状态,输入下述代码:

----------------------------------------------------

#Power off this machine everyday or weekday

#[email protected]

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

25 22 * * 0-5 sync && shutdown -h now

#  每星期日到星期五  晚10:25 关机

55 22 * * 6 sync && shutdown -h now

#  每星期六 晚10:55 关机

----------------------------------------------------

保存(默认是用vi打开的)

3.重启crond任务

/etc/rc.d/init.d/crond restart

4.查看已添加的计划任务

crontab –l

到此,linux下定时关机设置完毕

补充:

crontab -d

删除当前的crontab任务

crontab文件的每一行由六个域(minutes、hours、day of month、month、day of week、 command)组成,域之间用空格或Tab分开,其中:

minutes: 分钟,值的范围是0到59

hours: 小时,值的范围是0到23

day of month: 日期,值的范围是1到31

month: 月份,值的范围是1到12

day of week: 星期,值的范围是0到6,星期日值为0

command: 所要运行的命令

在rhel中,crond服务是默认启动的。如果被关闭了,可以将crond设置为系统启动后自动启动的服务,可以在/etc/rc.d/rc.local 中,在末尾加上 :

/sbin/service crond start

你可能感兴趣的:(linux,java定时关机)