1.监控apache服务状态

 
  
  1. #!/bin/bash 
  2.  
  3. . /etc/init.d/functions 
  4. HTTPPRONUM=`ps -ef | grep http | grep -v grep | wc -l` 
  5.  
  6. if [ $HTTPPRONUM -lt 1 ]; then 
  7.         action "httpd is not runing" /bin/false 
  8.         action "httpd is not runing" /bin/false > /tmp/httpd.log 
  9.         apachectl restart > /dev/null 2>&1 
  10.          action "httpd is restart" /bin/true 
  11.         mail -s "`uname -n`'s httpd restarted at `(date)`" root@example.com < /tmp/httpd.log 
  12.         exit 1 
  13. else 
  14.         action "httpd is runing" /bin/true 
  15.         exit 0 
  16. fi 

2.每10分钟检测一次/usr目录是否超过5G
 
  
  1. #!/bin/bash 
  2. while true 
  3. do 
  4.         sleep 600 
  5.         n=$(du -s /usr | cut -f 1) 
  6.  
  7.         if [ $n -gt 5242880 ]; then 
  8.                 echo "/usr目录大于5G" | mail -s "warning" root@example.com 
  9.         fi 
  10. done 

3.处理文本,要求合并文件后的输出以下结果:
400 ashok sharma $1,250
100 jason smith  $5,000
200 john doe  $500
300 sanjay gupta  $3,000
 
[root@shell ~]# cat employee.txt 
100 Jason Smith 
200 John Doe 
300 Sanjay Gupta 
400 Ashok Sharma
[root@shell ~]# cat bonus.txt 
100 $5,000 
200 $500 
300 $3,000 
400 $1,250
[root@shell ~]# paste employee.txt bonus.txt | awk '{print $1,$2,$3,$5}'|tr '[A-Z]' '[a-z]' | sort -k 2
400 ashok sharma $1,250
100 jason smith $5,000
200 john doe $500
300 sanjay gupta $3,000