How do I capture multiple lines of the status output of a command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I capture multiple lines of the status output of a command?
# 1  
Old 06-19-2009
How do I capture multiple lines of the status output of a command?

I need to know what the upload speed of an Internet connection. I thought the easiest way to do this would be to transfer a file via FTP to my server using the command:
Code:
sh-3.2$ ftp -u ftp://username:password@computerdomain/directory/ file_to_be_uploaded

Note: My environment allows me to issue ONLY 1 line of code. That line of code can have multiple commands seperated by a semi-colon( ; ).

The above command works great in terminal. It uploads the file and gives me lots of text to tell me what is going on:
Quote:
230 User username logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
200 Type set to I.
250 CWD command successful.
local: file_to_be_uploaded remote: file_to_be_uploaded
502 'EPSV': command not understood.
227 Entering Passive Mode (69,13,207,4,232,153)
150 Opening BINARY mode data connection for .
100% |*************************************| 905 KB 200.51 KB/s 00:00 ETA
226 Transfer complete.
927204 bytes sent in 00:05 (173.23 KB/s)
I'm after that last line in the form:
x bytes sent in mm:ss (y KB/s)

I want to obtain the value for y. I thought the way to do this would be to send the output to a text file:
Code:
sh-3.2$ ftp -u ftp://username:password@computerdomain/directory/ file_to_be_uploaded > ftpupload.txt

Problem is, all I get in ftpupload.txt is a previous line that has some useless error on it:
Quote:
502 'EPSV': command not understood.
How can I get the contents of the last line so I know what the upload throughput is?

OR, can someone tell me a better way to do this?

Rob
# 2  
Old 06-19-2009
you can't capture the ftp errors just like that..
redirect the ftp o/p to a file then grep for the suspected errors if found display warning messages
# 3  
Old 06-19-2009
Thanks vidyadhar85! You gave me what I needed to find the answer.

It's a simple -v command on the FTP command line:

Code:
sh-3.2$ ftp -v -u ftp://username:password@computerdomain/directory/ file_to_be_uploaded | grep KB/s

That gives me exactly what I want.

Rob
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python Paramiko multi threading to capture all output for command applied in loop

My issue : I am getting only last command output data in ouput file. Though comamnd "print(output)" displays data for all 3rd column values but the data saved in file is not what required it hs to be the same which is being printed by command"print(output)". Could you please help me to fix this,... (0 Replies)
Discussion started by: as7951
0 Replies

2. HP-UX

How capture all user command line output?

Hi I want to know how capture all user command line output and save this commands and outputs to text files? if you have script for this subject please give me.:o please help me thank you (6 Replies)
Discussion started by: amvhd
6 Replies

3. Shell Programming and Scripting

Capture output of command triggered in background

Is there any way to trigger a sequence of commands in parallel and capture their output in variables? e.g. something on the following lines x=`echo "X" &` y=`echo "Y" &` z=`echo "Z" &` so that $x, $y, and $z evaluate to X, Y and Z res. (7 Replies)
Discussion started by: jawsnnn
7 Replies

4. UNIX for Dummies Questions & Answers

Capture Multiple Lines Into Variable As Of Standard Output

Hello All, I have the below script and output. cat test.sh #!/bin/bash -x logit() { echo " - ${*}" > ${LOG_FILE} } LOG_FILE=/home/infrmtca/bin/findtest.log VAR=`find . -type f -name "*sql"` logit $VAR Output: cat /home/infrmtca/bin/findtest.log -... (9 Replies)
Discussion started by: Ariean
9 Replies

5. Solaris

How to capture Output of truus command

Hi I want to check if some process is sleeping. I can see that in truss -p <pid> I want to capture output and check that output if proces sis sleeping. Please suggest way to capture output of truss command or other way to check if process is sleeping (1 Reply)
Discussion started by: ankush_mehra
1 Replies

6. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

7. Shell Programming and Scripting

Enter the command to capture output--help

&& echo "PLEASE enter the command to capture output" || echo "Processing your command manual" x=$# echo $x while do while man $@ | read -r line do >$@.txt ... (1 Reply)
Discussion started by: rrd1986
1 Replies

8. Solaris

How to capture only some part of output when command executed??

Hi, When I execute this command prtdiag -v output sample : System clock frequency: 160 MHZ Memory size: 4GB ==================================== CPUs ==================================== E$ CPU CPU CPU Freq Size ... (4 Replies)
Discussion started by: vijaysachin
4 Replies

9. Shell Programming and Scripting

Find multiple patterns on multiple lines and concatenate output

I'm trying to parse COBOL code to combine variables into one string. I have two variable names that get literals moved into them and I'd like to use sed, awk, or similar to find these lines and combine the variables into the final component. These variable names are always VAR1 and VAR2. For... (8 Replies)
Discussion started by: wilg0005
8 Replies

10. Shell Programming and Scripting

[csh] How to capture output from a command and pass it on to a variable?

Hi there! I'm trying to write a script that will capture output from a command and assign it to a variable. Let's say, for example, I'd like to catch from inside the script whatever the following command outputs: ls *.aaa and put it into a variable "listoffiles". What I tried was: set... (3 Replies)
Discussion started by: machinogodzilla
3 Replies
Login or Register to Ask a Question