ssh in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh in perl
# 1  
Old 09-26-2012
ssh in perl

Hi
Can anyone tell me what does the below command do in Perl

Quote:
my @arrayline=`ssh -n $user\@$server $cmd`;
Thanks in advance
# 2  
Old 09-26-2012
Code:
my @arrayline=`ssh -n $user\@$server $cmd`;

above code connects to server whose user name is $user, server address is $server.
and executes command $cmd and assign the output to your variable..
This User Gave Thanks to pamu For This Post:
# 3  
Old 09-26-2012
Quote:
Originally Posted by irudayaraj
my @arrayline=`ssh -n $user\@$server $cmd`;
I consider this a bad way of coding in perl. Unless absolutely necessary, I don't consider it a good practice to invoke system commands in backticks. Check for more perl-ish alternatives. For e.g., there's an SSH module available in CPAN which will enable you to connect to another machine. Also, using system commands in perl defeats portability to different platforms. I've seen people in my previous work-place who have written quick-and-dirty perl scripts with lots of system calls. Instead it would be better to write the whole program in underlying OS' shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl SSH:Expect stdout

I am having a problem figuring out how to turn stdout on in the middle of my ssh session. If I turn it on or off in the initial session it works, but if I try to turn it on in the middle, I can't seem to find the correct statement. my $ssh = Net::SSH::Expect->new ( host =>... (1 Reply)
Discussion started by: numele
1 Replies

2. Shell Programming and Scripting

execute ssh command via perl

Hi I have a perl command that doesn't seem to be working correctly. It appears to be fine but even when i try and run it manually same thing. Can someone take a look at this and tell me what they think the problem could be? Here is the perl Line: system ("echo 'ssh -t -t $user\@$_ \"cd... (3 Replies)
Discussion started by: vpundit
3 Replies

3. Shell Programming and Scripting

Perl SSH without a perl module

I'm trying to create a perl script that will do 1 SSH session, but be able to write multiple commands to the session and receive multiple outputs. I know there are modules out there like Net:SSH::Perl, but I'm not allowed to use it. I was thinking of doing something like an open3 on an ssh... (4 Replies)
Discussion started by: mrwatkin
4 Replies

4. UNIX for Dummies Questions & Answers

SSH Connection under Perl

Hi guys, I have an Active Perl version 5.12.2.1203 installed on my PC, I have a script that will perform some commands to the remote server by using SSH connection from local PC to remote server. I've found out that the Active Perl installed on my PC does not support such module, it only allows... (1 Reply)
Discussion started by: rymnd_12345
1 Replies

5. Shell Programming and Scripting

ssh commands in Perl

I'm new to perl. I have a input file with pipe delimited lines which have server_name, and file names as fields. The file names have wild card (*) in the input feed file. The actual file names will be suffixed with timestamps. Ex: Actual files in remote servers server_1/abc_20110801.txt... (3 Replies)
Discussion started by: bperl
3 Replies

6. Shell Programming and Scripting

Methods to SSH (Perl)...

Can anyone break down the different methods of using SSH in perl? I'm currently using Net::SSH::Expect, which allows me to login to a machine and execute multiple commands without having to ssh again. This feature of holding the session works well for me, but it's slow. If I set timeouts to 4... (3 Replies)
Discussion started by: mrwatkin
3 Replies

7. Shell Programming and Scripting

SSH session in perl.

Is it possible to ssh to a server in perl and execute multiple commands without doing them all at once? I know I can potentially do something like system( 'ssh user@server "cd directory; grep blah *; curl someurl.com"'); However, I'd like the functionality where I don't have to keep SSHing... (3 Replies)
Discussion started by: mrwatkin
3 Replies

8. Shell Programming and Scripting

silent telnet and ssh using perl

Hi Experts, I use perl telnet and ssh for normal tasks and health checks. everything works fine but i would like to run scripts silently and print only data as i wish to. by silent i mean.no banners /no prompts/ nothing. I will format data before i print it on screen. just formatted... (3 Replies)
Discussion started by: mtomar
3 Replies

9. Shell Programming and Scripting

Send "perl -e '...' " command through SSH, from a perl script

Hey guys I am trying to send a perl -e command to a number of systems using SSH. The command should retrieve some information for me. The problem is, the remote shell tries to interpolate my variables and doesn't get it should take the command literally and just execute it. Below the code.... (2 Replies)
Discussion started by: clrg
2 Replies

10. Shell Programming and Scripting

PERL SSH call error

I have a Perl Script #!/usr/local/bin/perl $server_name = "info-xyz-05"; my $value = `/usr/bin/ssh -f $server_name /users/salesadm/MGFINFA/bridgerftpup.sh`; The above calls a shell script on another server called bridgerftpup.sh. This script has several commands and needs to call... (2 Replies)
Discussion started by: alfredo123
2 Replies
Login or Register to Ask a Question