在几个服务器之间移植检查脚本时我遇到了一些问题。
剧本。
#!/bin/bash
hostname=$1
port=$2
retstatus=0
retStr=
st=`date "+%s.%N"`
if [ $# -ne 2 ]; then
echo "Error, invalid parameters passed"
exit 3
fi
tmp_cook=`mktemp`
wget --no-check-certificate --keep-session-cookies --save-cookies $tmp_cook https://$hostname:$port/LoginForm.jsp -O /dev/null -o /dev/null
ta=`date "+%s.%N"`
wget --no-check-certificate --load-cookies $tmp_cook --keep-session-cookies --save-cookies $tmp_cook --post-data="j_username=scott&j_password=tiger" https://$hostname:$port/j_security_check -O /dev/null -o /dev/null
tb=`date "+%s.%N"`
ok2=`wget --no-check-certificate --load-cookies $tmp_cook --keep-session-cookies --save-cookies $tmp_cook https://$hostname:$port/MainMenu.jsp -o /dev/null -O - | grep 'Customer Care' | wc -l`
if [ $ok2 -gt 0 ]; then
retStr="SITE OK."
else
retStatus=2
retStr="SITE NOT OK."
fi
#echo 'Got session:'
rm -f $tmp_cook
et=`date "+%s.%N"`
da=`echo "$ta - $st" | bc`
db=`echo "$tb - $st" | bc`
dz=`echo "$et - $st" | bc`
printf "%s|SITE LOGIN:%02.2f,%02.2f,%02.2f\n" "$retStr" $da $db $dz
exit $retStatus
当我在调试模式下运行它时:
[nagios@mr-slave libexec]$ bash -x check_Login.sh node001.company.com 16004
+ hostname=node001.company.com
+ port=16004
+ retstatus=0
+ retStr=
++ date +%s.%N
+ st=1427736385.648488303
+ '[' 2 -ne 2 ']'
++ mktemp
+ tmp_cook=/tmp/tmp.ye9MyQfgJp
+ wget --no-check-certificate --keep-session-cookies --save-cookies /tmp/tmp.ye9MyQfgJp https://node001.company.com:16004/LoginForm.jsp -O /dev/null -o /dev/null
++ date +%s.%N
+ ta=1427736385.676642983
+ wget --no-check-certificate --load-cookies /tmp/tmp.ye9MyQfgJp --keep-session-cookies --save-cookies /tmp/tmp.ye9MyQfgJp '--post-data=j_username=scott&j_password=tiger' https://node001.company.com:16004/j_security_check -O /dev/null -o /dev/null
++ date +%s.%N
+ tb=1427736385.702942948
++ wget --no-check-certificate --load-cookies /tmp/tmp.ye9MyQfgJp --keep-session-cookies --save-cookies /tmp/tmp.ye9MyQfgJp https://node001.company.com:16004/MainMenu.jsp -o /dev/null -O -
++ grep 'menu 1'
++ wc -l
+ ok2=0
+ '[' 0 -gt 0 ']'
+ retStatus=2
+ retStr='SITE NOT OK.'
++ date +%s.%N
+ et=1427736385.729800960
++ echo '1427736385.676642983 - 1427736385.648488303'
++ bc
+ da=.028154680
++ bc
++ echo '1427736385.702942948 - 1427736385.648488303'
+ db=.054454645
++ echo '1427736385.729800960 - 1427736385.648488303'
++ bc
+ dz=.081312657
+ printf '%s|SITE LOGIN:%02.2f,%02.2f,%02.2f\n' 'SITE NOT OK.' .028154680 .054454645 .081312657
SITE NOT OK.|SITE LOGIN:0.03,0.05,0.08
+ exit 2
因此我检查了 tmp 文件中的 cookie 内容。
[nagios@dub-company-slave libexec]$ cat /tmp/tmp.ye9MyQfgJp
# HTTP cookie file.
# Generated by Wget on 2015-03-30 18:26:25.
# Edit at your own risk.
这里没有信息,我期望更多类似以下内容:
nagios@dub-company-slave [libexec] -->> cat /tmp/tmp.wdOvUJ9695
# HTTP cookie file.
# Generated by Wget on 2015-03-30 18:19:11.
# Edit at your own risk.
node001.company.com:16004 FALSE / FALSE 0 JSESSIONID RMw8VZFPvnnDFcmLzThjgp2mMDJ1GLgt4w8XJpRn1BWn2QNQrQjP!250469950
node001.company.com:16004 FALSE / TRUE 0 _wl_authcookie_ 6QxOZhTJCc9JyyL2lrZZ
该脚本在不同的从属服务器上运行,我能看到的唯一明显区别是两个略有不同的 wget 版本。
GNU Wget 1.11.4 Red Hat 修改版,可以运行 / GNU Wget 1.12 建立在 linux-gnu 上,但是不能运行。
答案1
在新版本的 Wget 中,其默认加密类型是 SSL3,而不是网站使用的 TLS1.0。
--secure-protocol=TLSv1 使一切正常运行:)