Shell脚本

一个ping的脚本,可以修改一下,用来测试某个网段中有那些ip可以ping通。哪些ip未使用。

ping.sh

#!/bin/bash
for n in {1…254}
do
ping -c1 -w1 192.168.2.KaTeX parse error: Expected 'EOF', got '&' at position 3: n &̲> /dev/null && …n is up || echo 192.168.2.$n is down
done
##这个脚本用来测试192.168.2.0网段中有哪些ip地址ping不通,不通的通常就可以使用。

##参考。
[ -z $a ] STRING zore
[ -n $a ] STRING nozore
[ -e $a ] file exist
[ file –ef file1 ] 比较两文件inode是否相等(是否互为硬链接)

[ file –ot file1 ] 比较file是否比file1 新

[ file –nt file1 ] 比较file是否比file1 老

##下面的Shell脚本可以与用户交流
先安装 yum install -y expect

##下面是脚本

#!/bin/bash
read -p “what is your name:” NAME
read -p “how old are you :” AGE

echo $NAME is $AGE old!

##监控脚本/mnt/Shell/ask.sh的提示信息,并给出值。
#!/usr/bin/expect
set name [lindex $argv 0]
set age [lindex $argv 1]

spawn /mnt/Shell/ask.sh
expect “name”
send “KaTeX parse error: Can't use function '\r' in math mode at position 5: name\̲r̲" expect "old"…age\r”
expect eof

#使用scp命令将文件远程拷贝到另外的主机上,通过“yes/no”来判断是不是第一次链接,如果是就自动输入“yes”,然后通过“password”来判断是否需要输入密码,之后自动输入密码。
#!/usr/bin/expect
set IP [ lindex $argv 0 ]
set PASS [ lindex a r g v 1 ] s p a w n s c p / m n t / S h e l l / a s k . s h r o o t @ argv 1 ] spawn scp /mnt/Shell/ask.sh root@ argv1]spawnscp/mnt/Shell/ask.shroot@IP:/mnt
expect {
“yes/no”
{send “yes\r”;exp_continue}
“password”
{send “$PASS\r”}
}
interact

该脚本需要安装expect,yum install -y expect

#检测主机是否开机,如果开机,显示主机名

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值