shell 脚本编程

1、简单脚本编程1

[root@localhost Desktop]# cat asr.sh 
#!/bin/bash
#This is a shell script
echo $0
echo $#,$*
echo $1,$3,$5
[root@localhost Desktop]#

2、简单脚本编程2

[root@localhost Desktop]# cat shell.sh 
#!/bin/bash
#This is a shell script
if [ ! -e /media/haha ]
then
mkdir -p /media/haha
fi
[root@localhost Desktop]# 

3、简单脚本编程3

[root@localhost Desktop]# cat shell.sh 
#!/bin/bash
#This is a shell script
ping -c 3 -i 0.2 -W 3 $1 &> /dev/null
if [ $? -eq 0 ]
then
echo "Host $1 is On-line"
else
echo "Host $1 is Off-line"
fi
[root@localhost Desktop]#

4、简单的shell脚本编程4

[root@localhost Desktop]# cat shell.sh 
#!/bin/bash
#This is a shell script
read -p "Enter : " GRADE
if [ $GRADE -ge 80 ] && [ $GRADE -le 100 ] ; then
echo "$GRADE is Excellent"
elif [ $GRADE -ge 70 ] && [ $GRADE -le 84 ] ; then
echo "$GRADE si Pass"
else
echo "$GRADE is Fail"
fi
[root@localhost Desktop]# 

5、简单的shell脚本编程5,批量创建用户

[root@localhost Desktop]# cat shell.sh 
#!/bin/bash
#This is a shell script
read -p "Enter : " PASSWD
for UNAME in `cat user.txt`
do
id $UNAME &> /dev/null
if [ $? -eq 0 ]
then
echo "Already Exists"
else
useradd $UNAME &> /dev/null
echo "$PASSWD" | passwd --stdin $UNAME &> /dev/null
if [ $? -eq 0 ]
then
echo "$UNAME create success"
else
echo "UNAME create failure"
fi
fi
done
[root@localhost Desktop]# 

6、简单脚本编程6,pingIP地址

[root@localhost Desktop]# cat shell.sh 
#!/bin/bash
#This is a shell script
for IP in `cat ip.txt`
do
ping -c 3 -i 0.2 -W 3 $IP &> /dev/null
if [ $? -eq 0 ] ; then
echo "Host $IP is On-line"
else
echo "Host $IP is Off-line"
fi
done
[root@localhost Desktop]# 

7、简单的脚本编程

[root@localhost Desktop]# cat shell.sh 
#!/bin/bash
#This is a shell script
PRICE=$(expr $RANOM % 1000)
TIMES=0
while true
do
read -p "Enter : " INT
echo $PRICE
echo #INT
let TIMES++
if [ $INT -eq $PRICE ] ; then
echo "OKOKOK,$TIMES"
exit 0
elif [ $INT -gt  $PRICE ] ; then
echo "HIGH"
else
echo "LOW"
fi
done
[root@localhost Desktop]# 

8、

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值