codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  How to Change user to root using ssh::expect  want2bemonk at 19:00 on Tuesday, September 01, 2009
 

Hi , I am trying to do a "su -" in a remote machine and run some commands as root.

With the below script i am able to login to the remote machine, but i get "su: incorrect password" error even when the password is correct, i guess i am not passing the password in the correct format.

Please look at the below code and let me know where i am going wrong Thanks.

Code :

#! /usr/bin/perl
use Net::SSH::Expect;

#Preparing for ssh session
my $ssh = Net::SSH::Expect->new (
host=>"posideon",
user=>'testusr',
timeout=>10,
raw_pty=>1,
password=>'wel123go',
log_file=>"/forum/log.txt"
);

#Logging in to the session
$ssh->login();
print "Logged in \n";

# Commands executed on the remote machine
$ssh->exec("stty raw -echo");
$whoami=$ssh->exec("whoami");

print "\$whoami : ",$whoami,"\n";

$ssh->send("su -");
$ssh->waitfor('Password:\s*\z', 1) or die "prompt 'Password' not found after 1 second";

my $pass = "passw0rd";

$result = $ssh->send($pass);

print "\$result : ",$result,"\n";

$whoami=$ssh->exec("whoami");

print "\$whoami : ",$whoami,"\n";

#closing the session
$ssh->close();








Content of the log file :

Password:

Last login: Tue Sep 1 23:53:01 2009 from poseidon.com^M

testusr@poseidon.com:~> testusr@etshmctbox10:~> hscpe

testusr@poseidon.com:~> Password:

su: incorrect password

testusr@etshmctbox10:~>


  Re: How to Change user to root using ssh::expect  amery buck at 13:18 on Saturday, May 08, 2010
 

Nice post about root using ssh::expect. I like your blog very much because it has very interesting articles of different topics like testking 642-067, testking 642-072 and testking 642-357 and their tips and tricks. I am a very big googler and search on different topics. Between searching i found your nice blog. Thanks for your this great blog.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: huffman encoding and decoding in C++...
•  Re: How to Change user to root using ssh::expect
•  Re: Need hosted_button_id value from PayPal generated code
•  Re: need help creating mysql database for my java code
•  Re: IsDate() in JavaScript?
•  Table error????????
•  need to convert sockets in perl on linux to work on windows
•  Re: refresh parent after closing pop up window
•  Re: running a command in remote machine by using perl


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010