jojo_angelov
Posts: 38
Joined: Mon Jan 06, 2014 1:59 am

How to store copy of any stdout and/or stderr output

Wed Oct 15, 2014 1:50 pm

So I have a setup where I have an Rpi sitting in a remote location. I have no direct access to the device and I seem to be having some issues with it. I am wondering if there is a way I can redirect all stdout and stderr to a file so after some time I can go back and see a history of what happened on the pi. Almost like as if I had a monitor hooked up to it and I am looking at what is going on with the pi.

User avatar
RaTTuS
Posts: 10462
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: How to store copy of any stdout and/or stderr output

Wed Oct 15, 2014 1:58 pm

yes ... depends though
you may want to look at
dmesg
or
/var/log/
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5973
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: How to store copy of any stdout and/or stderr output

Wed Oct 15, 2014 2:02 pm


User avatar
DougieLawson
Posts: 36179
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How to store copy of any stdout and/or stderr output

Wed Oct 15, 2014 2:41 pm

sudo apt-get install pastebinit
somewonkyprocessname | pastebinit

That gets the stdout written to http://paste.debian.net and gives you back the URL.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

gdt
Posts: 85
Joined: Thu Jul 19, 2012 10:19 am

Re: How to store copy of any stdout and/or stderr output

Sat Oct 18, 2014 10:28 am

If you are talking about the platform then look at the output of "dmesg" and the contents of /var/log/syslog and /var/log/daemon.

If it is a particular program you are interested in then run it like so:

Code: Select all

myprogram >file.txt 2>&1
You read pipes and redirections from right to left, so this outputs channel 2 ("stderr") into channel 1 ("stdout"); then sends stdout to the file named "file.txt"; then starts the program "myprogram".

If you want to be able to log out whilst this is running then this is the magic you need

Code: Select all

nohup 2>&1 myprogram &
What you need to know here is that nohup is a system program which swallows the hangup signal, allowing the myprogram to continue after you log out. nohup sends the stdout of myprogram to the file "nohup.out". So all we need to do is to redirect stderr into stdout. The final "&" starts all of this in the background.

Return to “General discussion”