ssh commands in Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh commands in Perl
# 1  
Old 08-15-2011
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
server_1/abc_20110802.txt
server_1/abc_20110803.txt
server_2/xyz_20110801.dat
server_2/xyz_20110802.dat



Ex: Input feed file
server_1|abc_*.txt
server_2|xyz_*.dat

I'm trying to ssh to the remote servers and read the file and capture the timestamps of the 'latest' file (in this case server_1/abc_20110803.txt and server_2/xyz_20110802.dat).
ssh keys to all the remote servers are already setup so that we don't need to pass user id and passwords.

I'm able to do this if the files exists in the same server using the following:


my @list_files = map { chomp; $_ } (`ls -t $wild_f_nme`);
my $f_nme=$list_files[0];
my ($accesstime, $modtime, $createtime, $fsize) = (stat($f_nme))[8,9,10,7];



How would I do this to check the time stamps of files in remote servers. I need to initiate ssh connection for each of the servers.

FYI - I'm unable to (cannot) install any modules (like Net::OpenSSH).
Can we accomplish this with using something like ?

my @list_files = map { chomp; $_ } (`qx/ssh $serv_nme ls -t $d_loc/$wild_f_nme`);

---------- Post updated at 10:56 AM ---------- Previous update was at 10:55 AM ----------

Any insights please?

Last edited by bperl; 08-14-2011 at 03:24 PM..
# 2  
Old 08-15-2011
Hi,

No idea of 'ssh' but:

1.- Do you know how to solve your problem using the module 'Net::OpenSSH'? Why cannot install it?
2.- Does next instruction works from command line? What is the output?
Code:
ssh $serv_nme ls -t $d_loc/$wild_f_nme

Regards,
Birei
# 3  
Old 08-15-2011
Code:
ssh $serv_nme ls -t $d_loc/$wild_f_nme

the above command give me the file listings from the remote server just like any ssh command from the command prompt.
Question is how to capture the file stats of files in remote machines through perl script.

The reason I don't want (cannot) install new module is the compatability in higher environments and also migration issues.
# 4  
Old 08-15-2011
redirect it into a file, open the file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remote ssh commands

ssh XXXXX@XXXXX'. $HOME/.profile 2>/dev/null;cd $COMMON_TOP/admin/scripts/$CONTEXT_NAME; adcmctl.sh start "apps${AppsPass}" || cd $ADMIN_SCRIPTS_HOME; adcmctl.sh start "apps${AppsPass}"' As per our business requirement we should be able to execute the above two commands seprated with or ( || )... (4 Replies)
Discussion started by: Y.balakrishna
4 Replies

2. Shell Programming and Scripting

SSH + multiple commands

Sorry for the basic question here, but I can't seem to find an answer anywhere. I want to alias a command that will ssh and then open up bbedit all in 1 command. alias bbb 'ssh NAME@SERVER bbedit' returns: bash: bbedit: command not found It returns this same thing for anything except... (1 Reply)
Discussion started by: busdriver
1 Replies

3. Shell Programming and Scripting

executing commands over ssh

Hi I am trying to send a command over ssh with a parameter but the shell fails to expand the command properly any ideas what am i doing wrong with this. This is ssh on AIX for i in 71 72 73 74 75 do for server in server1 server2 do somestr="Some String" echo "$server... (3 Replies)
Discussion started by: xiamin
3 Replies

4. Shell Programming and Scripting

Bash commands to an 'ssh' within an ssh'

I've struggled to find a solution to this problem from searching so I thought I'd write a post to see what can be done. I'm attempting to connect and run commands on 'server2' but because of security limitations I cannot access it directly. I can however ssh into 'server1' and then into... (7 Replies)
Discussion started by: mcintosh.jamie
7 Replies

5. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

6. Shell Programming and Scripting

remote ssh commands help

I have a script that I'm trying to use that will check for files on a remote machine and if there is files copy the files, modify the perm on the copied files, and then delete the files off of the remote server. Right now I need to get the correct syntax so the the remote commands still interpret... (4 Replies)
Discussion started by: jcalisi
4 Replies

7. Shell Programming and Scripting

[PERL] Running unix commands within Perl Scripts

I understand that in order to run basic unix commands I would normally type at the prompt, I would have to use the following format system(ls -l); or exec(ls -l); But when I actually try to use the command, the script fails to compile and keeps telling me there is an error with this line. ... (1 Reply)
Discussion started by: userix
1 Replies

8. Shell Programming and Scripting

ssh and unix commands

hello, when using ssh, ssh user@<host> do_collect_info.sh I have this error: do_collect_info.sh: ifconfig: not found the error does not appear when I run the sh script locally (no ssh) on the host and with the same user. any idea why? thanks. (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

9. Shell Programming and Scripting

ssh and commands

can someone point me to where it explains how to set the right commands wd ssh? cat something | while read h; do awk 'BEGIN {FS="\n"; RS=""; ORS="\n\n"} {if ($0~/'$h'/) print hdrvar,"\n",$0 }' /something/somedata ; done above works in when ssh'ing into linux machine invoke like this ssh... (10 Replies)
Discussion started by: convenientstore
10 Replies

10. UNIX for Dummies Questions & Answers

SSH Compress Commands

I am brand new to unix and am hoping someone can start me in the right direction. I hope I have the right forum but if not can a moderator move this thread to the right area. I am moving servers and need to back up a folder and its sub folders into a .tar.gz file then want to upload that file... (2 Replies)
Discussion started by: kushti
2 Replies
Login or Register to Ask a Question