0
第三个
- #!/bin/bash
- while :
- do
- read -p "Input your Pay:" pay
- tax=0;
- if [ $pay -lt 3000 ]
- then
- tax=0;
- elif [ $pay -ge 3000 ] && [ $pay -lt 5000 ]
- then
- taxm=1;
- elif [ $pay -ge 5000 ] && [ $pay -lt 8000 ]
- then
- taxm=2;
- elif [ $pay -ge 8000 ]
- then
- taxm=3;
- fi
- case $taxm in
- 1)
- tax=`echo "scale=2; ($pay-3000)*0.1" |bc -l`
- ;;
- 2)
- tax=`echo "scale=2; (($pay-5000)*0.15)+200" |bc -l`
- ;;
- 3)
- tax=`echo "scale=2; (($pay-8000)*0.2)+200+450" |bc -l`
- ;;
- *)
- echo "Try again!"
- continue
- ;;
- esac
- echo "You need to pay $tax ."
- done
0
没怎么验证 写了会玩玩,第二个不吸引人就不写了!
1.
#!/bin/bash
sum=0
for i in `seq 1 255`
do
if ping -c 2 -w2 115.239.210.$i >/dev/null 2>&1
then
return 0
fi
if [ $? == 0 ]
then
echo "115.239.210.$i"
((sum=$sum+1))
echo "$sum"
fi
done
2.
#!/bin/bash
while :
do
read -t 10 -p "input your salary: " salary
a=`echo $salary|sed s'/[0-9]//g'`
if [ ! -z $a ]
then
echo "you should input a integer number:"
continue
else
break
fi
done
if [ $salary -gt 8000 ]
then
taxes=`echo "scale=3;$salary*0.2"|bc -l`
echo "your taxes is $taxes"
elif [ $salary -ge 5000 -a $salary -le 8000 ]
then
taxes=`echo "scale=3;$salary*0.15"|bc -l`
echo "your taxes is $taxes"
elif [ $salary -gt 3000 -a $salary -lt 5000 ]
then
taxes=`echo "scale=3;$salary*0.1"|bc -l`
echo "your taxes is $taxes"
else
echo "you don't need pay the taxes."
fi
1.
#!/bin/bash
sum=0
for i in `seq 1 255`
do
if ping -c 2 -w2 115.239.210.$i >/dev/null 2>&1
then
return 0
fi
if [ $? == 0 ]
then
echo "115.239.210.$i"
((sum=$sum+1))
echo "$sum"
fi
done
2.
#!/bin/bash
while :
do
read -t 10 -p "input your salary: " salary
a=`echo $salary|sed s'/[0-9]//g'`
if [ ! -z $a ]
then
echo "you should input a integer number:"
continue
else
break
fi
done
if [ $salary -gt 8000 ]
then
taxes=`echo "scale=3;$salary*0.2"|bc -l`
echo "your taxes is $taxes"
elif [ $salary -ge 5000 -a $salary -le 8000 ]
then
taxes=`echo "scale=3;$salary*0.15"|bc -l`
echo "your taxes is $taxes"
elif [ $salary -gt 3000 -a $salary -lt 5000 ]
then
taxes=`echo "scale=3;$salary*0.1"|bc -l`
echo "your taxes is $taxes"
else
echo "you don't need pay the taxes."
fi
0
本帖最后由 boy461205160 于 2016-2-18 17:01 编辑
第二题:
#!/bin/bash
#判断apache和mysql通过rpm包还是编译安装;
ht=httpd
my=mysqld
if [ -n /etc/init.d/httpd && -n /etc/init.d/mysqld ]
then
yum install mysql httpd -y
service httpd start;service mysqld start
elif ps aux |grep $ht > /dev/null 2&>1; ps aux |grep $my > /dev/null 2&>1
then
echo " mysql and httpd is starting"
else
echo "mysql and httpd not service."
fi
done
2、每隔1小时检查httpd服务状态:
#!/bin/bash
while :
do
service httpd restart
sleep 3600
done
wsw13640218682 发表于 2016-2-5 13:27
你这个比我的写得更好,可以准确计算到小数位,但第一次输入有小数位的数字时候会提示错误,要输入一次整 ...
第二题:
#!/bin/bash
#判断apache和mysql通过rpm包还是编译安装;
ht=httpd
my=mysqld
if [ -n /etc/init.d/httpd && -n /etc/init.d/mysqld ]
then
yum install mysql httpd -y
service httpd start;service mysqld start
elif ps aux |grep $ht > /dev/null 2&>1; ps aux |grep $my > /dev/null 2&>1
then
echo " mysql and httpd is starting"
else
echo "mysql and httpd not service."
fi
done
2、每隔1小时检查httpd服务状态:
#!/bin/bash
while :
do
service httpd restart
sleep 3600
done
0
第一个,我自己 的思路
#!/bin/bash
count=0
for a in {1..254}
do
online=`ping -c 5 10.142.3.$a | grep "ttl=" | wc -l`
if [[ $online -ge 1 ]];then
echo "10.142.3.$a" ok
let count=$count+1
else
echo "10.142.3.$a" wrong
fi
done
echo "the online hosts are $count"
#!/bin/bash
count=0
for a in {1..254}
do
online=`ping -c 5 10.142.3.$a | grep "ttl=" | wc -l`
if [[ $online -ge 1 ]];then
echo "10.142.3.$a" ok
let count=$count+1
else
echo "10.142.3.$a" wrong
fi
done
echo "the online hosts are $count"
0
第一题:看着再修改,觉得有必要判断非法的ip
#!/bin/bash
##测试ip是否能够测试通过
checkip(){
if echo $1 |egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$';then
a=`echo $1 | awk -F. '{print $1}'`
b=`echo $1 | awk -F. '{print $2}'`
c=`echo $1 | awk -F. '{print $3}'`
d=`echo $1 | awk -F. '{print $4}'`
for n in $a $b $c $d ;do
if [ $n -ge 255 ] || [ $n -le 0 ];then
echo "您输入一个非法的的ip"
exit;
fi
done
##合法的ip
if ping -c2 $1 >/dev/null 2>&1;then
echo "主机能够ping通";
else
echo "主机不能够ping通";
fi
else
echo "您输入了一个非法的ip"
exit
fi
}
read -t 10 -p "请在十秒内输入一个合法的ip" str
checkip $str
#!/bin/bash
##测试ip是否能够测试通过
checkip(){
if echo $1 |egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$';then
a=`echo $1 | awk -F. '{print $1}'`
b=`echo $1 | awk -F. '{print $2}'`
c=`echo $1 | awk -F. '{print $3}'`
d=`echo $1 | awk -F. '{print $4}'`
for n in $a $b $c $d ;do
if [ $n -ge 255 ] || [ $n -le 0 ];then
echo "您输入一个非法的的ip"
exit;
fi
done
##合法的ip
if ping -c2 $1 >/dev/null 2>&1;then
echo "主机能够ping通";
else
echo "主机不能够ping通";
fi
else
echo "您输入了一个非法的ip"
exit
fi
}
read -t 10 -p "请在十秒内输入一个合法的ip" str
checkip $str
0
#!/bin/bash
while :
do
read -p "please your pay: " pay
if [ $pay -lt 3000 ]
then
echo "charge free!"
elif [ $pay -ge 3000 ] && [ $pay -lt 5000 ]
then
tax=`echo "($pay-3000)*0.1" |bc -l`
echo your tax is $tax
elif [ $pay -ge 5000 ] && [ $pay -lt 8000 ]
then
tax=`echo "(($pay-5000)*0.15)+200" |bc -l`
echo your tax is $tax
elif [ $pay -ge 8000 ]
then
tax=`echo "(($pay-8000)*0.20)+200+450" |bc -l`
echo your tax is $tax
fi
exit
done
坐等发工资
while :
do
read -p "please your pay: " pay
if [ $pay -lt 3000 ]
then
echo "charge free!"
elif [ $pay -ge 3000 ] && [ $pay -lt 5000 ]
then
tax=`echo "($pay-3000)*0.1" |bc -l`
echo your tax is $tax
elif [ $pay -ge 5000 ] && [ $pay -lt 8000 ]
then
tax=`echo "(($pay-5000)*0.15)+200" |bc -l`
echo your tax is $tax
elif [ $pay -ge 8000 ]
then
tax=`echo "(($pay-8000)*0.20)+200+450" |bc -l`
echo your tax is $tax
fi
exit
done
坐等发工资
0
#!/bin/bash
read -p "please input your salary: " n
if [ $n -gt 8000 ]
then
a=`echo $n*0.2|bc`
echo "you should pay $a as personal income tax"
elif [ $n -gt 5000 -a $n -lt 8000 ]
then
a=`echo $n*0.15|bc`
echo "you should pay $a as personal income tax"
elif [ $n -gt 3000 -a $n -lt 5000 ]
then
a=`echo $n*0.1|bc`
echo "you should pay $a as personal income tax"
else
echo "you don't have to pay the as personal income tax"
fi
read -p "please input your salary: " n
if [ $n -gt 8000 ]
then
a=`echo $n*0.2|bc`
echo "you should pay $a as personal income tax"
elif [ $n -gt 5000 -a $n -lt 8000 ]
then
a=`echo $n*0.15|bc`
echo "you should pay $a as personal income tax"
elif [ $n -gt 3000 -a $n -lt 5000 ]
then
a=`echo $n*0.1|bc`
echo "you should pay $a as personal income tax"
else
echo "you don't have to pay the as personal income tax"
fi
编辑回复