几个常用的小shell

1、查看进程的一个小shell

说明:适合批量执行日志压缩,特别是日志有规律的增长的日志类型,参考如下:

ls |grep abc|grep -v gz|grep -v `date +%Y%m%d`|xargs -l -t gzip

 2、查看业务进程是否启动?如未启动则启动,如启动则提示“程序已经启动,用户名是,UID是,PID是”,可以一次自己DIY起来

#!/bin/sh
#Start the CoreProcess
cd
source .cshrc
while [1]
do
	pnums=`ps -ef|grep CoreProcess | grep -v grep | wc -l`
	http=`ps -ef|grep http | grep -v grep | wc -l`
	uid=`ps -ef|grep CoreProcess|awk '{print $2}' `
if [ $pnums -eq 0 ]
		then
				cd /opt/CoreProcess/
				./CoreProcess –d		
elif 	[$pnums -eq 1]
		then
				echo "###########################################"
				echo "###The Uid is $uid                      ###"
				echo "###########################################"
		exit;
elif [ $http -eq 0]
	then
		/usr/local/apache2/bin/httpd -k start -DSSL
elif [ $http -gt 10]
	then
				echo "###########################################"
				echo "###The Number of Processes is $http     ###"
				echo "###########################################"
	exit;		
done

 这个shll是一个最基本的模型,可以自己DIY。

有一些疑问,就是如何做并列和或的选择判断?不是很懂,得加强学习SHELL

原文地址:https://www.cnblogs.com/alexy/p/shell1.html