传入PID查看指标脚本
#!/bin/bash
#************************************************
#Author: R
#Date: 2019-09-14 20:04:34
#File pidchack.sh
#************************************************
Rpid=`echo "$1"|sed -nr '/^[0-9]*$/p'`
if [ -z "$Rpid" ];then
echo "Please input num!"
exit 33
fi
ls /proc/$1 &>/dev/null
if [ $? -ne 0 ];then
echo "PID is not exist"
exit 34
fi
Rstatus=`cat /proc/$1/status`
echo "$Rstatus"|grep -i vm
echo "$Rstatus"|grep -i cpu
每分钟检查端口存活
脚本
#!/bin/bash
#************************************************
#Author: R
#Date: 2019-09-14 21:19:21
#File nmapchack.sh
#************************************************
for i in {1..3};do
str=`nmap -sS 192.168.1.1`
str2=`echo $str|grep -i "is up"`
if [ ! -z "$str2" ];then
exit 0
else
if [ "$i" -ne 3 ];then
sleep 10
fi
fi
unset str
done
echo "host is dowm" >> nmaphost.log
添加每分钟执行一次
crontab –e
*/1 * * * * /data/bin/nmapchack.sh
编写脚本判断后缀,是sh则增加执行权限
#!/bin/bash
#************************************************
#Author: R
#Date: 2019-09-17 16:39:03
#File excute.sh
#************************************************
if [ "$#" -eq 0 ];then
echo "Please input file"
exit 1
fi
cat $1 &>/dev/null
if [ "$?" -ne 0 ]; then
echo "File is not exist"
exit 2
fi
nam=`echo $1|sed -nr 's/.*\.(.*)/\1/p'`
if [ "$nam" == "sh" ];then
chmod +x $1
echo "Success"
fi
unset nam
编写脚本实现允许和禁止用户登录
允许用户登录
passwd方式
#!/bin/bash
#************************************************
#Author: R
#Date: 2019-09-17 16:56:22
#File login.sh
#************************************************
if [ "$#" -eq 0 ];then
echo "Please input user name"
exit 1
fi
user=`getent passwd $1 |cut -d: -f3`
if [ -z $user ];then
echo "user is not exist"
exit 2
fi
if [ "$user" -lt 1000 ];then
echo "Can not change system user"
exit 3
fi
passwd -u $1
改shell类型方式
#!/bin/bash
#************************************************
#Author: R
#Date: 2019-09-17 16:56:22
#File login.sh
#************************************************
if [ "$#" -eq 0 ];then
echo "Please input user name"
exit 1
fi
user=`getent passwd $1 |cut -d: -f3`
if [ -z $user ];then
echo "user is not exist"
exit 2
fi
if [ "$user" -lt 1000 ];then
echo "Can not change system user"
exit 3
fi
usermod -s /bin/bash $1
禁止用户脚本
passwd方式
#!/bin/bash
#************************************************
#Author: R
#Date: 2019-09-17 16:56:22
#File nologin.sh
#************************************************
if [ "$#" -eq 0 ];then
echo "Please input user name"
exit 1
fi
user=`getent passwd $1 |cut -d: -f3`
if [ -z $user ];then
echo "user is not exist"
exit 2
fi
if [ "$user" -lt 1000 ];then
echo "Can not change system user"
exit 3
fi
passwd -l $1
改shell类型方式
#!/bin/bash
#************************************************
#Author: R
#Date: 2019-09-17 16:56:22
#File nologin.sh
#************************************************
if [ "$#" -eq 0 ];then
echo "Please input user name"
exit 1
fi
user=`getent passwd $1 |cut -d: -f3`
if [ -z $user ];then
echo "user is not exist"
exit 2
fi
if [ "$user" -lt 1000 ];then
echo "Can not change system user"
exit 3
fi
usermod -s /sbin/nologin $1
计算第10个用户和第20个用户ID之和
#!/bin/bash
#************************************************
#Author: R
#Date: 2019-09-17 17:17:31
#File sumid.sh
#************************************************
user1=`getent passwd|sed -n '10p' |cut -d: -f3`
user2=`getent passwd|sed -n '20p' |cut -d: -f3`
echo "$(($user1+$user2))"
3350

被折叠的 条评论
为什么被折叠?



