定期任务执行:
1、未来的某个时间点仅执行一次
at
batch
at [-V] [-q x] [-f file] [-m] time
at [-V] [-q x] [-f file] [-m] -t [[CC]YY]MMDDhhmm
at -c job [job...]

batch [-V] [-f file] [-m]
时间表示法:
HH:MM [AM|PM]
MM/DD/YY
now + #(minutes/hours/days/mounth)
ctrl+d 提交任务
任务完成之后是以一封邮件的形式告知任务发起者任务的完成情况!(mail #)
at -l = atq查看任务
at -r Job_num = atrm Job_num 删除任务
at -f file TIME 指定某个时间执行某个文件


2、在未来周期性的执行一个任务
crontab(一个服务,一直在后台执行)
PATH=/sbin:/bin:/usr/sbin:/usr/bin
两类:
1、用户cron,不需要指定用户 六个字段
/var/spool/cron/USERNAME
2、系统cron,需要指定用户 七个字段
/etc/crontab
[root@localhost ~]# which crond
/usr/sbin/crond
[root@localhost ~]# rpm -qf /usr/sbin/crond
vixie-cron-4.1-77.el5_4.1
[root@localhost ~]# service crond status
crond (pid 4015) is running...

[root@localhost cron]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly 每个小时的第1分钟执行
02 4 * * * root run-parts /etc/cron.daily
每天的4点02分执行
22 4 * * 0 root run-parts /etc/cron.weekly
周日的4点22分执行
42 4 1 * * root run-parts /etc/cron.monthly
每月的1号的4点42分执行

时间:
min:00--59
hour:00-23
day:01-31
month:01-12
day of week:00-07(00和07都是周日)

非连续时间点:,
15,45 * * * * 每小时的15和45分执行

连续时间点:-
00 8-18 * * * 每天的8-18点的00分执行

*/#(数字) * * * * 每隔几分钟执行一次
0-59/3 * * * * 每隔3分钟执行一次
*/3 * * * * 每隔3分钟执行一次

[root@localhost cron]# crontab --help
crontab: invalid option -- -
crontab: usage error: unrecognized option
usage: crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
(default operation is replace, per 1003.2)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
-s (selinux context)


crontab用法:
-e 编辑crontab任务
-l 列出crontab任务
eg:
[root@localhost ~]# crontab -l
00 22 * * * /sbin/shutdown -h now &> /dev/null
-r 删除crontab任务
-u 指定用户名 ,为某用户指定crontab任务
crontab -u redhat -e







anacron:实现检查过期和未完成的任务,并立即执行未完成的任务
[root@localhost ~]# cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

1 65 cron.daily run-parts /etc/cron.daily
7 70 cron.weekly run-parts /etc/cron.weekly
30 75 cron.monthly run-parts /etc/cron.monthly


date 系统时间
clock 硬件时间
hwclock -w 将系统时间写入硬件时间,即同步
hwclock -s 将硬件时间写入系统时间,也是同步
crontab -e 同步系统时间和硬件时间
*/3 * * * * /sbin/hwclock -s &> /dev/null
每三分钟同步硬件时间和系统时间



sudo命令:
[root@localhost ~]# ll /etc/sudoers
-r--r----- 1 root root 3193 Feb 23 2010 /etc/sudoers
440权限

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
%USERMANAGER ALL=(ALL) ALL
组前加%表示系统组,eg:%USERMANAGER ALL=(ALL) ALL 这个组可以以所有用户的身份实行所有命令

格式:
who which_host=(whom) command_list
eg:
student ALL=(root) /usr/sbin/useradd,/usr/sbin/userdel,/usr/sbin/usermod,/usr/passwd !/usr/bin/passwd root(不允许更改root用户密码)

组:
Host_Alias
User_Alias
Cmnd_Alias

eg:
Cmnd_Alias USERCMND=/usr/sbin/useradd,/usr/sbin/userdel,/usr/sbin/usermod
User_Alias USERNANAGER = wz,redhat,student,centos,ubantu

Alias的名称中的字符必须全部使用大写字母

sudo:
-k 需要输入密码才可以切换
-l 现实当前sudo的用户可以使用的命令