Chinaunix首页 | 论坛 | 博客
  • 博客访问: 335586
  • 博文数量: 105
  • 博客积分: 358
  • 博客等级: 一等列兵
  • 技术积分: 444
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-25 23:00
个人简介

爱生活,爱养生 www.sijiyang.com 欢迎朋友来友联

文章分类

全部博文(105)

文章存档

2017年(2)

2016年(2)

2014年(24)

2013年(34)

2012年(39)

2011年(4)

分类: Python/Ruby

2012-08-14 17:32:21

#!/bin/bash
#luohongjiang
#qq:123769752
#mail:g_linux@qq.com
#version 1.5
init()
{
telnet 192.168.6.167      >192.168.6.167_22.txt
telnet 192.168.6.167 9997 >192.168.6.167_9997.txt
telnet 192.168.6.167 19997 >192.168.6.167_19997.txt
telnet 192.168.6.167 29997 >192.168.6.167_29997.txt
telnet 192.168.6.168      >192.168.6.168_22.txt
telnet 192.168.6.168 9997 >192.168.6.168_9997.txt
telnet 192.168.6.168 19997 >192.168.6.168_19997.txt
telnet 192.168.6.168 29997 >192.168.6.168_29997.txt
telnet 192.168.6.169      >192.168.6.169_22.txt
telnet 192.168.6.169 9997 >192.168.6.169_9997.txt
telnet 192.168.6.169 19997 >192.168.6.169_19997.txt
telnet 192.168.6.169 29997 >192.168.6.169_29997.txt
}

active()
{
file=$(find -name "*.txt" )
for f in $file
{
cat $f|grep  a3gclient|grep -i  "$1" >/dev/null
if (($? < 1));then
echo -e "\E[31m ${f}\E[0m"
cat $f|grep -n a3gclient|grep -i "$1" >/dev/null
num=$(cat $f|grep -n a3gclient|grep -i "$1"|awk -F : '{print $1}')
for inum in $num
{
for ((i=0;i<25;i++))
{   
  inum=$((inum+1))
  if sed -n ${inum}p $f|grep ' ';then
   break;
 else
 
sed -n $((inum-1))p $f|grep -iE 'ServPort|a3gclient'|awk -F : '{print $1}'
 fi
   }
}
fi
}
}

sshactive()
{
file=$(find -name "*.txt" )
for f in $file
{
cat $f|grep  a3gclient|grep -i  "$1" >/dev/null
if (($? < 1));then
echo -e "\E[31m ${f}\E[0m"
cat $f|grep -n a3gclient|grep -i "$1"
num=$(cat $f|grep -n a3gclient|grep -i "$1"|awk -F : '{print $1}'|tail -n1)
for ((i=0;i<25;i++))
{   
 if sed -n $((num+1))p $f|grep ' ';then
           break;
 elif sed -n $((num+$_top))p $f|grep ' ';then
       break;
 else
     num=$((num+$_top))
 sship=$(echo $f|awk -F "[/_]" '{print $2}')
 sshport=$(sed -n ${num}p $f|grep -i 'ServPort="22"'|awk '{print $2}'|awk -F '["]' '{print  $2 }')

  if [[ -n  $sshport ]];then
 break;
 fi
 fi
}

fi
}
echo -e "\n \E[0;32m$sship $sshport\E[0m"
echo "$(date +%D-%T) ssh -P $sshport  root@$sship:/" >>.supssh.log
ssh -p $sshport root@$sship 
}




scpactive()
{
file=$(find -name "*.txt" )
for f in $file
{
cat $f|grep  a3gclient|grep -i  "$1" >/dev/null
if (($? < 1));then
echo -e "\E[31m ${f}\E[0m"
cat $f|grep -n a3gclient|grep -i "$1"
num=$(cat $f|grep -n a3gclient|grep -i "$1"|awk -F : '{print $1}'|tail -n1)
for ((i=0;i<25;i++))
{   
 if sed -n $((num+1))p $f|grep ' ';then
           break;
 elif sed -n $((num+$_top))p $f|grep ' ';then
       break;
 else
     num=$((num+$_top))
 sship=$(echo $f|awk -F "[/_]" '{print $2}')
 sshport=$(sed -n ${num}p $f|grep -i 'ServPort="22"'|awk '{print $2}'|awk -F '["]' '{print  $2 }')

  if [[ -n  $sshport ]];then
 break;
 fi
 fi
}

fi
}
echo -e "\n \E[0;32m$sship $sshport\E[0m"
echo "$(date +%D-%T) scp -P $sshport $2 root@$sship:/" >>.supssh.log
scp -P $sshport $2 root@$sship:/ 
}









orcactive()
{
file=$(find -name "*.txt" )
for f in $file
{
cat $f|grep  a3gclient|grep -i  "$1" >/dev/null
if (($? < 1));then
echo -e "\E[31m ${f}\E[0m"
cat $f|grep -n a3gclient|grep -i "$1"
num=$(cat $f|grep -n a3gclient|grep -i "$1"|awk -F : '{print $1}'|tail -n1)
for ((i=0;i<25;i++))
{   
 if sed -n $((num+$_top))p $f|grep ' ';then
       break;
 else
     num=$((num+$_top))
 sship=$(echo $f|awk -F "[/_]" '{print $2}')
 sshport=$(sed -n ${num}p $f|grep -i 'ServPort="1521"'|awk '{print $2}'|awk -F '["]' '{print  $2 }')
 if [[ -n  $sshport ]];then
 break;
 fi
 fi
}

fi
}
echo -e "\n \E[0;32m$sship:$sshport\E[0m"
sqplpus root/broadtech@$sship:$sshport 
}

rdoactive()
{
file=$(find -name "*.txt" )
for f in $file
{
cat $f|grep  a3gclient|grep -i  "$1" >/dev/null
if (($? < 1));then
echo -e "\E[31m ${f}\E[0m"
cat $f|grep -n a3gclient|grep -i "$1"
num=$(cat $f|grep -n a3gclient|grep -i "$1"|awk -F : '{print $1}'|tail -n1)
for ((i=0;i<25;i++))
{   
 if sed -n $((num+$_top))p $f|grep ' ';then
       break;
 else
   num=$((num+$_top))
 sship=$(echo $f|awk -F "[/_]" '{print $2}')
 sshport=$(sed -n ${num}p $f|grep -i 'ServPort="3389"'|awk '{print $2}'|awk -F '["]' '{print  $2 }')
 if [[ -n  $sshport ]];then
 break;
 fi
 fi
}

fi
}
echo -e "\n \E[0;32m$sship:$sshport\E[0m"
rdesktop $sship:$sshport
}


ipactive()
{
file=$(find -name "*.txt" )
for f in $file
{
cat $f|grep "$1" >/dev/null
if (($? < 1));then
echo $f
echo "find $1"
sship=$(echo $f|awk -F "[/_]" '{print $2}')
sshport=$(cat $f|grep "$1"|awk '{print $2}'|awk -F '["]' '{print  $2 }')
break
fi
}
echo -e "\n \E[0;32m$sship:$sshport\E[0m"
ssh -p $sshport root@$sship 
}

    >/root/.ssh/known_hosts
_top=${3-1}
clear
if (($#<1));then
init
fi
case $1 in 
I)
init;;
ssh)
if [[ -n $2 ]];then
sshactive "$2"
fi
;;
ora)
    if [[ -n $2 ]];then
orcactive "$2"
fi
;;
rdo)
if [[ -n $2 ]];then
rdoactive "$2"
fi
;;
ip)
if [[ -n $2 ]];then
ipactive  "$2"
fi
;;
scp)
scpactive "$2" "$4"
;;
help)
echo "[I]   [NUM] Initialization list file" 
echo "[ssh] [NUM] Automatic connection port 22"
echo "[ora] [NUM] Automatic connection port 1521"
echo "[rdo] [NUM] Automatic connection port 3389"
echo "[ip]        Automatic connection port 22"
echo "[scp]       Automatic copy file to Area"
echo "[help] help message"
;;
*)
active "$1";;
esac


方便查到各地区映射主机
运行效果图:
[root@localhost update]#   ./supssh "guang xi"
 ./192.168.6.168_9997.txt
   
       
       
       
       
       
       
       
       
       
   
阅读(3502) | 评论(0) | 转发(0) |
0

上一篇:python 双色球

下一篇:简单之说sed

给主人留下些什么吧!~~