File: //ibin/imenu
#!/usr/bin/perl
# perl menu starter kit
# author - chad townsend - 09/07/1998
# initialize
&init()
# show main menu
&main_menu();
sub init {
BEGIN { $Curses::OldCurses = 1; }
use Curses;
use perlmenu;
require "menuutil.pl";
$| = 1;
$menu_default_arrow = $menu_default_top = 0;
}
sub main_menu {
# wait for the user to select something
while (1) {
# show the menu
&menu_init(1,"Innovative Internet Solutions, Inc.");
&menu_item("Reboot Server","reboot");
&menu_item("Kill a Process with kill -9", "kill_pid_9");
&menu_item("Restart a Process with kill -HUP","kill_pid_hup");
&menu_item("(Exit)","exit");
$sel = &menu_display("",$menu_default_arrow,$menu_default_top);
if ($sel eq "exit") {
&endwin();
print "bye, bye ...\n";
exit(0);
}
elsif ($sel eq "reboot") {
&do_reboot("Reboot Server",0,0);
}
elsif ($sel eq "kill_pid_9") {
&kill_pid("Kill Process with 'kill -9'",1,"-9");
}
elsif ($sel eq "kill_pid_hup") {
&kill_pid("Kill Process with 'kill -HUP'",1,"-HUP");
}
}
}
sub do_reboot {
local($default,$maxlen,$hide) = @_;
local($sel);
# init a numbered menu with a title
&menu_init(2,"$default");
&menu_item("Yes","yes");
&menu_item("No", "no");
$sel = &menu_display_radio("","no");
if ($sel eq "%UP%") { return; }
if ($sel eq "yes") {
#system("/sbin/shutdown -t sec 0 -r");
print("\n\ncheck the script to uncomment this command -> /sbin/shutdown -t sec 0 -r\n\n");
exit(0);
}
&clear_screen();
}
sub kill_pid {
# what flag do we use on kill, -9 or -HUP
my($cmd) = $_[2];
local($sel_num);
local($menu_default_top) = 0;
local($menu_default_row,$menu_default_col) = 0;
# show processes and wait for selection
while (1) {
# init a numbered menu with title
&menu_init(1,"Processes Currently Running - $_[0]");
# add item to return to main menu.
&menu_item("(Exit)","exit");
# get the list by doing a 'ps aux'
open(PS,"ps aux |");
while(<PS>) {
# chop off the new line character
chomp;
# split 'ps aux' by white space to separate values
@proc = split(/\s+/,$_);
# add each process to the menu, $proc[1] is the PID, [1] means 2nd field.
&menu_item("$_","$proc[1]");
}
close(PS);
# get user selection.
$sel = &menu_display("",$menu_default_row,$menu_default_top,$menu_default_col);
if (($sel eq "%UP%") || ($sel eq "exit")) { return; }
# doit
system("kill $cmd $sel");
}
}