文章目录
0.vim编辑器的设置
1.与服务相关的脚本
1.判断apache服务是否正常。
如果不正常则重启,并且输出信息到屏幕,把服务信息写入到一个新的文件中,可以把这个脚本加入到循环定时任务里面去
#!/bin/bash
# 判断apache服务是否开启,如果没有开启则将其自动开启
test=$(ps aux | grep httpd | grep -v httpd)
if [[ -n $test ]]
then
echo "$(date) apache is OK" >> /log/apache
else
echo "$(date) apache is failed"
/usr/bin/systemctl restart httpd &> /dev/null
if [[ $?==0 ]];
then
echo "restart success" >> /log/apache
else
echo "reestart fail" >> /log/apache
fi
fi
2. 检测IP是本机所在的10.10.31.1~100的主机
#!/bin/bash
network="10.10.31"
for setnu in $(seq 1 100)
do
ping -c 1 "$network.$setnu" &> /dev/null && result=1 || result=0
if [ $result==0 ]
then
echo "inet $network.$setnu is normal" >> /root/net
else
echo "inet $network.$setnu is false" >> /root/net
fi
done
2.与文件相关的脚本
1.批量解压缩某个目录下的压缩文件
#!/bin/bash
read -p 'enter a dir' dir
touch /root/text
cd $dir
ls *.tar.gz >> /root/text
ls *.tgz >> /root/text
for i in $(cat /root/text)
do
tar -zxf $i &> /dev/null
done
rm -rf /root/text
3.与用户管理相关的脚本
1.批量添加用户
#!/bin/bash
# 批量添加用户
read -p "name:" name
read -p "num:" num
read -p "password:" passwd
if [ ! -z $name -a ! -z $num -a ! -z $passwd ];then
y=$(echo $num | sed 's/[0-9]//g')
if [[ -z $y ]]
then
for (( i=0;i<$num;i=i+1 ))
do
/usr/sbin/useradd "$name$i" &> /dev/null
echo $passwd | /usr/bin/passwd --stdin "$name$i" &> /dev/null
done
fi
fi
删除所有普通用户
#!/bin/bash
#删除所有普通用户
for i in $(cat /etc/passwd | grep "/bin/bash" | grep -v "/root" | cut -d ":" -f 1)
do
userdel -r $i
done