shell和脚本二选一使用练习题

回复 收藏

本帖最后由 wsw13640218682 于 2016-2-18 17:05 编辑

QQ图片20151216115900.jpg


                        可以用shell,也可以通过脚本来实现参考脚本:{{{密码回复可见}}}

QQ图片20151216115900.jpg
2016-01-30 02:57 举报
已邀请:
0

杨金彪

赞同来自:

额不会告诉你额是来赚学分的😂
0

qwerthink

赞同来自:

好难,没有思路
0

licengceng

赞同来自:

学习
0

maria

赞同来自:

第三个
  1. #!/bin/bash
  2. while :
  3. do
  4. read -p "Input your Pay:" pay
  5. tax=0;
  6. if [ $pay -lt 3000 ]
  7. then
  8.     tax=0;
  9. elif [ $pay -ge 3000 ] && [ $pay -lt 5000 ]
  10. then
  11.     taxm=1;
  12. elif [ $pay -ge 5000 ] && [ $pay -lt 8000 ]
  13. then
  14.     taxm=2;
  15. elif [ $pay -ge 8000 ]
  16. then
  17.     taxm=3;
  18. fi

  19. case $taxm in
  20. 1)
  21.     tax=`echo "scale=2; ($pay-3000)*0.1" |bc -l`
  22.     ;;
  23. 2)
  24.     tax=`echo "scale=2; (($pay-5000)*0.15)+200" |bc -l`
  25.     ;;
  26. 3)
  27.     tax=`echo "scale=2; (($pay-8000)*0.2)+200+450" |bc -l`
  28.     ;;
  29. *)
  30.     echo "Try again!"
  31.     continue
  32.     ;;
  33. esac

  34. echo "You need to pay $tax ."
  35. done
0

thedawn

赞同来自:

1
0

北辰星

赞同来自:

学习
0

wsw13640218682

赞同来自:


你这个比我的写得更好,可以准确计算到小数位,但第一次输入有小数位的数字时候会提示错误,要输入一次整数后,再输入有小数点的数字就不会报错
0

沧海一叶

赞同来自:

哈哈,没什么难度
0

奋斗的种子

赞同来自:

1
0

Landon

赞同来自:

没怎么验证 写了会玩玩,第二个不吸引人就不写了!
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

迷城

赞同来自:

不错
0

boy461205160

赞同来自:

{:4_91:}
0

boy461205160

赞同来自:

本帖最后由 boy461205160 于 2016-2-18 17:01 编辑
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

陈秋明

赞同来自:

kankan
0

liushuangwei

赞同来自:

第一个,我自己 的思路

#!/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

jinm

赞同来自:

学习
0

jinm

赞同来自:

学习
0

jinm

赞同来自:

学习
0

wangxinpeng

赞同来自:

看第一题
0

qin521ne

赞同来自:

11
0

xzzlamp

赞同来自:

11
0

17095053557

赞同来自:

第一题:看着再修改,觉得有必要判断非法的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
0

陈森林

赞同来自:

{:4_91:}
0

a1138665328

赞同来自:

kankan
0

Toornix

赞同来自:

看下答案
0

monga

赞同来自:

学习
0

monga

赞同来自:

学习
0

hsm

赞同来自:

学习
0

jonnylin

赞同来自:

学习

0

小毅

赞同来自:

学习
0

lanceli

赞同来自:

学习下
0

13805775620

赞同来自:

学习
0

googleqicq

赞同来自:

#!/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
坐等发工资
0

Bullet_Point

赞同来自:

1
0

kw是id

赞同来自:

#!/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

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: