08 shell script --001 practice

Whether a judge / etc / inittab file larger than 100 rows, if so, then display "/ etc / inittab is a big file." No person show "/ etc / inittab IS A Small File."
    #! / Bin / bash
    $ WC = `-l Line / etc / inittab | Cut -d '' -f1` --------------->. 17
    IF [$ Line -gt 100]; the then
        echo" / etc / iS a Big inittab File. "
    the else
        echo" / etc / inittab iS a Small File. "
    Fi
2, a given user, the user is to determine what the user, if the user is an administrator, the display" the user management members ", otherwise display" the user is a normal user "
    #! / bin / bash
     A =` the above mentioned id -u root` ------------> 0 (0 administrators id) (500- 65535) to the general user uses the
    iF [$ A -eq 0]; the then
        echo "of the user is an administrator"
    is shorthand for beginning
        echo "the user is a general user"
    Fi
. 3, determines whether a file exists
    ! # / bin / the bash
    $ a = `ls 2019-08-10.http.log`
    IF [$ A -eq 0]; the then
        echo "file exists"
    the else
        echo "file does not exist"
    Fi
. 4, determines whether a user whether the default shell bash program, if there is, it shows that the current system has a plurality of category of users, otherwise showed no such users; [and show those users is bash]
    # / bin / bash!
    $ bash = `grep 'bash $' / etc / passwd | WC -l` ------ ---------->. 1
    IF [-eq the bash $ 0]; the then
        echo "no such user"
    the else
        echo "$ the bash"
    Fi
. 5, to write a script, a given file, such as : / etc / inittab a, to determine whether there is a blank line in the file? b, if so, its line number blank lines displayed, otherwise there is no blank lines
    # / bin / bash!
    $ A = `CAT / etc / inittab | Cut -d '#' -f2 | grep '^ $' | ----------------------- -l` WC>. 7
    IF [$ A -eq 0]; the then
        echo "no empty row"



6, write a script, given a user to determine whether the UID and GID, as if, like, it shows that the user is "good guy", otherwise it is "Bad Guy"
    #! / Bin / bash
    # [root @ ~ localhost] WX the useradd #
    # [the root @ localhost ~] -u WX # ID
    # 1000
    $ A `ID = -u wx`
    # [the root @ localhost ~] # -g WX ID
    # 1000
    $` B ID = -g wx` ------------------> 1000 and 1000
    IF [-eq $ A $ B]; the then
        echo. "Good Guy"
    the else
        echo. "Bad Guy"
    Fi
. 7 , write a script, given a user to get their password warning period; then determine whether the user was last modified from time password if today is already less than the warning period;
    #! / bin / bash

    
8, to determine whether the total entry command history command history is more than 1000, if greater than, "some command will gone" is displayed, otherwise the OK
    ! # / bin / bash
    $ `History A = | WC -l`
    if [$ a -gt 1000]; then
        echo "some the Command by Will Gone."
    the else
        echo "the OK"
    IF
9, given a file, if an ordinary file, on the show, if it is a directory file, also show up, otherwise it displays "does not recognize"
    #! / bin / the bash
    $ = `-` A
    $ =` d` B
    $ `C = LL the yum.conf | Cut -d '' -f1 | awk -F '' '. 1} {Print $'`
    IF [$ C $ -eq a]; the then
        echo "normal file"
    elif [-eq $ B $ C]; the then
        echo "directory file"
    the else
        echo "unrecognized"
    Fi    
10, to write a script that accepts a parameter (file path), this parameter is determined If it is an existing file on the show "ok", otherwise display "No SUCH file"
    # / bin / bash!
    $ a = `LL / etc / inittab | WC -l` ----------- ------>. 1
    IF [$ A -ge. 1]; the then
        echo "OK"
    else
        echo "NO such file"
    Fi
. 11, write a script, the script to pass two parameters, displaying both the two and the sum of the product of
    # / bin / the bash!
    $ A = 2
    $. 3 B =
    IF [$ SUM -eq '+']; the then
        echo "and is the sum of both: $ [$ $ A + B]"
    the else
        echo "is the product of both: $ [$ B $ A *]"
    Fi

Guess you like

Origin www.cnblogs.com/wx00/p/11313076.html