shell自动登录ssh并运行另外一台机器上的脚本
平时工作,如果客户有买linux服务器,经常要帮客户安装一些东西,这时得登录客户的服务器,然后从我们公司的服务器拷贝脚本,然后再运行,比较麻烦.
使shell利用python的SimpleHTTPServer模块可以很方便的进行操作(剑走偏锋)
PS: perl的net::ssh与ruby的net/ssh都是现成的.
以后直接运行它就可以了!
- #!/bin/bash
- use () {
- echo -e "try again.\teg: ./$0 1.1.1.1" && exit 1
- }
- echo $(echo $@)|grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' 2>&1 >/dev/null
- if [ $? -ne 0 ]
- then
- use
- if [ $# != 1 ]
- then
- use && exit 1
- fi
- fi
- cd /root/K
- python -c "import SimpleHTTPServer;SimpleHTTPServer.test()" 2>&1 >/dev/null &
- ssh -tt $@ <<EOF
- curl Your_Server_IP:8000/Some_Script|bash && exit
- EOF
- ps aux|grep \[S]impleHTTPServer|awk '{print "kill -9",$2}'|bash
- echo "all the jobs has been done!"
很专业啊,学习下