Keep CT to automatically execute command scripts on the remote host

Source: Internet
Author: User

 

The first script in December 2014, haha !!! Keep CT to automatically execute the command script on the remote host:

#!/usr/bin/expect --if { [llength $argv] < 4 } {puts "Usage: $argv0 ip user passwd port commands timeout"exit 1}match_max 600000set ip [lindex $argv 0]set user [lindex $argv 1]set passwd [lindex $argv 2]set port [lindex $argv 3]set commands [lindex $argv 4]set timeoutflag [lindex $argv 5]set yesnoflag 0set timeout $timeoutflagfor {} {1} {} {# for is only used to retry when "Interrupted system call" occuredspawn /usr/bin/ssh -q -l$user -p$port $ipexpect {"assword:" {send "$passwd\r"break;}"yes/no)?" {set yesnoflag 1send "yes\r"break;}"FATAL" {puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n"exit 1}timeout {puts "\nCONNECTERROR: $ip Logon timeout!!!\n"exit 1}"No route to host" {puts "\nCONNECTERROR: $ip No route to host!!!\n"exit 1}"Connection Refused" {puts "\nCONNECTERROR: $ip Connection Refused!!!\n"exit 1}"Connection refused" {puts "\nCONNECTERROR: $ip Connection Refused!!!\n"exit 1}"Host key verification failed" {puts "\nCONNECTERROR: $ip Host key verification failed!!!\n"exit 1}"Illegal host key" {puts "\nCONNECTERROR: $ip Illegal host key!!!\n"exit 1}"Connection Timed Out" {puts "\nCONNECTERROR: $ip Logon timeout!!!\n"exit 1}"Interrupted system call" {puts "\n$ip Interrupted system call!!!\n"}}}if { $yesnoflag == 1 } {expect {"assword:" {send "$passwd\r"}"yes/no)?" {set yesnoflag 2send "yes\r"}}}if { $yesnoflag == 2 } {expect {"assword:" {send "$passwd\r"}}}expect {"]" {send "$commands \r"}"assword:" {send "$passwd\r"puts "\nPASSWORDERROR: $ip Password error!!!\n"exit 1}}expect {"]" {send "sleep 1 \r"}}expect {"]" {send "exit\r"}}expect eof {puts "OK_SSH: $ip\n"exit 0;}

Usage:

./ssh.expUsage: ./ssh.exp ip user passwd port commands timeout

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.