第八周作业

第八周作业

1、写一个脚本,使用ping命令推测172.16.250.1-172.16.250.254之间的所有主机的在线状态;

在线的主机使用绿色显示;

不在线的主机使用红色显示;

 

#!/bin/bash

for i in {1..254};do

if ping -c 1 -w 1 192.168.1.$i &> /dev/null;then

echo -e “\033[32m192.168.1.$i\033[0m is up”

else

echo -e “\033[31m192.168.1.$i\033[0m is down”

fi

done

 

2、如何给网络接口配置多个地址,有哪些方式?

1、使用ifconfig命令

2、使用ip命令

3、通过修改配置文件

4、通过NetworkManage设置 3、写一个脚本,完成以下功能

1、假设某目录/etc/rc.d/rc3.d/下分别有k开头的文件和S开头的文件苦于;

2、显示所胡以k开头的文件的文件名,并且给其附加一个stop字符串;

3、显示所有以S开头的文件的文件名,并且给其附加一个start字符串;

4、分别统计S开头和K开头的文件各有多少;

 

#!/bin/bashdeclare -i n=0;declare -i m=0;for FILE in `ls /etc/rc.d/rc3.d`;do        if [[ $FILE =~ ^K ]];then                echo “$FILE stop”                let n=$n+1        elif [[ $FILE =~ ^S ]];then                echo “$FILE start”                let m=$m+1        fidoneecho “First char is S = $m , First char is K = $n”

 

4、写一个脚本,完成以下功能

1、脚本能接受用户名作为参数;

2、计算此些用户的ID之和;

 

#!/bin/bashdeclare -i SUM=0for i in $@;do        if ! id $i &> /dev/null ; then                echo “$i is not exists”        else                let SUM=$SUM+$(id -u $i);        fidoneecho “uid sum = $SUM”

 

5、写一个脚本:

1、传递一些目录给此脚本;

2、逐个显示每个目录的所有一级文人报幕员子目录的内容类型;

3、统计一共有多少个目录;且一共多少个文件的内容类型;

 

#!/bin/bash

declare -i dir=0

declare -i filetype=0

for i in $@;do

if [ -d $i ];then

for j in $i/*;do

file $j &> /dev/null

let filetype=$filetype+1

if [ -d $j ];then

let dir=$dir+1

fi

 

done

else

echo “$i is not a dirfile or not exists”

fi

done

echo ” dir = $dir ,all file = $filetype

 

6、写一个脚本:

通过命令行传递一个参数给脚本,参数为用户名

如果用户的id号大于等于500,则显示此用户为普通用户;

 

#!/bin/bashread -p “please send a username:” UNAMEif id $UNAME &> /dev/null ;then        if [ $(id -u $UNAME) -gt 500 ];then                echo “this is a normal user”        fielse        echo “no this user”fi

 

7、写一个脚本,用ping命令测试172。16.250.20-172.16.250.100以内有哪些主机在线,将在线的显示出来;

#!/bin/bash

#

declare -i uphosts=0

declare -i downhosts=0

 

for i in {1..216}; do

if ping -W 1 -c 1 192.168.$i.1 &> /dev/null; then

echo “192.168.$i.1 is up.”

let uphosts+=1

else

echo “192.168.$i.1 is down.”

let downhosts+=1

fi

done

 

echo “Up hosts: $uphosts, Down hosts: $downhosts.”

8、打印九九简洁表;

1 #!/bin/bash

2 #

3 for j in {1..9}; do

4         for i in $(seq 1 $j); do

5                 echo -n -e “${i}X${j}=$[${i}*${j}]\t”

6         done

7         echo

8 done

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/88331

(0)
N27_yangjifengN27_yangjifeng
上一篇 2017-11-13 09:33
下一篇 2017-11-13 10:53

相关推荐

  • 文本处理工具

    文本处理工具 1、查看文件内容 cat -v 显示非打印字符       -E 显示$      -T 显示TAB      -n 显示行号      -s 将连续的重复空行变成一行      -A = -vE…

    2017-07-30
  • 文本过滤、文本查找工具应用示例

    文本过滤、文本查找工具应用示例 1.显示当前系统上root、fedora或user1用户的默认shell [root@localhost ~]# cat /etc/passwd|grep “^root\>\|^fedora\>\|^user1\>”|cut -d: -f7 /bin/bash /bin/bash /bin/bash 2.找出…

    Linux干货 2017-07-30
  • 编译httpd2.4.10踩坑记

    作者【Jev Tse】【版权所有】  系统环境:centos6.8     【本文概览】     零、httpd2.4.10编译总结         1、基础环境         2、依赖包组   &…

    Linux干货 2016-11-29
  • Centos图形界面和命令界面模式切换

    大家都知道,centos有两种用户界面模式,一种是图形界面,也就是我们常说的Xwindows界面;另一种就是命令界面。有时因为方便需要在图形模式下安装一些程序,因图形界面占用的内存等资源较大,影响系统的运行,安装完后需要把系统切换到命令模式下运行,下面就两种模式如何进行切换做一下说明。 CentOS的启动模式共分为7级,分别是: 0-  停机 1-…

    系统运维 2015-07-19
  • 第三周

    作业

    2017-12-15
  • linux入门基础命令总结

    命令基础

    2017-09-18

评论列表(1条)

  • 马哥教育
    马哥教育 2017-12-02 09:05

    作业本身做的很不错,但是这个排版太差了,要自己复制下来一个一个的去测,才可以得出结果。