Sponsored Content
Top Forums Shell Programming and Scripting Remote ssh and return values.. Post 302420200 by deindorfer on Tuesday 11th of May 2010 03:02:13 AM
Old 05-11-2010
Using Net::SSH::Perl To Find A Pattern in a remote file and print info on matched file

Quote:
Originally Posted by radoulov
Or, of course, use Net::SSH:Perl if it's available.
Here's How You Can Do That:
Code:
#! /usr/bin/perl

use strict;
use warnings;
use Net::SSH::Perl;

my $user = '';
my $pass = '';
my $host = '';
my $port = 22;
my $DEBUG = 0;
my $attr = { debug => $DEBUG, port => $port, protocol => '2,1'};

my $cmd = qq~perl -lne 'if ( /(PAT_HERE)/ ) { printf "PATTERN: %s LINE: %d FILE: %s INODE %s", \$1, \$., \$ARGV, (stat \$ARGV)[1]; }' *~;
my $ssh = Net::SSH::Perl->new($host, %$attr);
$ssh->login($user, $pass);
my ($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print $stdout, "\n";

The above code expects you to replace the string "PAT_HERE" with the one you are looking for.

The code searches the files in the user-you-logged-in-as' ( $user ) home directory. If you want to search in other directories change the "cmd" line to something like this, where the the string " \/some\/dir\/* " is a directory you want to search:

Code:
my $cmd = qq~perl -lne 'if ( /(PAT_HERE)/ ) { printf "PATTERN: %s LINE: %d FILE: %s INODE %s", \$1, \$., \$ARGV, (stat \$ARGV)[1]; }' \/some\/dir\/*~;

More effort will be required if you want to handle situations in which no matches are returned gracefully.

Hope That Helps.

Last edited by deindorfer; 05-11-2010 at 04:13 AM.. Reason: Add Escaping Slashes
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

exit/return values

Sys: HP-UX 9000 In the calling script how do I 'read' the return/exit value of a called script?:confused: THX in advance for any assistence.:) (1 Reply)
Discussion started by: vslewis
1 Replies

2. Shell Programming and Scripting

Possible return values for $?

I think the $? returns 0 if the last issued command was successful and otherwise if not. But does anyone knows the value list that may be returned ? (or it is only zero/one ? ) Thanks in advance, Abrahao. (3 Replies)
Discussion started by: 435 Gavea
3 Replies

3. Shell Programming and Scripting

Help: return values from awk

Hi. I have a script like this: nawk 'BEGIN {FS=","; TOT1=0; REJ1=0;} { if($7=="TOTAL") { TOT1=TOT1 +$8} if($7=="REJS") { REJ1=REJ1 +$8} }' FILE_123.dat and... (1 Reply)
Discussion started by: mrodrig
1 Replies

4. Shell Programming and Scripting

can quoted text return values

Hi All, index=10.5 let "res = $index + 1.7" echo "res = $res" Can anybody explain what this piece of code does. (7 Replies)
Discussion started by: kinny
7 Replies

5. UNIX for Dummies Questions & Answers

Command does not want to return on ssh

Hi, I am trying to use this command to backup my remote server: ssh ftp nice -19 bru -cXiAf mail-02:/dev/nst1 /etc When I run I get: connect to address 205.150.86.5 port 544: Connection refused connect to address 205.150.86.5 port 544: Connection refused trying normal rsh... (1 Reply)
Discussion started by: mojoman
1 Replies

6. Shell Programming and Scripting

Can $? return multiple values?

Hi, I have a script which does something like the below: execute_some_script.sh $arg1 $arg2 `exec-some-cmd` if then; do something else do something else fi However, during some cases, there is an error saying: line xxx: [: too many arguments at the line number which has... (5 Replies)
Discussion started by: laloo
5 Replies

7. Solaris

how to login with ssh to remote system with out applying the remote root/usr password

how to login with ssh to remote system with out applying the remote root/user password with rlogin we can ujse .rhosts file but with ssh howits possible plz guide (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

8. Shell Programming and Scripting

Need Multiple Return Values

Hi, I need to retrun multiple values function errorFileCreation { echo "Before" return -1 "Siva"; echo "Aftyer" } echo ${?} - This can be used to getting first value. how can i get second one. Advance Thanks... Shiv (3 Replies)
Discussion started by: rsivasan
3 Replies

9. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

10. BSD

Connection SSH to remote by ssh

Hello guys! I am setting up a script to access a unix remote server. My problem is that when I put the ssh line "my host", the script does not wait for the server response asking for the password to execute the line in which I put the password, that is, I need to put a form in which script has a... (1 Reply)
Discussion started by: aroucasp
1 Replies
ssh-keysign(1M) 														   ssh-keysign(1M)

NAME
ssh-keysign - ssh helper program for host-based authentication SYNOPSIS
ssh-keysign ssh-keysign is used by ssh(1) to access the local host keys and generate the digital signature required during host-based authentication with SSH protocol version 2. This signature is of data that includes, among other items, the name of the client host and the name of the client user. ssh-keysign is disabled by default and can be enabled only in the global client configuration file /etc/ssh/ssh_config by setting Host- basedAuthentication to yes. ssh-keysign is not intended to be invoked by the user, but from ssh. See ssh(1) and sshd(1M) for more information about host-based authen- tication. /etc/ssh/ssh_config Controls whether ssh-keysign is enabled. /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_rsa_key These files contain the private parts of the host keys used to generate the digital signature. They should be owned by root, readable only by root, and not accessible to others. Because they are readable only by root, ssh-keysign must be set-uid root if host-based authentication is used. ssh-keysign will not sign host-based authentication data under the following conditions: o If the HostbasedAuthentication client configuration parameter is not set to yes in /etc/ssh/ssh_config. This setting cannot be overri- den in users' ~/.ssh/ssh_config files. o If the client hostname and username in /etc/ssh/ssh_config do not match the canonical hostname of the client where ssh-keysign is invoked and the name of the user invoking ssh-keysign. In spite of ssh-keysign's restrictions on the contents of the host-based authentication data, there remains the ability of users to use it as an avenue for obtaining the client's private host keys. For this reason host-based authentication is turned off by default. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsshu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ ssh(1), sshd(1M), ssh_config(4), attributes(5) AUTHORS
Markus Friedl, markus@openbsd.org HISTORY
ssh-keysign first appeared in Ox 3.2. 9 Jun 2004 ssh-keysign(1M)
All times are GMT -4. The time now is 03:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy