Created
June 19, 2023 13:56
-
-
Save earnhardt3rd/ba63220e5ef7599a3e3da7c80ef0db69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'getopts.pl'; | |
| Getopts('m:d:t'); | |
| my $MODE = uc($opt_m) || ""; | |
| my $DEBUG = $opt_d || 0; | |
| if (defined $opt_t) { my %TEST = &cleanUpProc();} | |
| 1; | |
| sub cleanUpProc { | |
| my $pMAIN = shift || ""; | |
| print " cleanUpProc($pMAIN)\n" if $DEBUG > 0; | |
| my %WINDOWS_KILL = ( | |
| ("pdm_d_mgr.exe" => ""), | |
| ("pdm_proctor_nxd.exe" => ""), | |
| ("pdm_mail_nxd.exe" => ""), | |
| ("pdm_ver_nxd.exe" => ""), | |
| ("pdm_global_nxd.exe" => ""), | |
| ("pdm_text_nxd.exe" => ""), | |
| ("pdm_tomcat_nxd.exe" => ""), | |
| ("pdm_maileater_nxd.exe" => ""), | |
| ("sslump_nxd.exe" => ""), | |
| ("sql_agent_nxd.exe" => ""), | |
| ("pdm_perl.exe" => ""), | |
| ("spel_srvr.exe" => ""), | |
| ("domsrvr.exe" => "") | |
| ); | |
| my %LINUX_KILL = ( | |
| ("pdm_tomcat_nx[d]" => ""), | |
| ("spel_srv[r]" => ""), | |
| ("spelsrv[r]" => ""), | |
| ("domsrv[r]" => ""), | |
| ("webengin[e]" => ""), | |
| ("org.apache.catalina.startup.Bootstra[p]" => ""), | |
| ("ServiceDes[k]" => "") | |
| ); | |
| if (lc($^O) =~ /win/) { | |
| if ($pMAIN ne "") { | |
| my $chkMainCmd = "tasklist /FO CSV /NH /FI \"IMAGENAME eq $pMAIN\""; | |
| my $chkMainCmdX=`$chkMainCmd 2>&1`; | |
| print " chkMainCmd:$chkMainCmd\n" if $DEBUG > 0; | |
| print " chkMainRTN:$chkMainCmdX\n" if $DEBUG > 0; | |
| if ($chkMainCmdX =~ /No tasks are running which match the specified criteria/) { | |
| print " Main Process Verified Stopped!\n"; | |
| } else { | |
| if (uc($MODE) ne "CRON") { | |
| print " ERROR! MAIN PROCESS STILL RUNNING ($pMAIN)\n"; | |
| print " Continue (y/n) [n]:"; | |
| my $wans = <STDIN>; | |
| chomp($wans); | |
| if (! $wans =~ /y|Y/) { | |
| system("pdm_status"); | |
| exit 1; | |
| } | |
| } | |
| } | |
| } | |
| print " Cleaning Up Windows Processes!\n" if $DEBUG > 0; | |
| foreach my $key(sort keys %WINDOWS_KILL) { | |
| my $winCmd = "FOR /F \"eol=; tokens=2,3* delims=, \" %i in ('tasklist /FO CSV /NH /FI \"IMAGENAME eq $key\"') do taskkill /f /PID:%i"; | |
| print " $winCmd\n" if $DEBUG > 0; | |
| my $wX = `$winCmd 2>&1`; | |
| print " $wX\n" if $DEBUG > 0; | |
| } | |
| } else { | |
| if ($pMAIN ne "") { | |
| my $chkMainCmd="ps -ef | grep $pMAIN"; | |
| my $chkMainCmdX=`$chkMainCmd 2>&1`; | |
| print " chkMainCmd:$chkMainCmd\n" if $DEBUG > 0; | |
| print " chkMainRTN:$chkMainCmdX\n" if $DEBUG > 0; | |
| if ($chkMainCmdX ne "") { | |
| if (uc($MODE) ne "CRON") { | |
| print " ERROR! MAIN PROCESS STILL RUNNING ($pMAIN)\n"; | |
| print " Continue (y/n) [n]:"; | |
| my $lans = <STDIN>; | |
| chomp($lans); | |
| if (! $lans =~ /y|Y/) { | |
| system("pdm_status"); | |
| exit 1; | |
| } | |
| } | |
| } | |
| } | |
| print " Cleaning Up Linux Processes!\n" if $DEBUG > 0; | |
| foreach my $key(sort keys %LINUX_KILL) { | |
| my $lCmd = "for pid in `/bin/ps -ef| /bin/grep $key | /bin/awk '{print \$2}'`; do /bin/kill \$pid; done"; | |
| print "$lCmd\n"; | |
| my $lX = `$lCmd`; | |
| print " $lX\n" if $DEBUG > 0; | |
| } | |
| sleep 5; | |
| my $ddict = `/opt/CA/ServiceDesk/bin/ddictbuild /opt/CA/ServiceDesk/site/ddict.sch`; | |
| print " $ddict\n" if $DEBUG > 0; | |
| sleep 3; | |
| my $ipc=`/opt/CA/ServiceDesk/bin/pdm_ipcclean -a`; | |
| print " $ipc\n" if $DEBUG > 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment