Keeping SSH open from expect within bash script -


before says use public keys, isn't option i'm dealing customer servers.

i have script maintains file of ip/username/passwords of customer's servers. through script select server , use here document expect log in server.

#### code here set variables. exp_internal 1 /usr/bin/expect << eofff  if { $use_tunnel == 1 } {         spawn ssh -l 4567:localhost:3306 $user\@$ip } else {         spawn ssh $user\@$ip } expect {     -re ".*es.*o.*" {         exp_send "yes\r"         exp_continue     }     -re ".*sword.*" {         exp_send "$pass\r"     } } expect {     "$ " { send "<<<send stuff>>>" }     "# " { send "<<<send stuff>>>" } } interact eofff # end of bash script 

my problem after here document ends, closes ssh session , drops me local server. i'd hold remote ssh session open.

edit added exp_internal 1 before if { $use_tunnel == 1 } { end of output below:

spawn ssh ****@***.***.***.*** parent: waiting sync byte parent: telling child go ahead parent: unsynchronized child spawn: returns {22819}  expect: "" (spawn_id exp4) match regular expression ".*es.*o.*"? no ".*sword.*"? no ****@***.***.***.***'s password: expect: "tms6@161.19.242.206's password: " (spawn_id exp4) match regular expression ".*es.*o.*"? no ".*sword.*"? yes expect: set expect_out(0,string) "****@***.***.***.***'s password: " expect: set expect_out(spawn_id) "exp4" expect: set expect_out(buffer) "****@***.***.***.***'s password: " send: sending "***********\r" { exp4 }  expect: "" (spawn_id exp4) match glob pattern "$ "? no "# "? no   expect: "\r\n" (spawn_id exp4) match glob pattern "$ "? no "# "? no last login: thu jun  4 13:39:10 2015 ***.***.***.***  expect: "\r\nlast login: thu jun  4 13:39:10 2015 ***.***.***.***\r\r\n" (spawn_id exp4) match glob pattern "$ "? no "# "? no [***@********* ~]$ expect: "\r\nlast login: thu jun  4 13:39:10 2015 ***.***.***.***\r\r\n\u******@*********:~\u001b\[****@********* ~]$ " (spawn_id exp4) match glob pattern "$ "? yes expect: set expect_out(0,string) "$ " expect: set expect_out(spawn_id) "exp4" expect: set expect_out(buffer) "\r\nlast login: thu jun  4 13:39:10 2015 ***.***.***.***\r\r\n\**********@*********:~\u001b\[***@**************** ~]$ " send: sending "mylist terminalprofile | cut -d'"' -f6\r" { exp4 } interact: received eof spawn_id exp0 [*****@********** sign_on_one_file]$ 

i'm dealing customer servers apologize blanking out of ip/usernames/hostnames/passwords.

so we're clear, last line when drops me prompt prompt of local machine. not remote attempting log in to.

when extract expect script out separate file , call last line of bash script works intended. i'd have in 1 file though ease distribution of script co-workers.

edit 2 <<send stuff>> function on ever server company owns. wrapper print mysql table csv.

expect {     "$ " { send "mylist terminalprofile | cut -d'\"' -f6\r" }     "# " { send "" } } interact 


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -