@wyjgd
2019-09-22T16:54:53.000000Z
字数 1211
阅读 563
实现传入进程pid,查看对应进程/proc下cpu、内存指标
#!/bin/bashread -p "pid number:" apid=`ps aux | awk '{print $2}'|grep -w $a`if [ ! $pid ];thenecho "input is wrong"elseecho "Mem:`cat /proc/$pid/status |egrep ^Vm`"echo "CPU:`ps -eo pid,%cpu|egrep -w $pid`"fi
实现每分钟检查一个主机端口是否存活(使用nmap),如果检查到端口不在线,sleep 10s,如果三次都不存在,记录到日志
#!/bin/bashread -p "please input ip eg(192.168.1.1):" ipread -p "need check port:" portfor i in {1..3};donmap -sS $ip | awk '{print $1}'|egrep [[:digit:]]|awk -F/ '{print $1}'|grep -w $port &> /dev/nullif [ `echo $?` -ne 0 ];thensleep 2echo "$ip $port is not online">/root/check.txt && echo "Wrong!please cat /root/check.txt"elseecho "$ip $port is online"fidonecrontab -e -uroot*/1 * * * * /root/port.sh
判断参数文件是否为sh后缀的普通文件,如果是,添加所有人可执行权限,否则提示用户非脚本文件
#!/bin/bashif [ ! -f $1 ];thenecho "$1 is wrong(not exist or not sh$ file)"elif [[ $1 =~ .*sh$ ]];thenchmod +x $1;echo "add x power over"fi
实现禁止和允许所有普通用户登录系统
#!/bin/bashread -p "Do you want to lock usually users:yes or no" yif [[ $y == yes || $y == y ]];thentouch /etc/nologinecho "locked"elserm -rf /etc/nologinecho "opened"fi
计算/etc/passwd文件中第10个和第20个用户的ID之和
#!/bin/basha=`getent passwd| awk -F: '{print $3}'|sed -n '10p'`b=`getent passwd| awk -F: '{print $3}'|sed -n '20p'`c=`getent passwd| awk -F: '{print $4}'|sed -n '10p'`d=`getent passwd| awk -F: '{print $4}'|sed -n '20p'`echo "sum.uid=$[a+b]"echo "sum.gid=$[c+d]"