-
批量添加指定数量的用户实例
查看全部 -
#!/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
查看全部 -
多分支语句case语句
查看全部 -
#!/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
查看全部 -
#!/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
查看全部 -
#!/bin/bash
read -t 30 -p "please input a dir:" dir
if [ -d "dir" ]
then
echo "yes"
else
echo "no"
fi
查看全部 -
#!/bin/bash
rate=$(df -h | grep "/dev/sda1" | 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
查看全部 -
多重条件判断
查看全部 -
字符串的判断
查看全部 -
两个整数之间的比较
查看全部 -
两个文件之间的比较
查看全部 -
按文件权限判断
查看全部 -
两种判断格式
test -e /root/abc
[ -e /root/abc ]
查看全部
举报