zoukankan      html  css  js  c++  java
  • shell-homeworkone

    1、判断/etc/inittab文件是否大于100行,如果大于,则显示”/etc/inittab is a big file.”否则显示”/etc/inittab is a small file.”

    #!/bin/sh
    if [ `wc -l /etc/inittab |cut -c 1-3` -gt 100 ];then
    echo "/etc/inittab is a big file"
    else
    echo "/etc/inittab is a small file"
    fi

    2、给定一个用户,来判断这个用户是什么用户,如果是管理员用户,则显示“该用户为管理员”,否则显示“该用户为普通用户”

    #!/bin/sh
    type=`whoami $1`
    if [ $type==root ];then
    echo "You are root"
    else
    echo "You are common user"
    fi

    3、判断某个文件是否存在

    #!/bin/sh
    read -p "Enter a file name:" file
    if [ -e "$file" ];then
    echo "this file exist"
    else
    echo "this file non-existent"
    fi

    -----------------------------

    if[-e $1 ];then
    echo "存在"
    else
    echo“不存在”
    if

    4、判断当前系统上是否有用户的默认shell程序是否为bash程序,如果有,就显示有多个这类用户,否则就显示没有这类用户;【并且显示出那些用户是bash】

         #!/bin/bash

        declare -i sum=`grep "/bin/bash$" /etc/passwd |wc -l `

        if grep "/bin/bash$" &> /dev/null;then

            echo "存在$sum个用户,shell程序为/bin/bash"

            exit 0

        else

            echo "没有这类用户"

            exit 1

        fi

    5、写出一个脚本程序,给定一个文件,比如:/etc/inittab a、判断这个文件中是否有空白行? b、如果有,则显示其空白行的行号,否则显示没有空白行

    #!/bin/sh
    read -p "Enter a file name:" file
    spaceline=`sed -n '/^$/=' $file`
    if [[ -z $spaceline ]];then
    echo "this file not have space line."
    else
    echo "this file have space line.The number is $spaceline"
    fi

    6、写一个脚本程序,给定一个用户,判断其UID与GID是否一样,如果一样,就显示该用户为“good guy”,否则显示为“bad guy”

    #!/bin/sh
    read -p "echo a username:" user
    USERID=`id -u $user`
    GROUPID=`id -g $user`
    if [ $USERID -eq $GROUPID ];then
    echo "Good Guy"
    else
    echo "Bad Guy"
    fi

        1、for遍历/etc/passwd

        

        2、判断每一行的UID和GID
    7、写一个脚本程序,给定一个用户,获取其密码警告期限;然后判断用户最近一次修改密码的时间距离今天是否已经小于警告期限;


    8、判断命令历史中历史命令的总条目是否大于1000,如果大于,则显示“some command will gone”,否则显示OK

    #!/bin/bash

    #

    HISTLINE=`history | wc -l`

    if [ $HISTLINE -ge 1000 ]; then

    echo "Some command will gone."

    else echo "ok" fi

    9、给定一个文件,如果是普通文件,就显示出来,如果是目录文件,也显示出来,否则就显示“无法识别”
    10、写一个脚本,能接受一个参数(文件路径),判断这个参数如果是一个存在的文件就显示“ok”,否则显示“No such file”

    #!/bin/sh
    read -p "Enter a file name:" file
    if [ -e "$file" ];then
    echo "this file exist"
    else
    echo "this file non-existent"
    fi
    11、写一个脚本,给脚本传递两个参数,显示两则之和和两者之积

    #!/bin/bash
    #
    if [ $# -lt 2 ]; then
    echo "Usage: cacl.sh ARG1 ARG2"
    exit 8
    fi
    echo "The sum is:$[$1+$2]"
    echo "The prod is:$[$1*$2]"

  • 相关阅读:
    Hello,Power BI
    ubuntu 14.04中Elasticsearch 2.3 中 Nginx 权限认证
    Elasticsearch中doc_value的认识
    Elasticsearch 5.0 _source field的简单认识
    在kubernetes集群上用helm安装Datadog(Monitoring)
    在Windows上安装Elasticsearch 5.0
    Matlab 高斯_拉普拉斯滤波器处理医学图像
    Logstash时区、时间转换,message重组
    Elasticsearch 2.3 (ELK)Geo_point绘图、日志Date时间获取实例
    ubuntu 安装Elasticsearch5.0(Debian包)
  • 原文地址:https://www.cnblogs.com/DevonL/p/11341215.html
Copyright © 2011-2022 走看看