Hi All
I am trying to write a perl script which will check some particular process is running in a machine or not. If the processes are running properly then its ok if the processes are not running then the script will start those processes and send a mail to a particular e-mail id mentioning the current status.
The problem I am facing that I have written the code for a single process but I am not able to run the code for multiple process.Another thing that I am checking the process by using PID but if I want to check the process by using process names then what to do?
I am copying the code what i have written.
#!/usr/bin/perl
use Proc::ProcessTable;
$t = new Proc::ProcessTable;
$command = '/etc/init.d/portmap start';
$pidfile = "/home/anadhikary/123.txt";
$notice = "1"; # 0=no 1=yes
$mail = 'anirban.adhikary@gmail.com';
$mail_prog = "/usr/sbin/sendmail";
open (PID, "$pidfile");
$assppid = <PID>;
close PID;
foreach $proc ( @{$t->table} )
{
$tmp = $proc->pid;
if ($assppid == $tmp)
{
$notice=0;
exit;
}
}
system ("$command");
if ($notice == 1)
{
open (MAIL, "|$mail_prog -t");
print MAIL "To: $mail\n";
print MAIL "Subject: Software need restart\n";
print MAIL "\nSoftware was restartet\n" ;
close (MAIL);
}