找包含 某字符的 文件 的文件名
#!/bin/bash
for FILE in `find . -name "*.xml"`do
a=`grep -c "HWSOSS_SSO" $FILE`
b=`grep -c "8443" $FILE`
if [ $a -ge 1 ];then
echo "aaaaaa"
echo $FILE
fi
done
替换所有某类文件内容
for i in `find . -name soap.ini`;do sed -i 's/192.168.204.90:28080/192.168.204.90:18081/g' $i ;done
判断用户名
if [ $(id | awk -F "[(|)]" '{print $2}') != ${USER} ];then
errorMessage "当前用户不正确 $(whoami)"
fi
if [ `id -u` -ne 0 ];then
echo "Please use root to execute this script"
exit 1
fi
expect 输入交互密码执行命令
#!/bin/bash
PASSWORD="Pinco@007"
#_EXIT="exit"
while read IP
do
echo "start to connet ${IP}"
cat > d.exp << EOF
#!/usr/bin/expect
#set ip 192.168.204.82 #expect 中设置变量
#set password huawei
set timeout 60
spawn scp -r /root/rpm root@${IP}:/root/
expect {
"*yes/no" { send "yes\r"; exp_continue} #继续执行
"*Password:" { send "${PASSWORD}\r" }
}
expect eof
spawn ssh root@${IP}
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*Password:" { send "${PASSWORD}\r" }
}
expect "#*"
send "rpm -Uvh /root/rpm/*.rpm\r"
send "exit\r"
expect eof
EOF
chmod 755 d.exp
/usr/bin/expect d.exp
done < "IP.txt"
gibc 升级脚本
#!/bin/bash
PASSWORD="Pinco@007"
#_EXIT="exit"
while read IP
do
echo "start to connet ${IP}"
cat > d.exp << EOF
#!/usr/bin/expect
#set ip 192.168.204.82
#set password huawei
set timeout 60
spawn scp -r /root/rpm root@${IP}:/root/
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*Password:" { send "${PASSWORD}\r" }
}
expect eof
spawn ssh root@${IP}
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*Password:" { send "${PASSWORD}\r" }
}
expect "#*"
send "rpm -Uvh /root/rpm/*.rpm\r"
send "exit\r"
expect eof
EOF
chmod 755 d.exp
/usr/bin/expect d.exp
done < "IP"