linux远程启动&停止weblogic、分割日志、端口检测 脚本
startWLS.sh
--------------------------------------------------------------------
#!/usr/bin/expect -f
set count 3
set ip(1) "134.16.22.50"
set username(1) "weblogic"
set password(1) "weblogic"
set domainurl(1) "/bea/user_projects/domains/sxptccs_domain/bin"
set cmd(1) "nohup ./startWebLogic.sh > jq_Admin.log &"
set ip(2) "134.16.22.50"
set username(2) "weblogic"
set password(2) "weblogic"
set domainurl(2) "/bea/user_projects/domains/sxptccs_domain/bin"
set cmd(2) "nohup ./startManagedWebLogic.sh ProxyServer > jq_ProxyServer.log &"
set ip(3) "134.16.22.50"
set username(3) "weblogic"
set password(3) "weblogic"
set domainurl(3) "/bea/user_projects/domains/sxptccs_domain/bin"
set cmd(3) "nohup ./startManagedWebLogic.sh Server_1 > jq_Server_1.log &"
for {set i 1} {$i <= $count} {incr i} {
puts $i
puts $ip($i)
puts $username($i)
puts $password($i)
puts "cd $domainurl($i)"
puts $cmd($i)
spawn telnet $ip($i)
expect "login:"
send $username($i)
send "\r"
expect "Password:"
send $password($i)
send "\r"
expect "]:"
send "cd $domainurl($i)"
send "\r"
send $cmd($i)
send "\r"
sleep 3
expect eof
}
exit
--------------------------------------------------------------------
stopWLS.sh
#!/usr/bin/expect -f
set count 3
set ip(1) "134.16.22.50"
set username(1) "weblogic"
set password(1) "weblogic"
set domainurl(1) "/bea/user_projects/domains/sxptccs_domain/bin"
set cmd(1) "nohup ./stopWebLogic.sh > jq_Admin_stop.log &"
set ip(2) "134.16.22.50"
set username(2) "weblogic"
set password(2) "weblogic"
set domainurl(2) "/bea/user_projects/domains/sxptccs_domain/bin"
set cmd(2) "nohup ./stopManagedWebLogic.sh ProxyServer > jq_ProxyServer_stop.log &"
set ip(3) "134.16.22.50"
set username(3) "weblogic"
set password(3) "weblogic"
set domainurl(3) "/bea/user_projects/domains/sxptccs_domain/bin"
set cmd(3) "nohup ./stopManagedWebLogic.sh Server_1 > jq_Server_1_stop.log &"
for {set i $count} {$i >= 1} {incr i -1} {
puts $i
puts $ip($i)
puts $username($i)
puts $password($i)
puts "cd $domainurl($i)"
puts $cmd($i)
spawn telnet $ip($i)
expect "login:"
send $username($i)
send "\r"
expect "Password:"
send $password($i)
send "\r"
expect "]:"
send "cd $domainurl($i)"
send "\r"
send $cmd($i)
send "\r"
sleep 3
expect eof
}
exit
--------------------------------------------------------------------
fglog.sh
#!/bin/sh
echo "shell /sxptccs/log/fglog.sh"
echo "--Begin time: "`date`" --"
logfile="/bea/user_projects/domains/base_gncs/bin/nohup.out"
echo "logfile: "${logfile}
fgurl="/sxptccs/log/"
echo "fgurl: "${fgurl}
H=`date "+%H"`
echo "now DATE-H: "${H}
cp ${logfile} ${fgurl}"gnlog_"`date "+%Y%m%d%H%M"`".log"
cp /dev/null ${logfile}
echo " fglog "`date`
while [ 1=1 ]
do
if [ `date "+%H"` -eq ${H} ];
then
sleep 1
else
cp ${logfile} ${fgurl}"gnlog_"`date "+%Y%m%d%H%M"`".log"
cp /dev/null ${logfile}
H=`date "+%H"`
echo " fglog "`date`
sleep 3600
fi
done
echo "--End time: "`date`" --"
--------------------------------------------------------------------
checkPort.sh
#!/usr/bin/expect -f
set timeout 1
set count 5
set result ""
# netstat -anp|grep 7080
# netstat -anp|grep 7080|wc -l
set ip(1) "134.16.22.50"
set username(1) "weblogic"
set password(1) "weblogic"
set port(1) 7080
set ip(2) "134.16.22.50"
set username(2) "weblogic"
set password(2) "weblogic"
set port(2) 8080
set ip(3) "134.16.22.47"
set username(3) "weblogic"
set password(3) "weblogic"
set port(3) 7070
set ip(4) "134.16.22.47"
set username(4) "weblogic"
set password(4) "weblogic"
set port(4) 4070
set ip(5) "134.16.22.47"
set username(5) "weblogic"
set password(5) "weblogic"
set port(5) 5070
for {set i 1} {$i <= $count} {incr i} {
spawn telnet $ip($i)
expect "login:"
send $username($i)
send "\r"
expect "Password:"
send $password($i)
send "\r"
expect "]$"
send "netstat -anp|grep $port($i)\r"
set accum {}
set tj 0
expect {
-re "tcp*" {
#set accum "$expect_out(0,string)"
set tj 1
exp_continue
}
}
#puts "$accum"
if {$tj == 1} {
set result "${result}RESULT($tj): IP-$ip($i) prot-$port($i) is open\n"
#lappend result "RESULT($tj): IP-$ip($i) prot-$port($i) is open\r"
} else {
set result "${result}RESULT($tj): IP-$ip($i) prot-$port($i) is close\n"
#lappend result "RESULT($tj): IP-$ip($i) prot-$port($i) is close\r"
}
expect eof
}
puts "\n---------CHECK PORT --------\n"
puts "$result"
puts "--------- END --------\n"
exit
--------------------------------------------------------------------