linux常用的shell编程例子

模板一:ip配置

#!/bin/sh

ifconfig eth0 192.168.1.xxx netmask 255.255.255.0 up >/dev/null 2>&1
/sbin/route add default gw 192.168.1.1

模板二:Samba挂载

#!/bin/sh
mount -o nolock 192.168.1.xxx:/nfs /mnt

模板三:检测程序重启,内存检测,CPU占有率,IP分配情况

#!/bin/bash

#trap "echo ` SIGTERM is trapped!`" SIGTERM
pathbin=/opt/

echo 0 > /tmp/UpgradeFlag

sudo echo $(date) >> /opt/log.txt

sleep 10

sudo echo $(date) >> /opt/log.txt

/opt/memory_limit.sh 90%&
/opt/CPU_occupancy_rate.sh 100.0&
trap "echo `singal is trapped.`" SIGTERM
while :
do
	for i in webs Client file_num_limit;
	do
		pid=`pidof $i`
		if [ -z "${pid}" ]; then
			if [ "$i" = "file_num_limit" ];
			then
				${pathbin}$i /opt/Log_msg&
			else
				${pathbin}$i &
			fi
		fi
	done

	if [ '1' -eq `cat /tmp/UpgradeFlag` ]; then
	echo 0 > /tmp/UpgradeFlag
	sleep 3
	echo "upgrade : tar xzvf /opt/Upgrade.bin -C /"
	killall webs Client file_num_limit
	tar xzvf /opt/Upgrade.bin -C /
	sleep 1
	reboot
	fi
	sleep 3
done

exit 0

内存检测memory_limit.sh

#! /bin/bash

str2=$1

echo "$1"

while true

do
	string=$(df -h /root)

	result=$(echo $string | grep "${str2}")

	if [ -n "$result" ]; then
		echo "exist ----"
		rm /opt/Log_msg/*
		killall Client
		sleep 3
	fi
	
	sleep 3
done



exit 0

CPU占有率CPU_occupancy_rate.sh

#! /bin/bash

str2=$1

echo "$1"

while true

do 
	string=$(ps -aux | grep kswapd0)
	
	#echo "${string}"

	result=$(echo $string | grep "${str2}")
	
	echo "$result"	

	if [ -n "$result" ]; then
		echo "exist ---"
		killall kswapd0
		sleep 3
	fi

	sleep 3
done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只很笨很懒的肥猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值