12.11

####十秒倒计时####
#!/bin/bash
for((SEC=10;SEC>0;SEC--))
do
echo -ne "After ${SEC}s is end"
echo -ne "\r    \r"
sleep 1
done

####一分钟十秒钟倒计时####
#!/bin/bash
MIN=1
for((SEC=10;SEC>=0;SEC--))
do
echo -ne "After ${MIN}:${SEC}s is end"
sleep 1
echo -ne "\r    \r"
    while ["$SEC" -le "0" -a "$MIN" -gt "0"]
    do
    echo -ne "After ${MIN}:${SEC}s is end"
    echo -ne "\r    \r"
    ((MIN--))
    SEC=60
    done
done
####显示那个主机能ping通####
#!/bin/bash
for NUM in {1..10}
do
ping -c1 -w1 172.25.254.$NUM &> /dev/null && echo 172.25.254.$NUM is up || echo 172.25.254.$NUM is down
done

mysql -uroot -predhat -e "show databases;" -NE | grep -E "^\*|schema" -v

##查看所输入的文件是否存在,存在输出文件类型##
#!/bin/bash
if
[ -e "$1" ]
then
[ -f "$1" -a ! -L "$1" ] && echo $1 is a file
[ -b "$1" ] && echo $1 is block
[ -c "$1" ] && echo $1 is a c block
else
[ -n "$1" ] && echo $1 is not exist || echo "please input give me a file"
fi
##创建用户##
if
[ -n "$1" -a -n "$2" ]
then
    if
    [ -e "$1" -a -e "$2" ]
    then
    MAXUSER=`wc -l $1 | cut -d " " -f 1`
    MAXPASS=`wc -l $2 | cut -d " " -f 1`
        if
        [ "$MAXUSER" -eq "$MAXPASS" ]
        then
        for NUM in $( seq 1 $MAXUSER )
        do
        USERNAME=`sed -n ${NUM}p $1`
        PASSWORD=`sed -n ${NUM}p $2`
        CKUSER=`getent passwd $USERNAME`
        [ -z "$CKUSER" ] &&(
        useradd $USERNAME
        echo $PASSWORD |passwd --stdin $USERNAME
        )||echo "$USERNAME exist !!"
        done
        else
        echo $1 and $2 have different lines
        fi
else
echo "ERROR: Please input userfile and password file after command !!"
fi
##case用法##
#!/bin/bash
case "$1" in
    apple)
    echo "banana";;
    banana)
    echo "apple";;
    *)
    echo "fruit";;
esac

##expect##自动应答shell中的问题
#!/usr/bin/expect
spawn /mnt/ask.sh
    expect "name:"
    send "lee\r"
    expect "old"
    send "18\r"
    expect "class"
    send "linux\r"
    expect "happy"
    send "happy\r"
expect eof

##用户可以自己输入答案##
set name [ lindex $argv 0 ]
set age [ lindex $argv 1 ]
set class [ lindex $argv 2 ]
set feel [ lidex $argv 3 ]

spawn /mnt/ask.sh
    expect "name:"
    send "$name\r"
    expect "old"
    send "$age\r"
    expect "class"
    send "$class\r"
    expect "happy"
    send "$feel\r"
expect eof

##连接某台主机##
#!/usr/bin/expect
set IP [lindex $argv 0]
set PASS [lindex $argv 1]
spwan ssh root@$IP
expect {
    "yes/no"
    {send "yes\r";exp_continue}
    "password:"
    {send "$PASS\r"}
}
interact

##那台主机开启并返回它的hostname##
#!/bin/bash
for NUM in {1..10}
do
ping -c1 -w1 172.25.254.$NUM &> /dev/null &&(
    /mnt/ssh.exp 172.25.254.$NUM redhat hostname |grep -E "^The|ECDSA|connecting|Warning|password|spawn" -v|sed "s/Permission\ denied\,\ please\ try\ again\./172.25.254.$NUM password is error/g")
done

猜你喜欢

转载自blog.csdn.net/qq_36369292/article/details/53692927
今日推荐