第八周

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

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

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

#!/bin/bash

#

for i in 172.16.250.{1..254};do

        if ping -c 6  $i &> /dev/null; then

                echo -e “\e[1;31m $i \e[0m”

        else

                echo -e “\e[1;32m $i \e[0m”

        fi

done

 

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

(1)   ip addr add IFADDR dev IFACE

(2)   ifconfig IFACE_LABEL IPADDR/NETMASK

示例:

[root@localhost yum.repos.d]# ip addr show eth1

4: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000

    link/ether 00:0c:29:ca:38:36 brd ff:ff:ff:ff:ff:ff

[root@localhost yum.repos.d]# ip addr add 192.168.200.66/24 dev eth1

[root@localhost yum.repos.d]# ip addr add 192.168.200.99/24 dev eth1

[root@localhost yum.repos.d]# ifconfig eth1:0 192.168.200.132/24

[root@localhost yum.repos.d]# ip addr show dev eth1

4: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000

    link/ether 00:0c:29:ca:38:36 brd ff:ff:ff:ff:ff:ff

    inet 192.168.200.66/24 scope global eth1

    inet 192.168.200.99/24 scope global secondary eth1

    inet 192.168.200.132/24 brd 192.168.200.255 scope global secondary eth1:0

(3)编辑配置文件/etc/sysconfig/network-scripts/ifcfg-IFACE

注意:使用命令配置会立即有效,但不会永久有效。

   编辑完配置文件,需要重启网络服务,才会立即生效

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

   (1) 假设某目录(/etc/rc.d/rc3.d/)下分别有K开头的文件和S开头的文件若干;

   (2) 显示所有以K开头的文件的文件名,并且给其附加一个stop字符串;

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

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

#!/bin/bash

#

a=0

b=0

for i in $(ls /tmp/rc3.d) ;do

    echo $i > /tmp/1.txt

    if [ $(grep -o “^K” /tmp/1.txt ) == “K” ]  &> /dev/null;then

        echo   ${i}stop

        let a++  

    elif [ $(grep -o “^S”  /tmp/1.txt ) == “S” ]  &> /dev/null;then

        echo ${i}start

        let b++

    else

        echo $i

    fi

done

rm -rf /tmp/1.txt

echo “The number of files at the beginning of the K is: $a”

echo “The number of files at the beginning of the S is: $b”

 

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

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

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

#!/bin/bash

#

if [ $# -lt 2 ];then

    echo “User name is at least two.”

        exit 2

fi

 

a=0

for i in $*;do

    if ! id $i &> /dev/null;then

        echo “$i is not exists.”

        exit 3

    else

        for j in $(id -u $i);do   

            j=$(($j+$a))

        done

        a=$j

     fi

done

echo   “The sum of $* id is: $a”

 

5、写一个脚本

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

   (2) 逐个显示每个目录的所有一级文件或子目录的内容类型;

   (3) 统计一共有多少个目录;且一共显示了多少个文件的内容类型;

#!/bin/bash

#

if [ $# -lt 1 ];then

        echo “Directory numbers wrong.”

        exit 2

else

        for i in $*;do

                if  ! [ -d $i ];then

                        echo “$i is not directory.”

                        exit 3

                fi

        done

fi

dir=$(pwd)

a=0

x=0;xx=0;xxx=0;xxxx=0;xxxxx=0;xxxxxx=0;xxxxxxx=0

for j in $*;do

        cd $j

        for i in $(ls);do

                if [ -f $i ];then

                        echo “$i is common file.”

                        x=1

                elif [ -d $i ];then

                        echo “$i is directory.”

                        let a++

                        xx=1

                elif [ -L $i ];then

                        echo “$i is link file.”

                        xxx=1

                elif [ -b $i ];then

                        echo “$i is block file.”

                        xxxx=1

                elif [ -c $i ];then

                        echo “$i is character file.”

                        xxxxx=1

                elif [ -p $i ];then

                        echo “$i is pipeline file.”

                        xxxxxx=1

                elif [ -S $i ];then

                        echo “$i is socket file.”

                        xxxxxxx=1

                else

                        echo “$i Unkown.”

                fi

        done

done

cd $dir

echo “Directory:$a”

echo “Type:$(($x+$xx+$xxx$xxxx+$xxxxx+$xxxxxx+$xxxxxxx))”

 

6、写一个脚本

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

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

#!/bin/bash

#

#!/bin/bash

#

if ! [ $# -le 1 ] ;then

        echo arguments is wrong.

        exit 2

elif ! id $1 &> /dev/null;then

        echo user is not exists.

        exit 3

else

        a=$(id -u $1)

fi

if [ $a -ge 500 ];then

        echo $1 is general user.

else

        echo $1 is system user or root

fi

 

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

#!/bin/bash

#

for i in 172.16.250.{20..100};do

        if ping -c 6  $i &> /dev/null; then

                echo $i

done

 

8、打印九九乘法表;

#!/bin/bash

for i in {1..9};do

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

                echo -n -e  “$j*$i=$(($i*$j))\t ”

        done

        echo

done

 

 

i=1

while [ $i -le 9 ];do

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

                echo -n -e  “$j*$i=$(($i*$j))\t ”

        done

        echo

        let i++

done

 

原创文章,作者:N26-xiaocong,如若转载,请注明出处:http://www.178linux.com/76783

(0)
N26-xiaocongN26-xiaocong
上一篇 2017-05-23 10:23
下一篇 2017-05-23 15:05

相关推荐

  • Linux 中cp 、rm和mv与inode之间的关系

    1.cp和inode          当文件不存在时,分配一个新的inode号,创建新文件;          当文件存在时,则inode号采用被覆盖之前的目标文件的inode号。 2.rm和ino…

    2017-07-21
  • 第一周作业

    1. 描述计算机的组成及其功能 CPU:CPU包括运算器和控制器,并采用大规模集成电路工艺制成的芯片,又称微处理器芯片。 运算器又称算术逻辑单元(Arithmetic Logic Unit简称ALU)。它是计算机对数据进行加工处理的部件,包括算术运算(加、减、乘、除等)和逻辑运算(与、或、非、异或、比较等)。 控制器负责从存储器中取出指令,并对指令进行译码;…

    Linux干货 2017-01-04
  • N25-第二周博客作业

    1. Linux上的文件管理类命令都有那些,其常用的使用方法及其相关示例演示. 文件管理工具有cp, mv, rm cp命令: 复制文件或文件夹 语法: cp [OPTION]… [-T] SOURCE DEST 单源复制cp [OPTION]… SOURCE… DIRECTORY 多源复制 常用选项:  &nb…

    Linux干货 2016-12-10
  • 系统启动这块的一些实验及基本内容–下

    下面我来讲下grub,grub在编辑的时候可以进入一种模式就是单用户模式,就是当grub.conf文件未写入密码时,普通用户将直接忽略系统密码进入系统,所以这可以称为一个捷径,也可以成为一个漏洞,当然linux的前辈们不可能连这个都想不到,他们也有自己的办法,这就是我们grub的两层加密机制,在选定登陆界面之前可以设置一次,启动内核时也可以设置一次,密码也可…

    Linux干货 2016-09-13
  • N25-第十三周博客作业

    1、建立samba共享,共享目录为/data,要求:(描述完整的过程) 1)共享名为shared,工作组为magedu;2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名;3)添加samba用户gentoo,centos和ubu…

    Linux干货 2017-04-19
  • 马哥教育21期网络班—第12周课程+练习—-LAMP练习下

    在LAMP架构中,请分别以fpm工作为独立守护进程的方式来支持http yum groupinstall "Development Tools" "Server Platform Development"——>安装包组1、编译安装Apacheht…

    Linux干货 2016-09-26

评论列表(1条)

  • luoweiro
    luoweiro 2017-06-26 22:57

    如果有执行结果效果会更好,加油。