TIP: Click on subject to list as thread! ANSI
echo: cbm
to: 6502ENHANCED@GMAIL.COM
from: JANNE JOHANSSON
date: 2017-06-29 10:41:00
subject: Using tcpser on a Pi for

On 2017-06-28 05:26, 6502enhanced@gmail.com : All wrote:
> Am Montag, 26. Juni 2017 20:45:48 UTC+2 schrieb Dropnine:

> OK, I've done the following:
>
> - wrote "tcpser -s 2400 -d /dev/ttyUSB0 -p 6502 -ts &"
> - then ps -A
> - and ps -x | grep -v grep |grep -c "tcpser"
>

I didn't want to turn this into a "my oneliner is better than yours",
but unix shells makes this rather simple:

pgrep tcpser || tcpser -s 2400 -d /dev/ttyUSB0 -p 6502 -ts &

which basically means,

"if tcpser is not found among the list of running programs, run it again"

or even more verbose explanation:

pgrep 
will return an "ok" exit code if found, and error code if not.

the || double-pipe means "if error, run stuff behind ||, else skip"
which is the opposite of the more common && operator which means
"run the stuff behind && only if previous command went well" mostly
used to make sure each step of a long series of commands worked and not
continue otherwise.

So, all in all, pgrep for the program, if not found, pgrep will signal
that it failed its mission to find tcpser in the process list, and runs
the command after, which incidentally is the full tcpser command again.

Since pgrep is rather cheap to execute, you could just run this as often
as you like, even in a loop like this:

while sleep 1
do
   pgrep tcpser || tcpser ...
done

If this is in rc.local and you want that script to exit, use shell ()
feature (called 'subshell') and place that one into the backgroup with a
single &.

( while sleep 1
  do
     pgrep ...|| ..
  done
) &

and you have yourself a daemon style script that checks for tcpser every
second (every sleep X interval) and restarts it asap if its gone.

---
* Origin: *** nntp://fidonews.mine.nu *** Finland *** (2:221/6.0)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.