LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Command output redirection > doesn't print to file (https://www.linuxquestions.org/questions/linux-general-1/command-output-redirection-doesnt-print-to-file-4175466416/)

djg2002 06-17-2013 06:02 PM

Command output redirection > doesn't print to file
 
I've used Linux for a while but am stumped. I just installed stun and ran the following:

david@smurf > stunc stun.stunprotocol.org -b > res
assign_socket: local socket is bound to 0.0.0.0:48157
stunc_bind_cb: stun_discovery_done
stunc_bind_cb: local address NATed as 13.135.7.82:48157
david@smurf > more res
david@smurf >

i.e. nothing got written to 'res' but continued to be output to screen.

What do I need to do to get access to the output? (I need it for a script I'm putting together).

Thanks,

David

(Ubuntu 12.04)

lleb 06-17-2013 07:48 PM

why are you trying to redirect before the command as well as after?

Code:

[user@server ~]$ nmap -p22 google.com

Starting Nmap 5.51 ( http://nmap.org ) at 2013-06-17 16:36 EDT
Nmap scan report for google.com (74.125.140.101)
Host is up (0.036s latency).
Other addresses for google.com (not scanned): 74.125.140.102 74.125.140.113 74.125.140.139 74.125.140.100 74.125.140.138
rDNS record for 74.125.140.101: ye-in-f101.1e100.net
PORT  STATE    SERVICE
22/tcp filtered ssh

Nmap done: 1 IP address (1 host up) scanned in 0.56 seconds
[user@server ~]$ nmap -p22 google.com > foo.txt
[user@server ~]$ cat foo.txt

Starting Nmap 5.51 ( http://nmap.org ) at 2013-06-17 16:36 EDT
Nmap scan report for google.com (74.125.140.138)
Host is up (0.024s latency).
Other addresses for google.com (not scanned): 74.125.140.100 74.125.140.139 74.125.140.113 74.125.140.102 74.125.140.101
rDNS record for 74.125.140.138: ye-in-f138.1e100.net
PORT  STATE    SERVICE
22/tcp filtered ssh

Nmap done: 1 IP address (1 host up) scanned in 0.36 seconds

like that. your output indicates that you are trying to redirect the input into the output, that is not going to work.

also please use code flags. [ code ] [ / code ] remove the spaces and put your copy/paste from the CLI into them.

p.s. if you are putting this into a script, it might be a good idea to use >> instead of >

> will create the file and overwrite 100% of data inside the file.
>> will create the file if it does not exist and if it does it will "append" to the end of the file the new output.

unSpawn 06-17-2013 07:59 PM

Try
Code:

stunc stun.stunprotocol.org -b > res 2>&1

chrism01 06-17-2013 08:46 PM

As hinted by UnSpawn, stdout (chan 1) is going to the file, but stderr (chan 2) is not, so you need to change that.

@lleb: I don't think that's a re-direct before the cmd, more like the last part of his bash prompt.

pawandarkknight 06-18-2013 11:43 PM

Thanks Sir !!


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