0

I'm making a kiosk like system, which reads data from a barcode reader, and a java program reads it from the console, and interprets it. I switched on autologin, and use crontab to run it like

* * * * * /home/name/script.sh < /dev/tty1 > /dev/tty1

while the script itself also includes

exec sudo /usr/bin/java -jar '/home/name/reader/dist/reader.jar' </dev/tty1

(There are other parts of the script, but they just check other running programs...)

What I expect is that after login, the crontab runs it like I was simply running it from the console. However, results are pretty whacky.

  • Sometimes it runs correctly for a while. However, after a few reads, bash comes in, and starts interpreting the tty1 input, instead redirecting it to java.

  • Sometimes it shows it's running, but never sends any information to the java.

  • Sometimes after receiving a kill command, the crontab restarts it without redirecting the input to java.

In the meantime, it communicates with other computers, which also send commands. Things like it's trying to update, responses, checks if everything is still running, and they are redirected to the tty1 output, but these always appear correctly, even when bash is reading from the stdin.

While I actually have no use for bash (I control it from SSH), it communicates with the other computers via ttyS0 and ttyAMA0, so they should not be locked.

https://unix.stackexchange.com/questions/372445/run-java-console-app-reading-standard-input-after-boot

I also tried running java as a service, but in that case, it constantly read 'null's from the input, making it impossible to extract any useful data from it.

Now I'm thinking it should be 0< /dev/tty1 instead, but other tutorials and questions are damn vague about input redirecting. There are tons about redirecting output and input from file, but nothing about input from tty...

Got a solution, yay! Start a process on a different tty

  • what init system does this host use? it may be better to use that to attach something to a tty then firing off cron jobs... – thrig Feb 19 '18 at 16:02
  • 2
    you're taking input directly from a barcode reader and redirecting it into a java program running as root on a kiosk device with direct access by the general public, without any validation or sanitising of the data? cool....where's my barcode printing program? General tip: don't run things as root unless they really need to be run as root...and even if you think they need root, they probably don't and you should explore all other options for not running as root first. – cas Feb 20 '18 at 3:18
  • @thrig: systemd. As I mentioned, I already did that, and it was constantly reading null. – kry Feb 20 '18 at 7:59
  • @cas: VoV. Intentionally mentioned parts were cut off. Have a cookie. – kry Feb 20 '18 at 8:00
  • right, i get it. you'd rather indulge in snark than risk getting any help. ok. bye then. – cas Feb 20 '18 at 8:04

Your Answer

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

Browse other questions tagged or ask your own question.