#!/usr/bin/ksh #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>># #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>># #<<<<<<<<<<<<<+-----------------------------------+>>>>>>>>>>>>>># #<<<<<<<<<<<<<| Process List Script |>>>>>>>>>>>>>># #<<<<<<<<<<<<<| Compaq : Premson P. R. |>>>>>>>>>>>>>># #<<<<<<<<<<<<<|-----------------------------------|>>>>>>>>>>>>>># #<<<<<<<<<<<<<| Created on: 16-06-2002 |>>>>>>>>>>>>>># #<<<<<<<<<<<<<+-----------------------------------+>>>>>>>>>>>>>># #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>># #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>># # # A Menu driven program for killing only specific processes # clear ECHO=print MON=`date +%h` DAY=`date +%0d` DC=`echo $DAY | wc -c | awk '{print $1}'` # DAY Determination if [ "$DC" = "2" ] then GRP1="$MON $DAY" else GRP1="$MON $DAY" fi # DAY_1 Determination DAY_1=`expr $DAY - 1` DC1=`echo $DAY_1 | wc -c | awk '{print $1}'` if [ "$DC1" = "2" ] then GRP2="$MON $DAY_1" else GRP2="$MON $DAY_1" fi function main_affirm { typeset answer typeset question=$1 typeset default=$2 case "${default}" in [yY]*) question="${question} ([y]/n)" ;; [nN]*) question="${question} (y/[n])" ;; *) question="${question} (y/n)" esac while : do ${ECHO} read -r "answer?${question} ? " || return 1 case ${answer} in [yY]*) listing if [ "$?" = "0" ] then list_com_conf del_affirm " Continue For Killing CDCI User Id Process Which are Listed Above" "n" else list_incom_conf fi return 0 ;; [nN]*) return 1 ;; "") case "${default}" in [yY]*) listing if [ "$?" = "0" ] then list_com_conf del_affirm " Continue Killing" "n" else list_incom_conf fi return 0 ;; [nN]*) return 1 ;; esac ;; esac ${ECHO} '\n\t\t\a Enter "y" or "n" ' done } function del_affirm { typeset answer typeset question=$1 typeset default=$2 case "${default}" in [yY]*) question="${question} ([y]/n)" ;; [nN]*) question="${question} (y/[n])" ;; *) question="${question} (y/n)" esac while : do ${ECHO} read -r "answer?${question} ? " || return 1 case ${answer} in [yY]*) delete return 0 ;; [nN]*) ${ECHO} "\n\t\t----- Process Killing Incomplete -----\n " return 1 ;; "") case "${default}" in [yY]*) delete return 0 ;; [nN]*) ${ECHO} "\n\t\t----- Process Killing Incomplete -----\n " return 1 ;; esac ;; esac ${ECHO} '\n\t\t\a Enter "y" or "n" ' done } function kill_affirm { typeset answer typeset question=$1 typeset default=$2 case "${default}" in [yY]*) question="${question} ([y]/n)" ;; [nN]*) question="${question} (y/[n])" ;; *) question="${question} (y/n)" esac while : do ${ECHO} read -r "answer?${question} ? " || return 1 case ${answer} in [yY]*) cdcikill ${ECHO} "\n\t\t----- Process Killing Complete -----\n " return 0 ;; [nN]*) ${ECHO} "\n\t\t----- Process Killing Incomplete -----\n " return 1 ;; "") case "${default}" in [yY]*) cdcikill ${ECHO} "\n\t\t----- Process Killing Complete -----\n " return 0 ;; [nN]*) ${ECHO} "\n\t\t----- Process Killing Incomplete -----\n " return 1 ;; esac ;; esac ${ECHO} '\n\t\t\a Enter "y" or "n" ' done } function listing { ${ECHO} "\n\t " ${ECHO} "\n\t\t Process Listing of CDCI Users..... " ${ECHO} "\n\t " ps aux | grep -v grep | grep -w "cdci" | tee cdcips.log } function delete { echo "\nCDCI Process Kill Operation On: [`date +%d-%h-%Y==%H:%M:%S`]" >> cdcikill.log cat cdcips.log >> cdcikill.log ${ECHO} "\n\t " ${ECHO} "\n\t Enter Process For Killing. If There Are More Than One" ${ECHO} "\t Process, Then Separate Them With Spaces.\n\t" ${ECHO} "\t Without Any Process Id Don't Press Enter Key.\n\t" read proclist ${ECHO} $proclist > proclist ${ECHO} "\n\t The Process(es) Are : $proclist \n\t" for i in `cat proclist` do grep -w "$i" cdcips.log 1>/dev/null 2>/dev/null if [ $? -ne 0 ] then ${ECHO} "\t CAUTION: Please See That Only CDCI Process Is Present !!!! \n" | tee -a cdcikill.log exit 0 fi done ${ECHO} "\n\t Are U Sure? Do U Want To Kill These CDCI Process(es) !!!\n" ps -efp "$proclist" | grep -v "TIME" kill_affirm " Continue Killing" "n" } function cdcikill { kill -9 `cat proclist` 1>>cdcikill.log 2>>cdcikill.log } function list_com_conf { ${ECHO} "\n\t " ${ECHO} "\n\t\t PS Process Listing Complete. " ${ECHO} "\n\t " } function list_incom_conf { ${ECHO} "\n\t " ${ECHO} "\n\t\t\t No CDCI Process !!!. " ${ECHO} "\n\t " } function do_introduction { ${ECHO} ${ECHO} ${ECHO} "\n\n\t PROCESS LIST INFORMATION" ${ECHO} "\t ------------------------" ${ECHO} ${ECHO} ${ECHO} "\t Here List of Process Will Display for the Specific User Id - CDCI ?" ${ECHO} "\t " ${ECHO} "\t [ Press , the default answer is assumed. ]\n" main_affirm " Continue" "y" return } if do_introduction then :; else exit 0 fi