常用的一些shell脚本(一)

1.模拟linnux登录shell


#/bin/bash
echo -n "login:"
read name
echo -n "password:"
read passwd
if [ $name = "cht" -a $passwd = "abc" ];then
echo "the host and password is right!"
else echo "input is error!"
fi

2.比较两个数大小

#/bin/bash
echo "please enter two number"
read a
read b
if test $a -eq $b
then echo "NO.1 = NO.2"
elif test $a -gt $b
then echo "NO.1 > NO.2"
else echo "NO.1 < NO.2"
fi

3.查找/root/目录下是否存在该文件

#/bin/bash
echo "enter a file name:"
read a
if test  -e /root/$a
then echo "the file is exist!"
else echo "the file is not exist!"
fi

4.for循环的使用

#/bin/bash
clear
for num in 1 2 3 4 5 6 7 8 9 10
do
    echo "$num"
done

5.

#/bin/bash
echo "Please enter a user:"
read a
b=$(whoami)
if test $a = $b
then echo "the user is running."
else echo "the user is not running."
fi

6.删除当前目录下大小为0的文件

#/bin/bash
for filename in `ls`
do
    if test -d $filename
    then b=0
    else   
       a=$(ls -l $filename | awk '{ print $5 }')
            if test $a -eq 0
             then rm $filename
             fi
        fi     
done

7.如果/export/um_lpp_source下有文件,那么将其文件系统大小改为3G

#/bin/bash
while line=`ls /export/um_lpp_source`
do
        if test $line=""
        then  echo "NULL"
             sleep 1
    else echo $line
                chfs -a size=3G /export/um_lpp_source
                 exit 0
        fi
done

 
8.测试IP地址

#/bin/bash
for i in  1 2 3 4 5 6 7 8 9
do
    echo "the number of $i computer is "
    ping -c 1 192.168.0.$i
done
                                                     ------转自http://www.jb51.net/article/54488.htm
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值