SHELL训练营--day20_shell练习41-45

#问候脚本
#!/bin/bash
d=`date +%H`
if [ $d -ge 0 -a $d -lt 7 ]
then
    tag=1
elif [ $d -ge 7 -a $d -lt 12 ]
then
    tag=2
elif [ $d -ge 12 -a $d -lt 18 ]
then
    tag=3
else
    tag=4
fi

case $tag in 
    1)
        echo "早上好"
        ;;
    2)
        echo "上午好"
        ;;
    3)
        echo "下午好"
        ;;
    4)
        echo "晚上好"
        ;;
esac

#菜单脚本
#!/bin/bash
echo -e "1) w\n2) ls\n3) pwd\n4) quit"
while
do
    read -p "Please input your choice(1-4):" c
    case $c in
        1)
            w
            ;;
        2)
            ls
            ;;
        3)
            pwd
            ;;
        4)
            exit
            ;;
        *)
            echo "Please input 1-4."
            ;;
    esac
done

#检查用户登录
#!/bin/bash
while :
do
    if w|sed '1'd|awk '{print $1}'|grep -qw "$1"
    then
        echo "$1 用户已经登录。"
    fi
    sleep 300
done

#检查系统是否被***
#!/bin/bash
pp=$$
ps -elf|sed '1'd > /tmp/pid.txt
for pid in `awk -v ppn=$pp '$5!=ppn {print $4}' /tmp/pid.txt`
do
    if ! [ -d /proc/$pid ]
    then
        echo "系统中没有pid为$pid的目录。请检查。"
    fi
done

#三行合一行
#!/bin/bash
n=1
cat $1|while read line
do
    n1=$[$n%3]
    if [ $n1 -eq 0 ]
    then
        echo "$line"
    else
        echo -n "$line "
    fi
    n=$[$n+1]
done

猜你喜欢

转载自blog.51cto.com/sincethen/2342704