rendered paste body!/bin/bash## This is a bot manager superscript.# Written by: Tres Melton (a/k/a RiverRat)# Copyright: 2007, all rights not granted, reserved# License: GNU GPL v3.0 or greater## ./manage-bots <action> [target]# x --start ; start# x --stop ; stop (signal 15)# x --restart ; restart things# x --status ; running?# x --rehash ; passthrough to...# x --reload ; reload the config files (signal -HUP)# x --kill ; passthrough to...# x --halt ; halt (signal 9)# x --connect ; passthrough to...# x --telnet ; telnet to the bot# x --interactive ; enter the program in interactive mode (-nt)# - --snoop ; tcpsnoop### To be placed in a config file later # TESTED LIVE:# start stop restart (single bot)# restart (multiple bot) # Debug levelDEBUG="${DEBUG:-3}" # Default: ActionLOCAL_DEBUG="${DEBUG}"[[ ${LOCAL_DEBUG} -ge 6 ]] && echo "DEBUG \"${DEBUG}\""[[ ${LOCAL_DEBUG} -ge 6 ]] && echo "LOCAL_DEBUG \"${LOCAL_DEBUG}\"" # CONFIGURATION ---------------------------------------------------------------# Bots (Could be resolved from the data below)ALLBOTS="RiverBot RiverBoat RiverRaft Freedom"# "Name Dir PID-file Port IP"RiverBot_record="RiverBot /home/me/.eggdrop/RiverBot /home/me/.eggdrop/RiverBot.pid 3567 192.168.0.2"RiverBoat_record="RiverBoat /home/me/.eggdrop/RiverBoat /home/me/.eggdrop/RiverBoat.pid 3456 192.168.0.2"RiverRaft_record="RiverRaft /home/me/.eggdrop/RiverRaft /home/me/.eggdrop/RiverRaft.pid 3678 192.168.0.2"Freedom_record="Freedom /home/me/.eggdrop/Freedom /home/me/.eggdrop/Freedom.pid 3789 192.168.0.2"#RP_linkbot_record="RP_linkbot /home/tres2/.eggdrop/RP_linkbot /home/tres2/.eggdrop/RP_linkbot.pid 3789 192.168.0.2" # Bots# man page key = Arraysdeclare -a BOTSBOTS[1]="${RiverBot_record}"BOTS[2]="${RiverBoat_record}"BOTS[3]="${RiverRaft_record}"BOTS[4]="${Freedom_record}"#BOTS[4]="${RP_linkbot_record}"#BOTS[?]="${}" # CONFIGURATION (END) --------------------------------------------------------- ########### # Clear globalsBot_record=""Bot_Name=""Bot_Dir=""Bot_Pid=""Bot_Pidf=""Bot_Addr=""# Set globalsINDENT=" "CURRENT_INDENT="${INDENT}"CALLEDAS="${0}"ACTION=""TARGETS=""TITLE_START="\033]0;"#TITLE_CONTENT="Hello"TITLE_END="\007" # Start of code function usage(){ echo "${CALLEDAS} [--<start|stop|status|restart|rehash|connect|list|kill|interactive>] [target(s)|ALL]" echo " --status will return 0 on success or the number of bots that failed." exit 0} function short_options(){ printf " --> Handling short option(s): %s\n" ${1}} function targets(){ # Check things first to ensure valid targets (done later. Redesign?)# TARGETS="${TARGETS} ${1}" # Set all at the same time so this won't work# TARGETS="${TARGETS} ${*}" TARGETS="${*}"} function bot_kill(){ [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Kill->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more echo "${CURRENT_INDENT}Killing $1" set_bot_details ${1} if [[ -f "${Bot_Pidf}" ]] ; then if [[ "${Bot_Pid}" == "" ]] ; then echo "${CURRENT_INDENT}${Bot_Name} Has a PID file but no PID. (Removing PID file: ${Bot_Pidf})" rm -f ${Bot_Pidf} 2> /dev/null else echo "${CURRENT_INDENT}${Bot_Name} Has a PID file. (${Bot_Pidf}) Checking for activity." ps l $Bot_Pid > /dev/null RET_VAL=$? if [[ "$RET_VAL" == "0" ]] ; then printf "%s%s appears to be running. (PID: %s) Killing.\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" CMD="kill -SIGKILL ${Bot_Pid} 2> /dev/null" echo "${CURRENT_INDENT}KILLING: ${1} with: \"${CMD}\"" eval "${CMD}" if [[ "$RET_VAL" != "0" ]] ; then echo "${CURRENT_INDENT}Failed: ${CMD}" fi else printf "%s%s not responding to signal. (PID: %s)\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" echo "${CURRENT_INDENT}Removing PID file ${Bot_Pidf} (and nothing to kill)" rm -f ${Bot_Pidf} 2> /dev/null fi fi else echo "${CURRENT_INDENT}${Bot_Name} Has no PID file. (PID file: ${Bot_Pidf}) (Skipping...)" fi CURRENT_INDENT="${CURRENT_INDENT/ /}" # Indent by two less [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Kill->>>"} function bot_stop(){ [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Stop->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more echo "${CURRENT_INDENT}Stopping $1" set_bot_details ${1} if [[ -f "${Bot_Pidf}" ]] ; then if [[ "${Bot_Pid}" == "" ]] ; then echo "${CURRENT_INDENT}${Bot_Name} Has a PID file but no PID. (Removing PID file: ${Bot_Pidf})" rm -f ${Bot_Pidf} 2> /dev/null else echo "${CURRENT_INDENT}${Bot_Name} Has a PID file. (${Bot_Pidf}) Checking for activity." ps l $Bot_Pid > /dev/null RET_VAL=$? if [[ "$RET_VAL" == "0" ]] ; then printf "%s%s appears to be running. (PID: %s) Stopping.\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" CMD="kill -SIGTERM ${Bot_Pid} 2> /dev/null" echo "${CURRENT_INDENT}STOPPING: ${1} with: \"${CMD}\"" eval "${CMD}" if [[ "$RET_VAL" != "0" ]] ; then echo "${CURRENT_INDENT}Failed: ${CMD}" fi rm -f ${Bot_Pidf} 2> /dev/null else printf "%s%s not responding to signal. (PID: %s)\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" echo "${CURRENT_INDENT}Removing PID file ${Bot_Pidf} (and nothing to kill)" rm -f ${Bot_Pidf} 2> /dev/null fi fi else echo "${CURRENT_INDENT}${Bot_Name} Has no PID file. (PID file: ${Bot_Pidf}) (Skipping...)" fi CURRENT_INDENT="${CURRENT_INDENT/ /}" # Indent by two less [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Stop->>>"} function bot_rehash(){ [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Rehash->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more echo "${CURRENT_INDENT}Rehashing $1" set_bot_details ${1} if [[ -f "${Bot_Pidf}" ]] ; then if [[ "${Bot_Pid}" == "" ]] ; then echo "${CURRENT_INDENT}${Bot_Name} Has a PID file (${Bot_Pidf}) but no PID. (skipping...)" else echo "${CURRENT_INDENT}${Bot_Name} Has a PID file. (${Bot_Pidf}) Sending HUP (causes a reload/rehash)." ps l $Bot_Pid > /dev/null RET_VAL=$? if [[ "$RET_VAL" == "0" ]] ; then printf "%s%s appears to be running. (PID: %s) Rehashing.\n" "${CURRENT_INDENT}" "${Bot_Name}" "${Bot_Pid}" CMD="kill -SIGHUP ${Bot_Pid} 2> /dev/null" echo "${CURRENT_INDENT}REHASHING: ${Bot_Name} with: \"${CMD}\"" eval "${CMD}" if [[ "$RET_VAL" != "0" ]] ; then echo "${CURRENT_INDENT}Failed: ${CMD}" fi else printf "%s%s not responding to signal. (PID: %s) Failed to reload.\n" "${CURRENT_INDENT}" "${Bot_Name}" "${Bot_Pid}" fi fi else echo "${CURRENT_INDENT}${Bot_Name} Has no PID file. (PID file: ${Bot_Pidf}) (Skipping...)" fi CURRENT_INDENT="${CURRENT_INDENT/ /}" # Indent by two less [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Rehash->>>"} function bot_start(){ [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Start->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more echo "${CURRENT_INDENT}Starting $1" set_bot_details ${1} if [[ -f "${Bot_Pidf}" ]] ; then echo "${CURRENT_INDENT}${Bot_Name} Has a PID file. (${Bot_Pidf}) Checking for activity." ps l $Bot_Pid > /dev/null RET_VAL=$? if [[ "$RET_VAL" == "0" ]] ; then printf "%s%s appears to be running. (PID: %s) Skipping.\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" CURRENT_INDENT="${CURRENT_INDENT/ /}" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Start->>>" return else printf "%s%s not responding to signal. (PID: %s)\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" echo "${CURRENT_INDENT}Removing PID file ${Bot_Pidf}" rm -f ${Bot_Pidf} 2> /dev/null fi fi CMD="" CMD="${CMD}cd ${Bot_Dir}" CMD="${CMD};${Bot_Dir}/eggdrop ${Bot_Dir}/${Bot_Name}.conf" CMD="${CMD};cd - > /dev/null" echo "${CURRENT_INDENT}STARTING: ${1} with: \"${CMD}\"" eval "${CMD}" CURRENT_INDENT="${CURRENT_INDENT/ /}" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Start->>>"} function bot_interactive(){ [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Interactive->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more echo "${CURRENT_INDENT}Starting interactively $1" set_bot_details ${1} if [[ -f "${Bot_Pidf}" ]] ; then echo "${CURRENT_INDENT}${Bot_Name} Has a PID file. (${Bot_Pidf}) Checking for activity." ps l $Bot_Pid > /dev/null RET_VAL=$? if [[ "$RET_VAL" == "0" ]] ; then printf "%s%s appears to be running. (PID: %s) Skipping.\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" CURRENT_INDENT="${CURRENT_INDENT/ /}" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Interactive->>>" return else printf "%s%s not responding to signal. (PID: %s)\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" echo "${CURRENT_INDENT}Removing PID file ${Bot_Pidf}" rm -f ${Bot_Pidf} 2> /dev/null fi fi CMD="" CMD="${CMD}cd ${Bot_Dir}" CMD="${CMD};${Bot_Dir}/eggdrop -nt ${Bot_Dir}/${Bot_Name}.conf" CMD="${CMD};cd - > /dev/null" echo "${CURRENT_INDENT}STARTING: ${1} (INTERACTIVELY) with: \"${CMD}\"" echo "${CURRENT_INDENT} ^C to exit." echo -ne "\033]0;Started ${Bot_Name} interactively\007" # Use the title bar to indicate the bot connected to eval "${CMD}" CURRENT_INDENT="${CURRENT_INDENT/ /}" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Interactive->>>"} # RESTARTfunction bot_restart(){ local SLEEP_TIME="3" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Restart->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more set_bot_details ${1} CMD="" bot_stop "${1}" echo "${CURRENT_INDENT}Sleeping for ${SLEEP_TIME} seconds." sleep $SLEEP_TIME bot_start "${1}" return 0} function bot_connect(){ [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Connect->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more set_bot_details ${1} if [[ ! -f "${Bot_Pidf}" ]] ; then echo "${CURRENT_INDENT}${Bot_Name} doesn't have a PID file." echo "${CURRENT_INDENT}Trying anyway." else ps l $Bot_Pid > /dev/null RET_VAL=$? if [[ "$RET_VAL" != "0" ]] ; then printf "%s%s not responding to signal. (PID: %s)\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" echo "${CURRENT_INDENT}Trying anyway." fi fi CMD="telnet $Bot_Addr $Bot_Port" printf "${CURRENT_INDENT}Connecting to %s on port %s with \"%s\"\n" "${Bot_Name}" "$Bot_Port" "${CMD}" echo echo -ne "\033]0;Connected to ${Bot_Name}\007" # Use the title bar to indicate the bot connected to eval "${CMD}" CURRENT_INDENT="${CURRENT_INDENT/ /}" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Connect->>>"} function bot_status(){ [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Status->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more set_bot_details ${1} if [[ ! -f "${Bot_Pidf}" ]] ; then echo "${CURRENT_INDENT}${Bot_Name} doesn't have a PID file." CURRENT_INDENT="${CURRENT_INDENT/ /}" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Status->>>" return fi ps l $Bot_Pid > /dev/null RET_VAL=$? if [[ "$RET_VAL" != "0" ]] ; then printf "%s%s not responding to signal. (PID: %s)\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" else printf "%s%s appears to be running. (PID: %s)\n" "${CURRENT_INDENT}" "${1}" "${Bot_Pid}" HEADER="$(ps l $Bot_Pid|head -n 1)" OUTPUT="$(ps l $Bot_Pid|tail -n 1)" # OUTPUT="$(ps l $PID|tail -n 1)" # OUTPUT="$(ps l $PID|tail -n 1;return ${PIPESTATUS[0]})" <-- More likely the solution # RET_VAL=${PIPESTATUS[0]} printf "%s %s\n" "${CURRENT_INDENT}" "$HEADER" printf "%s ps: %s\n" "${CURRENT_INDENT}" "$OUTPUT" fi CURRENT_INDENT="${CURRENT_INDENT/ /}" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Status->>>" return $RET_VAL} function bot_snoop(){ echo " Complicated so instructions for now:" echo " sudo lsof -i|grep \$SERVER|grep eggdrop" echo " And save for later: PORT=local port IP=server address" echo " nslookup \$SERVER" echo " tcpflow -i eth1 -c host <IP> and port <PORT>" echo ""} function set_bot_details(){ [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Set->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more [[ ${LOCAL_DEBUG} -ge 4 ]] && echo "${CURRENT_INDENT}Setting bot details for: ${1}" index1=1 for tempbot in ${ALLBOTS} ; do Bot_record="${BOTS[$index1]}"# echo "${CURRENT_INDENT}Checking Bot: $tempbot"# echo "${CURRENT_INDENT}Bot_record_name: ${Bot_record}" # All# echo "${CURRENT_INDENT}Bot_record_name: ${Bot_record%% *}" # The name# echo "${CURRENT_INDENT}Bot_record_name: ${Bot_record#* }" # The rest# echo "${CURRENT_INDENT}${1} ${tempbot} ${Bot_record%% *}" if [[ "${1}" != "${Bot_record%% *}" ]] ; then let index1++ continue # NO match fi index2=0 for field in ${Bot_record} ; do [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "${CURRENT_INDENT}field = $field" # There has to be a better way to do this (see above) case $index2 in 0) [[ ${LOCAL_DEBUG} -ge 8 ]] && echo "${CURRENT_INDENT}name = $field" Bot_Name="$field" ;; 1) [[ ${LOCAL_DEBUG} -ge 8 ]] && echo "${CURRENT_INDENT}dir = $field" Bot_Dir="$field" ;; 2) [[ ${LOCAL_DEBUG} -ge 8 ]] && echo "${CURRENT_INDENT}pidf = $field" Bot_Pidf="$field" if [[ -r "${Bot_Pidf}" ]] ; then Bot_Pid="$(< ${Bot_Pidf})" else Bot_Pid="" fi # Check for error (shouldn't need to with the -r now) ;; 3) [[ ${LOCAL_DEBUG} -ge 8 ]] && echo "${CURRENT_INDENT}port = $field" Bot_Port="$field" ;; 4) [[ ${LOCAL_DEBUG} -ge 8 ]] && echo "${CURRENT_INDENT}Addr = $field" Bot_Addr="$field" ;; *) echo "Error: Big time" ;; esac let index2++ done break let index1++ done CURRENT_INDENT="${CURRENT_INDENT/ /}" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Set->>>"} function dump_bot_details(){ [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-Dump->>>" CURRENT_INDENT="${CURRENT_INDENT}${INDENT}" # Indent by two more # Everything should be assigned globally w/ set_bot_details echo "Dumping bot details for: $1" echo "${CURRENT_INDENT}Bot_record: $Bot_record" echo "${CURRENT_INDENT}Bot_Name: $Bot_Name" echo "${CURRENT_INDENT}Bot_Dir: $Bot_Dir" echo "${CURRENT_INDENT}Bot_Pid: $Bot_Pid" echo "${CURRENT_INDENT}Bot_Pidf: $Bot_Pidf" echo "${CURRENT_INDENT}Bot_Port: $Bot_Port" echo "${CURRENT_INDENT}Bot_Addr: $Bot_Addr" CURRENT_INDENT="${CURRENT_INDENT/ /}" [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "${CURRENT_INDENT}<<<-/Dump->>>"} # Start of execution. main() [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "========================================================="[[ ${LOCAL_DEBUG} -ge 9 ]] && printf "\$CALLEDAS: %s\n" $CALLEDAS CURRENT_INDENT="${INDENT}"while [[ 1 ]] ; do CURRENT="${1}" shift case ${CURRENT} in # ensure that we are not resetting the ACTION variable --connect|--telnet) [[ ${LOCAL_DEBUG} -ge 6 ]] && printf "${CURRENT_INDENT}Option: connect\n" [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT} Remaining: %s\n" "${*}" if [[ "${ACTION}" != "" ]] ; then echo "Resetting the action" usage fi ACTION="CONNECT" ;; --snoop) [[ ${LOCAL_DEBUG} -ge 6 ]] && printf "${CURRENT_INDENT}Option: snoop\n" [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT} Remaining: %s\n" "${*}" if [[ "${ACTION}" != "" ]] ; then echo "Resetting the action" usage fi ACTION="SNOOP" ;; --stop) [[ ${LOCAL_DEBUG} -ge 6 ]] && printf "${CURRENT_INDENT}Option: stop\n" [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT} Remaining: %s\n" "${*}" if [[ "${ACTION}" != "" ]] ; then echo "Resetting the action" usage fi ACTION="STOP" ;; --kill|--halt) [[ ${LOCAL_DEBUG} -ge 6 ]] && printf "${CURRENT_INDENT}Option: kill\n" [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT} Remaining: %s\n" "${*}" if [[ "${ACTION}" != "" ]] ; then echo "Resetting the action" usage fi ACTION="KILL" ;; --start) [[ ${LOCAL_DEBUG} -ge 6 ]] && printf "${CURRENT_INDENT}Option: start\n" [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT} Remaining: %s\n" "${*}" if [[ "${ACTION}" != "" ]] ; then echo "Resetting the action" usage fi ACTION="START" ;; --status) [[ ${LOCAL_DEBUG} -ge 6 ]] && printf "${CURRENT_INDENT}Option: status\n" [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT} Remaining: %s\n" "${*}" if [[ "${ACTION}" != "" ]] ; then echo "Resetting the action" usage fi ACTION="STATUS" ;; --rehash|--reload) [[ ${LOCAL_DEBUG} -ge 6 ]] && printf "${CURRENT_INDENT}Option: rehash\n" [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT} Remaining: %s\n" "${*}" if [[ "${ACTION}" != "" ]] ; then echo "Resetting the action" usage fi ACTION="REHASH" ;; --restart) [[ ${LOCAL_DEBUG} -ge 6 ]] && printf "${CURRENT_INDENT}Option: restart\n" [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT} Remaining: %s\n" "${*}" if [[ "${ACTION}" != "" ]] ; then echo "Resetting the action" usage fi ACTION="RESTART" ;; --interactive) [[ ${LOCAL_DEBUG} -ge 6 ]] && printf "${CURRENT_INDENT}Option: restart\n" [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT} Remaining: %s\n" "${*}" if [[ "${ACTION}" != "" ]] ; then echo "Resetting the action" usage fi ACTION="INTERACTIVE" ;; --list) echo "Configured bots: ${ALLBOTS}" exit 0 ;; --help|-h) usage ;; --*) echo "${CURRENT_INDENT}Unknown option: ${CURRENT}" usage ;; -*) short_options ${CURRENT} ;; *) targets ${CURRENT} ${*} break ;; esac if [[ ${1} == "" ]] ; then [[ ${LOCAL_DEBUG} -ge 7 ]] && printf "${CURRENT_INDENT}Done: \n" break else [[ ${LOCAL_DEBUG} -ge 8 ]] && printf "${CURRENT_INDENT}Finished with: ${CURRENT_INDENT}${CURRENT}\n" fidone [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "ALLBOTS: $ALLBOTS"[[ ${LOCAL_DEBUG} -ge 9 ]] && echo "TARGETS: ${TARGETS}"[[ ${LOCAL_DEBUG} -ge 9 ]] && echo "=========================================================" # At this point the command line should be entirely interpreted# Continuing # Ensure an action, default to "status" if necessaryif [[ "$ACTION" == "" ]] ; then echo "No action, defaulting to STATUS." ACTION="STATUS"else [[ ${LOCAL_DEBUG} -ge 8 ]] && echo "Good"fi # Expand ALL to all the botsif [[ "${TARGETS}" == "ALL" ]] ; then echo "Handling all bots: ${ALLBOTS}" TARGETS=${ALLBOTS}else if [[ "${TARGETS}" == "" ]] ; then echo "No targets." if [[ "$ACTION" == "STATUS" ]] ; then TARGETS=${ALLBOTS} else echo "Only defaults to 'ALL' bots for the 'status' action." usage fi else echo "Handling specified bot(s): ${TARGETS}" fifi # Filter multiple bots from actions that can only handle one botif [[ "$ACTION" == "CONNECT" || "$ACTION" == "SNOOP" || "$ACTION" == "INTERACTIVE" ]] ; then if [[ "${TARGETS#* }" != "${TARGETS}" ]] ; then echo "Can't $ACTION to more than one bot. (${TARGETS})" exit 1 else [[ ${LOCAL_DEBUG} -ge 6 ]] && echo "$ACTION for a single bot. (${TARGETS})" fifi # Check targets for validityfor temp in ${TARGETS} ; do [[ ${LOCAL_DEBUG} -ge 7 ]] && echo "Checking: $temp" isbot="n" for tempbot in ${ALLBOTS} ; do [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "Comparing: \"${temp}\" \"${tempbot}\"" if [[ "$temp" == "$tempbot" ]] ; then [[ ${LOCAL_DEBUG} -ge 6 ]] && echo "valid bot: $temp" isbot="y" break fi done if [[ "$isbot" == "n" ]] ; then echo "$temp is not configured as a valid bot." echo "Configured bots: ${ALLBOTS}" usage fidone # Process the bots# --snoop ; tcpsnoop# --interactive ; enter the program in interactive mode (-nt)STATUS_RETURN="0"for tempbot in ${TARGETS} ; do [[ ${LOCAL_DEBUG} -ge 6 ]] && echo "Acting on: $tempbot with ${ACTION}" # if kill (-9) then clean up the pid file # if connect then make sure only one target and is running [[ ${LOCAL_DEBUG} -ge 5 ]] && echo "Processing the bot: $tempbot" case ${ACTION} in "CONNECT") [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "connect $tempbot" bot_connect ${tempbot} ;; "STOP") [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "stop $tempbot" bot_stop ${tempbot} ;; "START") [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "start $tempbot" bot_start ${tempbot} ;; "RESTART") [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "restart $tempbot" bot_restart ${tempbot} ;; "REHASH") [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "rehash $tempbot" bot_rehash ${tempbot} ;; "STATUS") [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "status $tempbot" bot_status ${tempbot} RET_VAL=$? if [[ "$RET_VAL" != "0" ]] ; then let STATUS_RETURN++ fi ;; "KILL") [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "kill $tempbot" bot_kill ${tempbot} ;; "SNOOP") [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "snoop $tempbot" echo "SNOOPing" bot_snoop ${tempbot} ;; "INTERACTIVE") [[ ${LOCAL_DEBUG} -ge 9 ]] && echo "interactive $tempbot" bot_interactive ${tempbot} ;; *) echo "Unknown action. This is a bad thing." ;; esacdoneechoecho "That's all folks"exit $STATUS_RETURN