-
例子:删除用户脚本
查看全部 -
批量添加指定数量的用户
cat /etc/passwd 查看当前所有用户
查看全部 -
从一加到一百
查看全部 -
#!/bin/bash
cd /root/test
ls *.tar.gz > ls.log(>覆盖)
ls *.tgz >> ls.log(>>追加)
for i in $(cat ls.log)
do
tar -zxvf $i &> /dev/null
done
rm -rf ls.log
查看全部 -
#!/bin/bash
read -t 10 -p "please input your choice yes/no: " choice
case $choice in
"yes")
echo "your choice is yes"
;;
"no")
echo "your choice is no"
;;
*)
echo "your choice is another"
;;
esac
查看全部 -
#!/bin/bash
read -t 30 -p "Please input a file name:" file
if [ -z "$file" ]
then
echo "Error, please input a file name!"
exit 11
elif [ ! -e "$file" ]
then
echo "Your input is not a file name!"
exit 22
elif [ -f "$file" ]
then
echo "$file is a regular file!"
elif [ -d "$file" ]
then
echo "$file is a directory !"
else
echo "$file is another file!"
fi
查看全部 -
#!/bin/bash
read -t 30 -p "Please input num1:" num1
read -t 30 -p "Please input num2:" num2
read -t 30 -p "Please input operator:" ope
if [ -n "$num1" -a -n "$num2" -a -n "$ope" ]
then
test1=$(echo $num1 | sed 's/[0-9]//g')
test2=$(echo $num2 | sed 's/[0-9]//g')
if [ -z "$test1" -a -z "$test2" ]
then
if [ "$ope" == '+' ]
then
result=$(($num1+$num2))
elif [ "$ope" == '-' ]
then
result=$(($num1-$num2))
elif [ "$ope" == '/' ]
then
result=$(($num1 / $num2))
elif [ "$ope" == '*' ]
then
result=$(($num1*num2))
else
echo "Error: the input operator is worng, please input +-*/"
exit 111
fi
else
echo "Error: Please input numbers!"
exit 222
fi
echo "$num1 $ope $num2 is $result"
else
echo "Error: You input null value!"
exit 333
fi
查看全部 -
多分支if 条件语句
查看全部 -
#!/bin/bash
test=$(ps aux | grep "httpd" | grep -v "grep")
if [ -n "$test" ]
then
echo "httpd is on"
else
echo "httpd is off"
/etc/rc.d/init.d/httpd start
fi
查看全部 -
ps aux:查看系统中所有正在运行的进程,
apache关键字
httpd grep -v grep:取反,不包含grep
判断apache服务是否启动 ps aux | grep httpd |grep -v grep
查看全部 -
#!/bin/bash
read -t 10 -p "input your etcname" etcname
if [-d "$etcname"]
then
echo "yes"
else
echo "no"
fi
查看全部 -
#!/bin/bash
rate=$(df -h | grep "/dev/sda1" | awk '{print $5}' | cut -d "%" -f 1)
if [ "$rate" -ge "80" ]
then
echo "/dev/sda1 is full"
fi
查看全部 -
#!/bin/bash
test=$(env | grep "USER" | cut -d "=" -f 2)
if [ "$test" == "root" ]
then
echo "Current user id root."
fi
查看全部 -
多重条件判断
查看全部 -
字符串的判断
查看全部
举报