Perl open a remote shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl open a remote shell
# 1  
Old 08-24-2010
MySQL Perl open a remote shell

Hello ,

I am writing a script which takes the user name , password and hostname from the database and login to the server .

I am only able to login to the server and my script logs out and only I can run few command if I provide those command in my script else I am not able to run those command after logging in.

I need to run those command once I have logged in using my script and I want to track down all the commands being executed in a particular session.

I know how to run command on remote shell using script , but I want to open remote shell using perl and want to run the command manually and terminate the session when I am done as we normally do with shell .

Any help or guidance will be highly appreciated.

Thanks
# 2  
Old 08-24-2010
You can use the following method,


Code:
# get data from database and form ssh
.
.
.
.
.

# execute the formed ssh to the remote machine.
# exec ( "ssh .... ...." )
# this will give you the remote shell, where you can execute the commands manually.. and exit..

Refer <b>perldoc -f exec</b> for further details
# 3  
Old 08-24-2010
check if CPAN package Net::SSH is what you are looking for
# 4  
Old 08-24-2010
yes I have net::ssh:Smilieerl and expect too
This script can execute can execute the command which is given in the script only but I want to enter the command manually and I should be able to terminate the session when I am done with my work.

here is the basic script which I am using to execute the few command but I want to generalize it

Code:
#!/usr/bin/perl -w
use Net::SSH::Perl
$host = '192.168.0.114';
$username = 'user';
$login_passwd = ''password;


my $cmd = "ls -l";
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($username, $login_passwd);

my($stdout, $stderr) = $ssh->cmd("$cmd");
print "$stdout\n$cmd\n";

Thanks for the response Smilie

Last edited by Yogesh Sawant; 08-24-2010 at 06:45 AM.. Reason: added code tags
# 5  
Old 08-24-2010
then what stops you from obtaining the command from STDIN and passing it as an argument to $ssh->cmd()
# 6  
Old 08-25-2010
Thanks Yogesh,

But I may need to enter multiple commands and it may also depend on the situation of my requirement hence every time loging into the server and logging out is a problem , is there any way I can escape this and my script should login once and execute as many command as I want without logging out from the server .

Smilie
# 7  
Old 08-25-2010
Why not just run system("ssh user@hostname"); and let the user interact with it directly?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

2. UNIX for Dummies Questions & Answers

Check port 2222 is open on a remote host

I am able to connect to a remote host using the legacy IP and port 2222. Today the remote has a new IP I am unable to connect. How to check if the remote host is blocking or if its my server is unable to connect. Err Msg : telnet: Unable to connect to remote host: Connection refused Err... (5 Replies)
Discussion started by: ITDev01
5 Replies

3. Shell Programming and Scripting

Triggering remote UNIX shell script from Remote desktop

I m trying to run a batch script in remote desktop which executes unix commands on the unix server...the problem is i wnt the output in HTML format.so in my batch script i m giving the cmd like ssh hostname path ksh HC_Report.ksh>out.html ...but it generates the HTML file in remote desktop .i... (2 Replies)
Discussion started by: navsan
2 Replies

4. Shell Programming and Scripting

Help !! perl open function

Help Please perl Gurus, I am trying to add ungrouped passengers in a group and I creating a script however it fails on first step only I tried all the options it returns following error. syntax error at junki line 4, near "open " Execution of junki aborted due to compilation errors. ... (2 Replies)
Discussion started by: dynamax
2 Replies

5. UNIX for Dummies Questions & Answers

How to Know is a Remote hosts have open port

Hi gurus of unix!!!!, I have a little question. I nedd your helps The scenarios is the following I have tree equipment that are installed in different places. I use a carrier to interconnect the equipment. Some Port's (TCP) need to be open for an application that must be function correctly. For... (3 Replies)
Discussion started by: andresguillen
3 Replies

6. Shell Programming and Scripting

Open n number of remote sessions

I m need of something useful to reduce my n number of login sessions to save my time. Scenario : I will login 40+ servers daily with ip address. i hv generated ssh key gens in order to avoid passwords. what i need is : when i click a terminal, i need these 40 servers logged in... (1 Reply)
Discussion started by: anand.linux1984
1 Replies

7. Shell Programming and Scripting

Simple open remote file script

I use Rsync to copy files to a remote folder in a command like this rsync -aNPHAXxrvh --protect-args --fileflags --force-change --delete $file user@remotehost:/Volumes/backup That works great with passwordless key exchange ;) Now I'm trying to open a remote file using this command ssh -q... (5 Replies)
Discussion started by: elbombillo
5 Replies

8. Solaris

Unable to open remote connections

Hello everybody, This is an unusual problem that I am facing on my Solaris 9 on Sun Blade 150 workstation. I can ping remote machines (outside subnet) but I can't open up a connection/port on those machines. For example, `ping ftp.xyz.com` gives ftp.xyz.com is alive but if I do a `ftp... (1 Reply)
Discussion started by: red_crab
1 Replies

9. UNIX for Dummies Questions & Answers

Remote Connect - SCO Open Server

Hello.. Please helppppppp...!!! I am using SCO Open Server version 5.0 at work. I am trying to find a third party software to use on my computer at home which has windows 98 on it to do remote connect to my work. Is there any such software ? I know there is PC ANYWHERE but i don't think it... (2 Replies)
Discussion started by: jackpotp
2 Replies
Login or Register to Ask a Question