Cover V10, I04
Article
Listing 1

apr2001.tar


Listing 1 chk-sshd.pl -- Perl script that starts sshd if it's not currently running

  01:  #!/usr/bin/perl -w
  02:
  03:  ###########################################
  04:  ## this is the process we are looking for
  05:  ## (your server may be different)
  06:  ###########################################
  07:  $ps_entry  = "/usr/local/sbin/sshd";
  08:
  09:  ###########################################
  10:  ## this is the path to sshd, depends on
  11:  ## your setup, it might be different.
  12:  ###########################################
  13:  $sshd_path = "/usr/local/sbin/sshd";
  14:
  15:  ###########################################
  16:  ## use the ps command to get a list of
  17:  ## the processes currently running
  18:  ###########################################
  19:  @processes = `ps ax`;
  20:
  21:  $n = @processes;
  22:  $is_running = 0;
  23:
  24:  for ($i=0; $i<$n; $i++) {
  25:    if ($processes[$i] =~ /$ps_entry/) {
  26:      $is_running = 1;
  27:    }
  28:  }
  29:
  30:  ###########################################
  31:  ## if sshd is not currently running, then
  32:  ## start it now.
  33:  ###########################################
  34:  if (not $is_running) {
  35:    `$sshd_path &`;
  36:  }