home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / sokwatch.zip / sockwatch.cmd < prev   
OS/2 REXX Batch file  |  2002-01-30  |  1KB  |  50 lines

  1. /* Socket watching */
  2.  
  3. delay = 300 /* i.e. run every 5 minutes */
  4.  
  5. Call rxfuncadd 'SysLoadFuncs', 'REXXUTIL', 'SYSLOADFUNCS'
  6. Call sysloadfuncs
  7.  
  8. wwwsock = 'www-http..80'
  9. wwwserver = 'call ap-start'
  10. mysqlsock = '\socket\MySQL'
  11. mysqlserver = 'call mysql-start'
  12. sshsock = '22'
  13. sshserver = 'start /min /n sshd'
  14.  
  15. call SysSleep 5
  16.  
  17. do forever
  18.  
  19.   myqueue = RxQueue('Create')
  20.   oldq = RxQueue('Set', myqueue)
  21.   'netstat -s | rxqueue' myqueue
  22.  
  23.   www = 0
  24.   ssh = 0
  25.   mysql = 0
  26.  
  27.   do queued()
  28.     parse pull line
  29.     ll = translate(line)
  30.     if word(ll,1)='LOCAL' & word(ll,2)='NAME' & word(ll,3)='=' then state='LISTEN'
  31.     else state = translate(word(line,6))
  32.     if state = 'LISTEN' | state = 'ESTABLISHED' then do
  33.       sock = word(line,4)
  34.       if sock = wwwsock then www = 1
  35.       if sock = sshsock then ssh = 1
  36.       if sock = mysqlsock then mysql = 1
  37.     end
  38.   end
  39.  
  40.   moc = RxQueue('Set', oldq)
  41.   moc = RxQueue('Delete', myqueue)
  42.  
  43.   if www = 0 then wwwserver
  44.   if ssh = 0 then sshserver
  45.   if mysql = 0 then mysqlserver
  46.  
  47.   call SysSleep delay
  48.  
  49. end
  50.