home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.sys.cbm      Discussion about Commodore micros      53,866 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 52,008 of 53,866   
   Janne Johansson to 6502enhanced@gmail.com   
   Using tcpser on a Pi for telnet gateway    
   29 Jun 17 10:44:40   
   
   From: nospam.Janne.Johansson@f6.n221.z2.binkp.net   
      
   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.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca