#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