一个ping的脚本,可以修改一下,用来测试某个网段中有那些ip可以ping通。哪些ip未使用。
#!/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
#检测主机是否开机,如果开机,显示主机名