"tap" into the console output of a python script that launches /etc/rc.local

Hello all

I have a python script that receives UDP packets and then talks to my arduino sketch over serial connection and works great, the script also prints information to the console.

If I launch the script at a ssh window from the linux command line I can see my "print" commands for debugging purposes.

But when I launch the script by adding oit to /etc/rc.local I loose the ability to see the print commands from the python script. ANd I cannot run another instance by sshing to the yun because the first one is running automatically

Can I ssh and "tap" into the output of the script that was ran automatically at startup and see the output of the script without modifying my arduino sketch?

Thank you

Best regards

Rodolfo

Pipe it to log file:

foo.py >/var/log/foo.log

might better pipe error message as well.

foo.py >/var/log/foo.log 2>&1

1 is stdout. 2 is stderr.

Hello Sonnyyu

Thank you for your kind answer.

I need to be able to see the messages as they are happening because those are UDP packets that are sent to the arduini sketch for lighting control in realtime.

I was thinking of a way of tapping into maybe a device at the /dev folder maybe with a c program where I can catch the console output of the script that was run by /etc/rc.local

Or just like you suggest instead of piping to a file, is there a way to pipe to a device I can later access to see the output like if I was running on a terminal window?

THANK YOU

Have a great day!

Rodolfo

tail --help
...
-f              Print data as file grows
...
tail -f /var/log/foo.log

Thank you Sonny yu

This answer definetly works. I was hoping to find a solution that did not involve files as the process is constantly running and as the Yun's internal memory has a limited life and an USB or micro SD card as well, I cannot use this solution to permamently monitor the python script.

Can you please recommend me a way of implementing a browser based "text dump" application where I just dump from the python script anything I want and then from a browser connected to my yun I watch my debug info?

I will appreciate your help a lot

THANK YOU

Best

Rodolfo

rmagnus: ... This answer definetly works. I was hoping to find a solution that did not involve files as the process is constantly running and as the Yun's internal memory has a limited life and an USB or micro SD card as well, I cannot use this solution to permamently monitor the python script. ...

foo.py >/tmp/foo.log 2>&1

will log to RAM

rmagnus: ... Can you please recommend me a way of implementing a browser based "text dump" application where I just dump from the python script anything I want and then from a browser connected to my yun I watch my debug info? ...

foo.py >/www/foo.log 2>&1

view it at "http://arduino.local/foo.log"

@sonnyyu you are THE MAN

WOW

I love this solution!

So /tmp is ram mounted as a folder?

That is great!

THANK YOU

Best

Rodolfo

rmagnus:
::::SNIP::::
Can I ssh and “tap” into the output of the script that was ran automatically at startup and see the output of the script without modifying my arduino sketch?
::::SNIP::::

@Rodolfo

Redirection, as Sonny has pointed to, is one possible solution. Unix/Linux was made for “streaming” text and data. As such, there is a host of solution. (No pun intened.)

Unix/Linux has three standard stream (standard in, standard out, & standard error), respectively numbered 0,1, & 2. In addition, there are command line symbols that are standard among the many shells available (Yun uses the predecessor to bash, ash.)

The symbols for redirection are:

< standard in redirected

standard out redirected
| piping of standard out.
tee (the program) pipes to a file and standard out at the same time (man tee)

You might do well to redirect or pipe your output, but python can output to a file, AND standard in, standard out, & standard error.

System-specific parameters and functions
https://docs.python.org/2/library/sys.html

Jesse

@sonnyyu

Success! I am logging now to a file stored at /tmp so I have no concern about wearing out flash memory.

Is there a way to access the file with a browser as easy as your example

"http://arduino.local/foo.log"

without copying the file to folder /www?

I am ok if I need to add a file to the www directory that shows the file stored at /tmp folder or if I need to modify the original file that shows files at /www directory but I don’t know where they are.

THANK YOU

Best
Rodolfo

Load an other small http daemon and map "/tmp" to its http root directory.

opkg update
opkg install mini-httpd
nano /etc/mini_httpd.conf
cgipat=cgi-bin/**|**.sh
dir=/tmp
nochroot
pidfile=/var/run/mini_httpd.pid
user=root
port=8080
/etc/init.d/mini_httpd restart
/etc/init.d/mini_httpd enable

View log file at "http://arduino.local:8080/foo.log".

@sonnyyu

It works perfect and it seems to stay working after power off.

This will help me a lot monitoring the correct execution of scripts run by /etc/rc.local by just doing a:

date>/tmp/foo.log

Now I know if a .sh script executed or not

And same goes for a Python script.

Now, one last question:

If I put html files inside /www (before doing this mod you recommended) or /tmp after the mod, can I execute by calling for example:

"http://arduino.local/test.html" if it is under /www

Or "http://arduino.local:8080/test.html"? after changing to /tmp?

THANK YOU!

Have a great weekend

@Jesse THANK YOU