Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6770849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:21:45+00:00 2026-05-26T15:21:45+00:00

Good day everyone I need to execute command on linux machine this command is

  • 0

Good day everyone

I need to execute command on linux machine this command is interactive
command.
Interactive command means require input like [yes , no] or password
twice

my real case is.
I create a script execute commands and get the outputs successfully.
but some servers has Loging password expired so I need to interact with
server to send the current password + the new password(twice)

ssh userName@10.0.0.243
userName@10.0.0.243's password:
You are required to change your password immediately (password aged)
Last login: Sun Aug  7 13:15:40 2011 from 10.0.0.28
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user userName.
Changing password for userName
(current) UNIX password:
New UNIX password:
Retype new UNIX password:

Notes::

  • I’m using Ruby 1.9.2
  • I’ve no problem in executing command in normal case
  • please, I have to avoid workarounds like (echo “pass” | ssh -S) to make me pass any other interactive situations.
  • I’m using ‘net/ssh’ libs
  • The Script is Attached http://king-sabri.net/files/LinuxHWScanner.rb
  • I tried “net/ssh/telnet” and it doesn’t help
  • Some advises tell useing ‘rake/remote_task’ is the solution but I can’t understand how it works in my case

if you need more simplicity, here a simple code if you make it works I thing it’ll solve my previous issue

  require 'net/ssh'

  host = "10.0.0.106"
  port = 22     # SSH port
  user = 'root'     # username
  pass = "123123"   # password

Net::SSH.start( host,user,:password => pass, :port=> port , :verbose => :error ) do |session|

 puts session.exec!("passwd root")
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:21:46+00:00Added an answer on May 26, 2026 at 3:21 pm

    Something like this?

    Net::SSH.start('10.0.0.6', 'not_root', :password => "test") do |ssh|
       ssh.open_channel do |channel|
          channel.on_request "exit-status" do |channel, data|
            $exit_status = data.read_long
          end
          channel.exec("passwd") do |channel, success|
            if success
              channel.on_data do |channel, data|
                # Don't really need this callback actually
                puts "got data: #{data.inspect}"
              end
              # You don't need this line if you're root
              channel.send_data("oldpass\n")
              channel.send_data("newpass\n")
              channel.send_data("newpass\n")
            else
               puts "FAILED"
            end
          end
          channel.wait
          puts "SUCCESS" if $exit_status == 0
       end
    end
    

    This one is dirty, but working for both upon premature on-expiration prompt and upon passwd issuing:

    Net::SSH.start('localhost', 'not_root', :password => "test") do |ssh|
      ssh.open_channel do |channel|
         channel.on_request "exit-status" do |channel, data|
            $exit_status = data.read_long
         end
         channel.on_data do |channel, data|
            puts data.inspect
            if data.inspect.include? "current"
                    channel.send_data("oldpass\n");
            elsif data.inspect.include? "new"
                    channel.send_data("newpass\n");
            end
         end
         channel.request_pty
         # This will just safely fail if we have already a password prompt on
         channel.exec("passwd");
         channel.wait
         # Will reflect a valid status in both cases
         puts $exit_status
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day everyone. This problem was part of another one which it as been
Good day everyone, i have faced with such an issue as linkage error like
Good day! I've found this solution here: VS2010 Web Publish command line version of
Good day. I'd like to ask a question. Why TextBox control Txt in this
Good day everyone, I am building a page in ASP.NET, and using Master Pages
Good day everyone. I am working on a Firefox extension, and I want to
Good Day Everyone... Apparently, I'm not setting-up impersonation correctly for my WCF service. I
Good Day Everyone... I’m getting an unexpected WCF error complaining of Known Types which
Good day everyone! I am trying to understand how buffer overflow works. Right now,
Good day everyone. I have an audio class, that plays a .wav file. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.