程序   进程--现在系统正在执行的程序

# ps -ef | grep sshd          唯一的数字  进程ID          前台 后台

系统网络服务在后台             常驻

# netstat  -lntup | grep sshd                   守护进程   端口

crond定时任务

     秒级任务

#!/bin/bash

while  true

do

        echo  hequan >> /tmp/a.log

        sleep 1

done

# sh xx. &

[1] 1844          

 # ps -ef | grep xx.                      # kill  1844    

       

# chkconfig --list | grep 3:on

系统自身的定期执行的任务

# ll /var/log/messages

# cat /etc/logrotate.conf

# ll /etc/  | grep cron  --color=auto

-rw-------.  1 root root    541 11月 23 2013 anacrontab

drwxr-xr-x.  2 root root   4096 3月  27 18:47 cron.d

drwxr-xr-x.  2 root root   4096 3月  27 18:48 cron.daily

-rw-------.  1 root root      0 11月 23 2013 cron.deny

drwxr-xr-x.  2 root root   4096 3月  27 18:47 cron.hourly

drwxr-xr-x.  2 root root   4096 3月  27 18:48 cron.monthly

-rw-r--r--.  1 root root    457 9月  27 2011 crontab

drwxr-xr-x.  2 root root   4096 9月  27 2011 cron.weekly

用户执行的定时任务

crontab -l

/usr/sbin/ntpdate    time.nist.gov  >>/dev/null  2>&1

1 at 执行一次

# chkconfig --list atd

2 anacron    适合非7*24的服务器

3crond每分钟检查 是否有执行的任务  

crond 进程          crontab 用来设置定时任务规则的命令

-u   用户   -l查看     -r 删除  -e编辑  -i 确认

# crontab -e

# cat /var/spool/cron/root

# cat /etc/cron.deny

# cat /etc/crontab

SHELL=/bin/bash

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

MAILTO=root

HOME=/

# For details see man 4 crontabs

# Example of job definition:

# .---------------- minute (0 - 59)

# |  .------------- hour (0 - 23)

# |  |  .---------- day of month (1 - 31)

# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...

# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# |  |  |  |  |

# *  *  *  *  * user-name command to be executed

分 时 日 月 周   命令                    0是周日

00  23  *  *  *      00 17-19 * * *   每天17 18 19的整点执行  

*/10    每10分钟

学习金字塔              教授给别人

10 1 * *6,0   xxxxxxxxxxxxx

00 */1  * * *

周和日 尽量不要同时用。

* * * * *   echo   hequan >> /root/hequan.txt

# date +%T     14:15:15

# date +%F     2016-03-31

00 9,14 * * *  /bin/sh  /root/x > /dev/null  2>&1

专业  规范  

/dev/null  2>&1  =  1>/dev/null   2>/dev/null   标准输出和标准错误都定向到空。

# cat /var/log/cron   日志

开机启动

*/1 * * * *   /bin/echo "+"   >>  /hequan.log    

# tar zcvf  /tmp/services_$(date +%F-%H)  ./services    

命令行操作成功是定时任务可以成功的大前提

00 */2 * * *  /bin/sh    /server/scripts/tar.sh >/dev/null 2>&1

命令放定时任务是,时间的% 需要转义。

# date +%F%T 

2016-03-3115:40:05

# date +%Y%m%d

20160331

* 00 * * *  /bin/sh    /server/scripts/tar_html.sh >/dev/null

2>&1

cd /var/www

 tar zcvf /tmp/html_$(date +%F).tar.gz  ./html/

/etc/sysctl.conf  内核优化

/etc/hosts  本地解析

/var/log/secure 登陆安全

正则表达式

.  任意一个字符

*重复前面的字符 N次

{n,m} 重复n-m次

[^t]  非t

chmod -R 755  xx

chown -R   root:xx           xx

umask禁止权限         666  - 022   777-022

groupadd -g 801  sa 

定时任务执行的时候,会给系统发邮件 sendmail邮件   ,临时放在/var/spool/clientmqueue/

6没装sendmail

rpm  -qa  | grep sendmail

注释

#/bin/sh

> /dev/null 2>&1

定时任务用脚本文件。

在指定用户下执行相关的定时任务

生存任务程序 不要随意打印输出信息  

路径要规范   /server/scripts

先在测试环境下测试,然后正式环境规范部署。 防止出错。

# df -lk