From: locky thindromen Date: 2012-07-24T22:48:31+09:00 Subject: help with net-ssh shell-script timing I'm working on a script to connect to a remote server, run a custom su script, and then execute commands after it finishes and hands the root prompt back. my main issue seems to be that net-ssh likes to fire-and-forget commands sent over the channel. what's killing me is this sudo script, i cannot alter it, and i cannot get to the files i need to output without going through it first. ___ the script behaves like this user@blah > ss Password: executing script blablabla... root@blah > ___ what i have so far: SSH.start(host, user){|ssh| ssh.open_channel{|channel| #get root privelages #configure behavior of channel channel.on_data{|channel, data| #when output is recieved from remote stdout do... puts "#{data}" if data =~ /^Password:/ channel.send_data("#{PASSWORD}\n") else end channel.on_close... (etc.) channel.request_pty do |ch, success| if success puts "pty successfully obtained" else puts "could not obtain pty" end end channel.exec("ss"){|channel, win| #custom sudo script. if win puts "ss command sent" else puts "ss command FAIL" end } channel.exec("tail /some/log/file.txt") #or channel.send_data # ssh.exec, and exec! ...end what i've tried so far (that i can remember) i've tried to block the exec("ss") command, syncronizing exec"ss" the .on_data password callback, and the tail command. tried having the channel wait() after calling SS, nesting the tail command in the on_data callback right after sending the password. tried having the on_data callback update its self something like this... channel.on_data{|channel, data| if data =~ /^Pssword:/ channel.send_data("#{PASSWORD}\n"){ channel.on_data{|channel, data| #executing script blablabla... channel.on_data{|channel, data| channel.exec("tail /some/log/file.txt") } } } i've come at the problem from every angle i can come up with, and still need to figure out how ensure that if SS returns a root prompt without requesting the password (if i've logged in recently) that the script will proceed. you all have been phenomenally helpful in the past, thanks in advance for any assistance ~Locky -- Posted via http://www.ruby-forum.com/.