第八周作业

第八周作业

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

相关推荐

  • 运维自动化之系统安装

    自动化安装系统,cobbler的安装使用

    Linux干货 2018-01-15
  • rsyslog日志服务

    一、知识整理: 1、日志服务rsyslogd新特点:     多线程;     基于SSL/TLS/UDP/TCP/RELP网络协议传输日志信息;     强大的过滤器,实现过滤日志信息中任何部分的内容;   &nbsp…

    Linux干货 2016-10-24
  • chrony、sudo、rsyslog

    chrony 程序环境: 配置文件:/etc/chrony.conf 主程序文件:chronyd 工具程序:chronyc unit file: chronyd.service 配置文件:chrony.conf server:指明时间服务器地址; allow NETADD/NETMASK allow all:允许所有客户端主机; deny NETADDR/N…

    Linux干货 2017-06-13
  • 10 文本处理のsed狗带

    sed 介绍 工作原理 语法 参数选项:-n, -e, -r, -f, -i 地址定界 编辑命令 查找替换 空间操作 练习 参考文档 sed介绍 sed是一个(stream editor)。         1) :使用sed只能在命令行下输入编辑命令来编辑文…

    Linux干货 2016-08-12
  • Linux用户、组、权限管理

    Linux用户与组管理 Linux系统上,用户通过内核拷贝程序到内存中,从此发起进程。进程以发起者的身份进行,进程对文件的访问权限,取决于发起进程的用户的权限。而有些后台进程或服务类进程以非管理员身份运行,为此也需要创建多个普通用户,此类用户不需登录。 系统中,用户类别分为管理员和普通用户(系统用户和登录用户),组类别分为基本组和附加组。管理系统上的用户与组…

    Linux干货 2016-12-07
  • Linux 性能监控、测试、优化工具

    Linux 平台上的性能工具有很多,眼花缭乱,长期的摸索和经验发现最好用的还是那些久经考验的、简单的小工具。系统性能专家 BrendanD. Gregg 在最近的 LinuxCon NA 2014 大会上更新了他那个有名的关于 Linux 性能方面的 talk (Linux Performance Tools) 和幻灯片。    和 Br…

    Linux干货 2015-03-03

评论列表(1条)

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

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