LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2011, 08:35 AM   #1
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
how to redirect output from remote to local


Hi all

I've got a big issue...

I'm doing some commands on a remote server (using ssh to log on to the remote server, did a ssh key swap), how do i redirect the output of a command back to the local server ????

the person who helps me out is my HERO i'm really stuck on this and it would bring me a lot further if i get this to work

pls respond

thx
 
Old 03-29-2011, 08:41 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Technically you can not force an output back to your local machine, but here is what you can do:
Code:
ls -al > /home/user/logfiles/out001.log
Now on your local machine, do the following:
Code:
scp -P 22 remotemachine:/home/user/logfiles/out001.log ~
What the second command will do is transfer the out001.log file to your local machine's home directory.

Cheers,

Josh
 
Old 03-29-2011, 08:46 AM   #3
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
ok, thx, i'll try it

i'll get back to you
 
Old 03-29-2011, 08:47 AM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Not a problem. And will do...

Josh
 
Old 03-29-2011, 08:51 AM   #5
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
You are superman !!
(i mean it works )

is there a way to handle the output created on the remote server (through ssh connection) on the local server?
So i mean, i create a connection with the remote server, i execute some commands and the output of those commands need to be handled on the local server.
Now, you're solution works, but is there a way to do the same WITHOUT redirecting it in files and SCP them to the local server?

Brownie
 
Old 03-29-2011, 10:19 AM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Maybe you could use nc to open a separate port on your local machine, then for each command you execute on the remote computer, redirect the output to nc to send the data over? Something like that in real time?
 
Old 03-29-2011, 11:56 AM   #7
toordog
Member
 
Registered: Jul 2010
Location: Montreal, Canada
Distribution: RedHat, Ubuntu, Solaris, AIX, BSD
Posts: 42

Rep: Reputation: 3
Quote:
Originally Posted by corp769 View Post
Maybe you could use nc to open a separate port on your local machine, then for each command you execute on the remote computer, redirect the output to nc to send the data over? Something like that in real time?

I just did some test and i'm not sure if it apply to your context but here it is:

This test has been done from one unix to another unix.

server2 has a script test.ksh that do a: ls -lai /root

on server1 i do : ssh root@someip /root/test.ksh > test.output.local


On server1, i have the file test.output.local created with the output of the remote ls command.

If you try to create redirection inside your remote script, it will not work because the shell is running on your remote server. If you do the redirect from your local unix, the shell run local so it will output to local stdout.



If you are running windows and using like putty which is a terminal emulator, you will not be able to do it. Instead of putty, you will need a real terminal like plink.

plink.exe. Unlike putty, which acts like a terminal emulator, plink acts like a normal (non-interactive) CLI program.

Using it, I could do this in cmd.exe and get the remote command output saved locally.

\> plink remote_host "ls -l" > log.txt



hope it helps,
 
Old 03-29-2011, 04:05 PM   #8
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
I'm sorry to confuse you. I meant redirecting as in using the pipe to nc. Have you used nc before?
 
Old 03-29-2011, 11:08 PM   #9
toordog
Member
 
Registered: Jul 2010
Location: Montreal, Canada
Distribution: RedHat, Ubuntu, Solaris, AIX, BSD
Posts: 42

Rep: Reputation: 3
Quote:
Originally Posted by corp769 View Post
I'm sorry to confuse you. I meant redirecting as in using the pipe to nc. Have you used nc before?
I know netcat, but it is not the easiest way to do it. You will have a hard time to get the output of netcat into your other shell input.


Regards,
 
Old 03-30-2011, 06:00 AM   #10
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Quote:
Originally Posted by toordog View Post
I know netcat, but it is not the easiest way to do it. You will have a hard time to get the output of netcat into your other shell input.

Regards,
I know that... I was saying to use netcat to send files back to his local computer immediately.
 
Old 03-30-2011, 09:20 AM   #11
toordog
Member
 
Registered: Jul 2010
Location: Montreal, Canada
Distribution: RedHat, Ubuntu, Solaris, AIX, BSD
Posts: 42

Rep: Reputation: 3
Quote:
Originally Posted by corp769 View Post
I know that... I was saying to use netcat to send files back to his local computer immediately.
Isn't it easier to redirect it directly to a local file instead?

*I do agree that netcat could output to a local file as well.
 
Old 03-30-2011, 12:38 PM   #12
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Yes. I was more thinking of a live transfer, if that makes any sense?
 
Old 03-30-2011, 02:56 PM   #13
toordog
Member
 
Registered: Jul 2010
Location: Montreal, Canada
Distribution: RedHat, Ubuntu, Solaris, AIX, BSD
Posts: 42

Rep: Reputation: 3
Quote:
Originally Posted by corp769 View Post
Yes. I was more thinking of a live transfer, if that makes any sense?

Doing something like this would work :

on local server: nc -l 80 -k|cat >test.log

on remote server: ls -lai | nc 10.3.23.193 80


Of course on local server the pipe can send to the input of another script.
 
Old 03-30-2011, 03:05 PM   #14
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Yup, that's exactly what I was thinking. Maybe have a script to display the input in a terminal, real time? Maybe possibly using ttyinject or something like that
 
Old 03-31-2011, 01:12 AM   #15
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
i'm sorry for the delay but i had a job interview yesterday

hmm, i've read your suggestions and it doesn't really makes sense xD i'm not so familiar with all those linux commands so it's hard to understand, but no problem
i understand that there is another possibility to do this without using a 'logfile' but it's probably going to take too much time to get this working, so i'll use that logfile instead (it was already working 2 days ago) now i'm just going to make the logfile in a logical way, so anyone can understand it !!

Maybe another question:
let's say i've put something in a logfile (like ERROR or whatever), so by doing a grep command i can read the ERROR in the file, then there must be done some actions (doesn't matter what), but after those actions (commands like LS or CAT or whatever) can i delete that ERROR from the logfile, i don't mean the WHOLE file, only that ERROR?

Regards

Oh and btw, thanks for all those replies !!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] iptables redirect : local to remote public host paziulek Linux - Networking 2 05-17-2010 02:34 PM
Redirect local DNS query to remote DNS server on non standard port? rock_ya_baby Linux - Server 8 04-13-2010 04:31 AM
redirect output to remote server via ssh packets Programming 4 05-19-2009 08:30 PM
Redirect Output to remote PC possible?? wilkija Linux - Newbie 4 10-03-2006 12:43 PM
Synaptic gui X redirect from remote to local station issue r00tnuke Red Hat 1 09-22-2003 02:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration