您的位置:首页 > 其它

unix自动登录Telnet,实现查看多台服务器硬盘及数据表空间使用情况

2008-12-01 20:39 826 查看
以下代码在Sun Solaris 10 系统上运行成功。

#######################Auto Login Telnet###########################
# 在网上找到了一些自动登录的例子,现在用于更实用的例子。 #
# #
# 下面代码主要用于,简单的实现了,在一台服务上运行一个脚本, #
# 就可以查看其它服务器上的硬盘及数据表空间使用情况, #
# 想必还有一些更好的办法,或更安全的方法来实现。 #

###################################################################
#!/bin/bash
ipAddressList="192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.5" #IP地址列表;
rm LookResult.log #删除原来的日志。这里如何能做个判断会再好点。

tmptty=`tty` ;echo 1:$tmptty
tmptty=`basename $tmptty` ;echo 2:$tmptty
tmpname=`whoami` ;echo 3:$tmpname
inp1="telnetUserName" ;echo 4:$inp1 #telnet 登录时用户名
inp2="telnetPassword" ;echo 5:$inp2 #telnet 登录时用户密码
inp3="df -h" ;echo 6:$inp3 #查看磁盘空间使用情况。

inp4="sqlplus userName/password<<!" #登录数据。
inp5=" select t1.tablespace_name ""表空间""," #表空间使用情况
inp51=" t1.r ""可用空间"","
inp52=" t2.a ""总大小"" from "
inp53=" (select tablespace_name ,sum(bytes)/1024/1024 as r from dba_free_space t1 group by tablespace_name)t1,"
inp54=" (select tablespace_name , sum(bytes)/1024/1024 as a from dba_data_files group by tablespace_name) t2 "
inp55=" where t1.tablespace_name=t2.tablespace_name;"
inp6="!"

echo 8:$inp4
echo $inp5 $inp51 $inp52 $inp53 $inp54 $inp55
echo $inp6
inputfile=in
outputfile=out.log
for ipAddress in $ipAddressList #循环IP得址列表
do
echo "******************************$ipAddress Looking Beging **********************" >>LookResult.log
echo "******************************$ipAddress Looking Beging **********************"
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile

exec 7<>$outputfile
exec 8<>$inputfile
telnet $ipAddress <&8 >&7 & #开始Telent 登录

sleep 1; echo $inp1 >> $inputfile #用户名
sleep 1; echo $inp2 >> $inputfile #密码
sleep 1; echo $inp3 >> $inputfile #查看磁盘空间使用情况命令。
sleep 1; echo $inp4 >> $inputfile #登录Sqlplus
sleep 1; echo $inp5$inp51$inp52$inp53$inp54$inp55 >> $inputfile #查看表空间使用情况语句
sleep 1; echo $inp6 >> $inputfile #语句结束退出Sqlplus
sleep 1; echo exit >> $inputfile #退出Telnet登录

ps -ef | grep telnet | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh #结束相关进程
ps -ef | grep tail | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh #结束相关进程

cat $outputfile
more $outputfile >> LookResult.log
echo "******************************$ipAddress Looking over ************************" >> LookResult.log
echo "******************************$ipAddress Looking over ************************"
done
exit #退出.sh
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐