Extracting some part of Perl's Expect Buffer


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Extracting some part of Perl's Expect Buffer
# 1  
Old 06-07-2019
Extracting some part of Perl's Expect Buffer

Hi,

I am capturing command's output on remote host using Expect. The problem is that the command line arguments also getting print with the output in file and also need to print last two relevant columns (percentage used and its mounted point).

The output of $exp->before() buffer is :
Code:
df
Filesystem      1K-blocks     Used Available Use%     Mounted on
devtmpfs         4063064        8   4063056    1%            /dev
tmpfs            4074272        0   4074272       0%             /dev/shm
tmpfs            4074272   141132   3933140     4%             /run
tmpfs            4074272        0   4074272        0%           /sys/fs/cgroup
/dev/sda1       20510332 15487436   3974372  80%       /
/dev/sdb1       10189112   964776   8700100    10%        /var/log
tmpfs             814856        0    814856            0%           /run/user/107
tmpfs             814856        0    814856          0%             /run/user/0

I need following output. Deleted first line (df) and only last two columns interchanged:


Code:
Mounted on     Use%  
/dev                       1%
/dev/shm             0%
/run                      4%
/sys/fs/cgroup   0%
/ 	                     80%
/var/log              10%
/run/user/107    0%
/run/user/0       0%

Thanks

Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags.
It makes it far easier to read and preserves spaces for indenting or fixed-width/tabulated data.

Last edited by rbatte1; 06-07-2019 at 07:05 AM..
# 2  
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question