Bash shell脚本练习(五)
1.监控apache服务状态[*]#!/bin/bash
[*]
[*]. /etc/init.d/functions
[*]HTTPPRONUM=`ps -ef | grep http | grep -v grep | wc -l`
[*]
[*]if [ $HTTPPRONUM -lt 1 ]; then
[*] action "httpd is not runing" /bin/false
[*] action "httpd is not runing" /bin/false > /tmp/httpd.log
[*] apachectl restart > /dev/null 2>&1
[*] action "httpd is restart" /bin/true
[*] mail -s "`uname -n`'s httpd restarted at `(date)`" root@example.com < /tmp/httpd.log
[*] exit 1
[*]else
[*] action "httpd is runing" /bin/true
[*] exit 0
[*]fi
2.每10分钟检测一次/usr目录是否超过5G
[*]#!/bin/bash
[*]while true
[*]do
[*] sleep 600
[*] n=$(du -s /usr | cut -f 1)
[*]
[*] if [ $n -gt 5242880 ]; then
[*] echo "/usr目录大于5G" | mail -s "warning" root@example.com
[*] fi
[*]done
3.处理文本,要求合并文件后的输出以下结果:
400 ashok sharma $1,250
100 jason smith$5,000
200 john doe$500
300 sanjay gupta$3,000
# cat employee.txt
100 Jason Smith
200 John Doe
300 Sanjay Gupta
400 Ashok Sharma
# cat bonus.txt
100 $5,000
200 $500
300 $3,000
400 $1,250
# paste employee.txt bonus.txt | awk '{print $1,$2,$3,$5}'|tr '' '' | sort -k 2
400 ashok sharma $1,250
100 jason smith $5,000
200 john doe $500
300 sanjay gupta $3,000
页:
[1]