- 论坛徽章:
- 0
|
检测httpd状态:
#!/bin/bash
service httpd status &> /dev/null //查看状态,strat返回的是0,stop返回的是1 。&>输出重
if [ $? -ne 0 ] ; then 定向不在显示器输出
echo "http server is down. at time:`date`" >> /var/log/htmon.log
service httpd restart
service httpd status &> /dev/null
if [ $? -ne 0 ] ; then
chkconfig --level 2345 httpd on
shutdown -r now
fi
fi
myudel.sh脚本用于批量添加用户帐号
#!/bin/bash
read -p "the number of users(1-99):" num
read -p "username prefix is:" pre
read -p "expire time is (YYYY-mm-dd):" etime
read -p "initial password is:" pw
i=1
while [ $i -le $num ]
do
if [ $i -lt 10 ] ; then
un="${pre}0$i"
else
un="${pre}$i"
fi
useradd -e $etime $un
echo $pw | passwd --stdin $un &> /dev/null
let i++
done
myudel.sh脚本用于批量删除用户帐号 不要求有交互操作
要求管理员执行脚本时输入的第一个位置参数为用户名
#!/bin/bash
if [ $# -le 0 ] ; then /$#是表示命令行中的位置参数数量
echo "error:the prefix of users has not be specified." //用户的前缀并没有被指定
echo "usage: $0 nameprefix"
exit 1
fi
tar cjf /root/users.cnf.tar.gz /etc/passwd /etc/shadow /etc/group &> /dev/null //不输出到显示器
tobedel=`grep "$1" /etc/passwd | cut -d ":" -f1 | grep -v "root"`
for u in $tobedel
do
userdel -r $u &> /dev/null
done |
|