0

I have an app controlling a piece of connected hardware that displays a few lines of info and requires user input (on stdio). The app runs fine from a shell.

I set up the RPi to auto-login with CLI and run the app as a cron job shortly after reboot. It runs (as evidenced by it interacting properly with the attached hardware) but I cannot see the output and there is no way to enter input; it's running in the background, not interacting with the open shell.

How can I make it interact with the open shell, or start a new one?

5
  • 1
    you can't make cron jobs interactive - that's not what cron jobs are for – Jaromanda X Feb 17 at 2:14
  • I am using it to start the app @reboot, after a short delay to help ensure other services are fully running. I'd gladly use another method but cannot figure out how to do it so that other services fully load at boot. – user120300 Feb 17 at 4:49
  • It's a very interesting idea. I've never tried this, and I'm not quite sure it can be done. If it can be done, the only way I can think to get it done would be to use your cron job to start a screen or tmux session which you could then take control of when you logged in to your interactive shell. It's certainly worth a try... A quick search revealed a few ideas including this one, and this one – Seamus Feb 17 at 5:27
  • screen and tmux did not work for me. I have got around it for now using the workaraoun don the bottom of this but this only works if booting to desktop; not from console. – user120300 Feb 19 at 3:45
  • I cannot understand how this issue is so undocumented. Surely RPis are often used to run a single app at boot? – user120300 Feb 19 at 3:46
1

If you want it to keep a process running so you can use it then install the screen program then use screen at the start command in the cron job. This is where you use the /usr/bin/screen -d -m -fa -S Screen_Name_For_Instance /usr/bin/name_of_server_program to start it up. You can test the command at your command line. Once happy it runs correctly then the CTRL key held down then the a and next d keys pressed while it is held down will detach the screen and leave it running for you. A screen -r will get you back into a running single session screen instance if more than one you need to know the process ID number it tells you when detaching to use screen -r 12345 for process 12345 or if you use the naming option when starting it then screen -r Name. The CTRL key held down then the a and k it is held down will kill off the running session you are in and the program running in it. Or at the command line knowing the process ID number kill 12345. A nice page on it here.

https://stackoverflow.com/questions/4847691/how-do-i-get-out-of-screen-without-typing-exit

1
  • I tried using screen now but it did not help. – user120300 Feb 19 at 3:48
1

Since you are using stdio, a fifo might be a solution for your input. For example, open two terminals and do:

terminal 1:                               |terminal 2:
$ mkfifo fifo                             |
$ tail -f fifo | sed 's/a/A/'             |$ echo hoppa > fifo
hoppA                                     |

So, you could create a fifo in your application directory

mkfifo /your/application/directory/fifo

and use that as to give commands to your application.

Normally, for background jobs, you would redirect the output to some log file, which you could then cat, tail -f or whatever you want.

In all, your crontab entry would be:

@reboot tail -f /your/application/directory/fifo | your_app | logger

When you want to provide input to your application, you do:

echo "Do something" > /your/application/directory/fifo

Here, threw the output on the syslog, so

tail /var/log/messages

would give you the output.

2
  • Sorry, I am new to this and have no idea on how to proceed with this info. – user120300 Feb 19 at 3:47
  • Hope it is clearer now. – Ljm Dullaart Feb 19 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.