Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Extracting some part of Perl's Expect Buffer Post 303035894 by rbatte1 on Friday 7th of June 2019 06:09:55 AM
Old 06-07-2019
Welcome suneet17,

I have a few to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far? Please paste this in CODE tags.
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools you are calling this in with? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.
Is there a reason not to just use something like ssh $user@$server df > $local_output_file?


We're all here to learn and getting the relevant information will help us all.


Thanks, in advance,
Robin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting part of the basename

Hi, I was wondering if there is an easy way to strip off the required basename. I have a script called apb0110021.sh and the contents of the script are typeset -u MScript=`basename $0 | cut -d. -f1` scriptname=sys.Audit.ksh parms="PROJECT1 dsAudit $MScript 1 BEGIN" $SCRIPTS/$scriptname... (3 Replies)
Discussion started by: madhunk
3 Replies

2. Shell Programming and Scripting

Expect buffer size increase, please help

Hi Group, I am struggling to increase buffer size of expect, sometimes after increasing the buffer size, expect captures all my expected output, sometimes not, :-( I tried match_max 700000 set expect_out(buffer) {} Could anybody guide me for any solution. HTH,... (1 Reply)
Discussion started by: jaduks
1 Replies

3. Shell Programming and Scripting

need help extracting this part

JADE TRADER 143W MYPEN 40 HC M X10 28 7 1 0 MYPEN 20 GP X X10 15 2 1 0 MYPEN 40 GP X X10 28 7 1 0 MYPEN 20... (6 Replies)
Discussion started by: finalight
6 Replies

4. Shell Programming and Scripting

awk: Extracting part of the buffer

Hi, I am trying to extract part of a line using "awk". My requirement is to extract the value $6 (which is the last parameter) from a line. As the sixth value contains some space, i am getting only part of the string. so i am trying to extract from $6 to the end of the buffer. How to do it... (7 Replies)
Discussion started by: venkat_k
7 Replies

5. Shell Programming and Scripting

Expect: How to read buffer for spawn

Hi All, I have to write one expect script to login to one system. I am using set timeout -1 match_max 100000 spawn ssh root@hostname Now when I do spawn ssh to that host it send some warning message and one challenge Challenge: 111-2345 I need to read this challenge value and has... (1 Reply)
Discussion started by: Lokesh Agrawal
1 Replies

6. Shell Programming and Scripting

EXPECT help with full buffer(?), or other available solutions

First, to level set: I'm proficient enough with basic BASH scripting for simple things (say, 4 out of 10), but this current project really requires a higher understanding of EXPECT than I have. I have an interactive-only control application residing locally on a database server that I would... (2 Replies)
Discussion started by: toeharp
2 Replies

7. UNIX for Dummies Questions & Answers

Extracting part of a word

I have the code message={TP=2012:09:23:00:00:00:GMT,SD=2012:09:23:00:00:00:GMT,SP=2,FT=CCGT,FG=3605} I want to extract the FG=3605 parts of this. Please help. I am trying to do this using awk or unix. (5 Replies)
Discussion started by: JenniferTopham
5 Replies

8. Shell Programming and Scripting

Filtering escape character from expect buffer

I have written an application in Tcl-Expect which spawns minicom and sends and receives data via the serial port. Sometimes i see that the application receives control characters along with human readable data. A search on the internet tells me that the control characters are nothing but the VT... (0 Replies)
Discussion started by: cityprince143
0 Replies

9. Shell Programming and Scripting

Extracting a part of a string

Hi, I needed to extract some specific characters from a string based on user input. For example: After the script executes the user enters the following details: Please enter the string: This is a shell script Please enter the starting position: 11 Please enter the number of characters to be... (4 Replies)
Discussion started by: ChandanN
4 Replies

10. Shell Programming and Scripting

Extracting the part of string

I have a string: 2015-04-16 07:30:05,625000 +0900 xxxx.com I just want to extract the time from the above line I am using the below syntax x=~ /(.*) (\d+)\:(\d+)\:(\d+),(.*)\.com/ $time = $2 . ':' . $3 . ':' . $4; print $time But it is not working. Can some1 please help (2 Replies)
Discussion started by: karan8810
2 Replies
SSH(3pm)						User Contributed Perl Documentation						  SSH(3pm)

NAME
Net::SSH - Perl extension for secure shell SYNOPSIS
use Net::SSH qw(ssh issh sshopen2 sshopen3); ssh('user@hostname', $command); issh('user@hostname', $command); ssh_cmd('user@hostname', $command); ssh_cmd( { user => 'user', host => 'host.name', command => 'command', args => [ '-arg1', '-arg2' ], stdin_string => "string ", } ); sshopen2('user@hostname', $reader, $writer, $command); sshopen3('user@hostname', $writer, $reader, $error, $command); DESCRIPTION
Simple wrappers around ssh commands. For an all-perl implementation that does not require the system ssh command, see Net::SSH::Perl instead. SUBROUTINES
ssh [USER@]HOST, COMMAND [, ARGS ... ] Calls ssh in batch mode. issh [USER@]HOST, COMMAND [, ARGS ... ] Prints the ssh command to be executed, waits for the user to confirm, and (optionally) executes the command. ssh_cmd [USER@]HOST, COMMAND [, ARGS ... ] ssh_cmd OPTIONS_HASHREF Calls ssh in batch mode. Throws a fatal error if data occurs on the command's STDERR. Returns any data from the command's STDOUT. If using the hashref-style of passing arguments, possible keys are: user (optional) host (requried) command (required) args (optional, arrayref) stdin_string (optional) - written to the command's STDIN sshopen2 [USER@]HOST, READER, WRITER, COMMAND [, ARGS ... ] Connects the supplied filehandles to the ssh process (in batch mode). sshopen3 HOST, WRITER, READER, ERROR, COMMAND [, ARGS ... ] Connects the supplied filehandles to the ssh process (in batch mode). EXAMPLE
use Net::SSH qw(sshopen2); use strict; my $user = "username"; my $host = "hostname"; my $cmd = "command"; sshopen2("$user@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; while (<READER>) { chomp(); print "$_ "; } close(READER); close(WRITER); FREQUENTLY ASKED QUESTIONS
Q: How do you supply a password to connect with ssh within a perl script using the Net::SSH module? A: You don't (at least not with this module). Use RSA or DSA keys. See the quick help in the next section and the ssh-keygen(1) manpage. A #2: See Net::SSH::Expect instead. Q: My script is "leaking" ssh processes. A: See "How do I avoid zombies on a Unix system" in perlfaq8, IPC::Open2, IPC::Open3 and "waitpid" in perlfunc. GENERATING AND USING SSH KEYS
1 Generate keys Type: ssh-keygen -t rsa And do not enter a passphrase unless you wanted to be prompted for one during file copying. Here is what you will see: $ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/User/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/User/.ssh/id_rsa. Your public key has been saved in /home/User/.ssh/id_rsa.pub. The key fingerprint is: 5a:cd:2b:0a:cd:d9:15:85:26:79:40:0c:55:2a:f4:23 User@JEFF-CPU 2 Copy public to machines you want to upload to "id_rsa.pub" is your public key. Copy it to "~/.ssh" on target machine. Put a copy of the public key file on each machine you want to log into. Name the copy "authorized_keys" (some implementations name this file "authorized_keys2") Then type: chmod 600 authorized_keys Then make sure your home dir on the remote machine is not group or world writeable. AUTHORS
Ivan Kohler <ivan-netssh_pod@420.am> Assistance wanted - this module could really use a maintainer with enough time to at least review and apply more patches. Or the module should just be deprecated in favor of Net::SSH::Expect or made into an ::Any style compatibility wrapper that uses whatver implementation is avaialble (Net::SSH2, Net::SSH::Perl or shelling out like the module does now). Please email Ivan if you are interested in helping. John Harrison <japh@in-ta.net> contributed an example for the documentation. Martin Langhoff <martin@cwa.co.nz> contributed the ssh_cmd command, and Jeff Finucane <jeff@cmh.net> updated it and took care of the 0.04 release. Anthony Awtrey <tony@awtrey.com> contributed a fix for those still using OpenSSH v1. Thanks to terrence brannon <tbone@directsynergy.com> for the documentation in the GENERATING AND USING SSH KEYS section. COPYRIGHT
Copyright (c) 2004 Ivan Kohler. Copyright (c) 2007-2008 Freeside Internet Services, Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. BUGS
Not OO. Look at IPC::Session (also fsh, well now the native SSH "master mode" stuff) SEE ALSO
For a perl implementation that does not require the system ssh command, see Net::SSH::Perl instead. For a wrapper version that allows you to use passwords, see Net::SSH::Expect instead. For another non-forking version that uses the libssh2 library, see Net::SSH2. For a way to execute remote Perl code over an ssh connection see IPC::PerlSSH. ssh-keygen(1), ssh(1), IO::File, IPC::Open2, IPC::Open3 perl v5.10.0 2008-05-14 SSH(3pm)
All times are GMT -4. The time now is 03:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy