Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grab the output from scp 1

Status
Not open for further replies.

hokky

Technical User
Nov 9, 2006
170
0
0
AU
Hi Guys,

Just trying to grab the output from scp like :
abc@... 100% --ETA--

to a logfile.

what I've tried is :
Code:
scp [source] [destination] <b>1>logfile.txt</b>

It doesnt work,

any idea ?
 
sorry the bold doesnt work before

scp [source] [destination] <b>1>logfile.txt</b>
 
scp [source] [destination] 1>logfile.txt
 
scp doesn't display any output if the output device is not a terminal.



Annihilannic.
 
While is not exactly what you are looking for, it will "capture" all of the output:

script some.file
- you should then see something like: Script command is started.
- do all the stuff you need to do, scp, etc.
- when done, type: exit
- you should then see something like: Script command is complete.

Everything you did is now in some.file. Do note that the script output will have control characters, etc. in it if/when you vi it.
 
scp doesn't display any output if the output device is not a terminal.

what about the progress of copying until 100%, you know when scp doing copy the counting until 100%.

That's what I wanna know, just in case it's stuck for some reason.

sbrews,

I dont understand your explanation.

you mean I create a script called "some.file" and where do I see Script command is started ?

can you explain more specific please?
 
no, script is a command. It records all screen output.

So for example, this:

script scp_transfer.txt
<script file started (or similar message displayed)>
scp some.file user@host:/some/location
(scp does its thing)
exit
<script file finished (or similar message)>

would record everything types/displayed on the screen from the time you hit enter for the script command until you hit enter for the exit command in a file called scp_transfer.txt
 
hokky said:
what about the progress of copying until 100%, you know when scp doing copy the counting until 100%.

scp will display that progress bar if stdout is to your terminal. But if you try and redirect the output to a file, scp is smart enough to realise that it is not a terminal any more, and does not display the progress bar. The reason is because normally no-one needs to see the progress in a log file, and displaying a progress bar requires use of various screen control codes which would be make a log file messy. If you like you could use the following to produce verbose output, including the duration of the transfer:

[tt]scp -v [source] [destination] > logfile.txt 2>&1[/tt]

Annihilannic.
 
Hi Anni,

With using your command,
I couldn't even grab the verbose output...

In the logfile.txt is nothing captured. :((
 
Really?? What OS are you on and what shell are you using? Did any output go to the screen? What version of ssh (ssh -V to check)?

Annihilannic.
 
The OS is Redhat,

If I didn't redirect it to output file, the output go to the screen

the version of my ssh is
OpenSSH_3.6.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090701f

Thx
 
You mustn't have copied the command I gave you correctly, did you remember the 2>&1 at the end?

[tt]$ ssh -V
OpenSSH_3.6.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090701f
$ echo ${BASH_VERSINFO[*]}
2 05b 0 1 release i386-redhat-linux-gnu
$ scp testfile localhost:/tmp > output
$ ls -l output
-rw-r--r-- 1 anni unixadm 0 Jan 18 08:33 output
$ scp -v testfile localhost:/tmp > output
Executing: program /usr/bin/ssh host localhost, user (unspecified), command scp -v -t /tmp
OpenSSH_3.6.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090701f
<snip>
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0
$ ls -l output
-rw-r--r-- 1 anni unixadm 0 Jan 18 08:33 output
$ scp -v testfile localhost:/tmp > output 2>&1
$ ls -l output
-rw-r--r-- 1 anni unixadm 3489 Jan 18 08:33 output
$[/tt]

Annihilannic.
 
Ooo, I thought I don't need to put 2>&1 at the end as I don't want the std error put into the logfile ?
 
Debugging output is sent to stderr, so yes, you do want that in the log file.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top