shell 脚本 自动化

最简单打开终端登录:

gnome-terminal --tab -e "bash -c \"sshpass -p "apeadmin" ssh -tt ape@192.168.1.136 'cd / && /bin/bash' \""


   sshpass为自动登录   -tt 为接受自动登录

scp 拷贝:

g_count_135="ape@ip"
g_passwd
="pwd"

sshpass
-p "apeadmin" scp -r ape@192.168.1.135:/var/www/html/telhtm/js/tel.js ~/

shell 自动化脚本1(打开终端):

 

g_shdaily_path="/ape/ImRoBot5/Dev/cvs/ImRoBot5/shdaily/cgi"
g_baspath_135
="/ape/ImRoBot5/Dev/cvs/ImRoBot5/bas/cgi"
g_baspath_136
="/ape/Dev/cvs/ImRoBot5/bas/cgi"
g_dianxin
="/var/www/html/telhtm"
g_bas
="/var/www/cgi-bin"
g_wangkangluo1
="/ape/ImRoBot5/wangkangluo1"
g_passwd
="apeadmin"
g_cout_136
="ape@ip"
g_cout_135
="ape@ip"
g_limit
=4 #打开终端屏幕数量
g_tail=wssh1.tail #调试跟踪输出文件
#
echo $l_statu >>$g_tail

fun_main()
{
case $# in
0)
fun_deal_0
;;
1)
fun_deal_1 $
1
;;
esac
}

fun_deal_0()
{
fun_cd
$g_baspath_136 $g_cout_136 3
}


fun_deal_1( )
{
case $1 in
"135")
fun_cd
$g_baspath_135 $g_cout_135 3
;;
"sh")
fun_cd
$g_shdaily_path $g_cout_135 3
;;
"wget")
fun_cd
$g_wangkangluo1 $g_cout_135 1
;;
"dx")
fun_cd
$g_dianxin $g_cout_135 3
;;
"bas")
fun_cd
$g_bas $g_cout_136 1
esac
}

fun_cd()
{
if [ $3 = 3 ]
then
# echo "bug" >>$g_tail
gnome-terminal --tab -e "bash -c \"sshpass -p $g_passwd ssh -tt $2 'cd $1 && /bin/bash' \"" --tab -e "bash -c \"sshpass -p $g_passwd ssh -tt $2 'cd $1 && /bin/bash' \"" --tab -e "bash -c \"sshpass -p $g_passwd ssh -tt $2 'cd $1 && /bin/bash' \""
else
gnome
-terminal --tab -e "bash -c \"sshpass -p $g_passwd ssh -tt $2 'cd $1 && /bin/bash' \""
fi
}

fun_main $
1

shell 自动化脚本2(打开终端):

 

shdailypath="/ape/ImRoBot5/Dev/cvs/ImRoBot5/shdaily/cgi"
baspath
="/ape/ImRoBot5/Dev/cvs/ImRoBot5/bas/cgi"
wangkangluo1
="~/wangkangluo1"
passwd
="pwd"
cout
="ape@ip"

if [ -d $1 ]
then
gnome
-terminal -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd ~/wangkangluo1 && /bin/bash' \""
exit 0
fi

if [[ $1 != *[^0-9]* ]]&&[[ $1 != 0* ]] #判断是整数还是字符串
then
LIMIT
=8 #上限
a=0
b
=$1
b
=$(($b-1))
if [ $1 -le "$LIMIT" ]
then
while [ $a -le $b ]
do
a
=$(($a+1))
gnome
-terminal -e "sshpass -p $passwd ssh $cout"
done
fi
exit 0
else
if [ $1 = "sh" ] #打开shdaily工作空间
then
mode
=$2
gnome
-terminal --window -e "sshpass -p $passwd ssh $cout -t vim $mode $shdailypath/shdailyFCGI.c " --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $shdailypath && /bin/bash' \""
gnome
-terminal --window -e "sshpass -p $passwd ssh $cout -t vim $mode $shdailypath/eggDAO.c " --tab -e "sshpass -p $passwd ssh $cout -t vim $mode $shdailypath/eggDAO.h " --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $shdailypath && /bin/bash' \""
gnome
-terminal --window -e "sshpass -p $passwd ssh $cout -t vim $mode $shdailypath/basSearchOp.c " --tab -e "sshpass -p $passwd ssh $cout -t vim $mode $shdailypath/basSearchOp.h " --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $shdailypath && /bin/bash' \"" #--tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd /var/www/cgi-bin' \""
#" --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $shdailypath && /bin/bash' \""
gnome-terminal --window -e "sshpass -p $passwd ssh $cout -t gdb $shdailypath/shdaily.fcgi " --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $shdailypath/../ && /bin/bash' \""
# gnome-terminal -e "sshpass -p $passwd ssh $cout"

fi

if [ $1 = "bas" ] #打开bas工作空间
then
mode
=$2
gnome
-terminal --window -e "sshpass -p $passwd ssh $cout -t vim $mode $baspath/basFCGI.c " --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $baspath && /bin/bash' \""
gnome
-terminal --window -e "sshpass -p $passwd ssh $cout -t vim $mode $baspath/eggDAO.c " --tab -e "sshpass -p $passwd ssh $cout -t vim $mode $baspath/eggDAO.h " --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $baspath && /bin/bash' \""
gnome
-terminal --window -e "sshpass -p $passwd ssh $cout -t vim $mode $baspath/basSearchOp.c " --tab -e "sshpass -p $passwd ssh $cout -t vim $mode $baspath/basSearchOp.h " --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $baspath && /bin/bash' \""
gnome
-terminal --window -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $baspath && /bin/bash' \"" --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $baspath/../ && /bin/bash' \""
#gnome-terminal --window -e "sshpass -p $passwd ssh $cout -t gdb /ape/ImRoBot5/Dev/cvs/ImRoBot5/shdaily/cgi/bas.fcgi " --tab -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd $baspath/../ && /bin/bash' \""

fi

if [ $1 = "cd" ]
then
if [ -d $2 ] #进入cvs目录
then
echo "3"
else #进入相应的项目目录
if [ $2 = "sh" ]
then
gnome
-terminal -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd /ape/ImRoBot5/Dev/cvs/ImRoBot5/shdaily/cgi && /bin/bash' \""
fi
if [ $2 = "bas" ]
then
gnome
-terminal -e "bash -c \"sshpass -p $passwd ssh -tt $cout 'cd /ape/ImRoBot5/Dev/cvs/ImRoBot5/bas/cgi && /bin/bash' \""
fi
fi
fi
exit 0
fi
exit 0
fi

LIMIT
=8 #上限
a=0
b
=$1
b
=$(($b-1))
#echo "$b"
if [ $1 -le "$LIMIT" ]
then
while [ $a -le $b ]
do
a
=$(($a+1))
# echo -n "$a "
gnome-terminal -e "sshpass -p $passwd ssh $cout"
done
fi
exit 0
BLOCK

shell自动化脚本3(函数):

g_shdaily_path="/ape/ImRoBot5/Dev/cvs/ImRoBot5/shdaily/cgi"
g_baspath_135
="/ape/ImRoBot5/Dev/cvs/ImRoBot5/bas/cgi"
g_baspath_136
="/ape/Dev/cvs/ImRoBot5/bas"
g_wangkangluo1
="~/wangkangluo1"
g_passwd
="pwd"
g_cout
="ape@ip"
g_limit
=4 #打开终端屏幕数量
g_tail=wssh1.tail #调试跟踪输出文件
#
echo $l_statu >>$g_tail


fun_main( )
{
local l_statu
=`fun_jus_mode $1 $2`
echo $l_statu >>$g_tail
}

fun_jus_mode( )
{
local l_str_back
local l_jud
local l_can_num
=`fun_calu_num $1 $2`
case $l_can_num in
0)
l_str_back
="null"
;;
1)
l_jud
=`fun_jus_ifstr $1`
if [ $l_jud = "str" ]
then
l_str_back
="cd_defalut"
else
l_str_back
="cd_defalut_num"
fi
;;
2)
l_str_back
="ok"
;;
esac
echo $l_str_back
}

fun_jus_ifstr( )
{
local l_statu
if [[ $1 != *[^0-9]* ]]&&[[ $1 != 0* ]]
then
l_statu
="num"
else
l_statu
="str"
fi
echo $l_statu
}


fun_calu_num( )
{
local l_str_back
local l_i
=0

while [ 1 -eq 1 ]
do
if [ $# -eq $l_i ]
then
l_str_back
=$l_i
break
//return 0
fi
l_i
=$(($l_i+1))
done

echo $l_str_back
}

fun_cd_bas( )
{
gnome
-terminal -e "bash -c \"sshpass -p $g_passwd ssh -tt $g_cout 'cd $g_baspath136 && /bin/bash' \""
}

fun_main $
1 $2 $3

posted @ 2011-06-02 16:55  wangkangluo1  阅读(3303)  评论(1编辑  收藏  举报