/
usr
/
local
/
lp
/
apps
/
malre
/
scripts
/
File Upload :
llllll
Current File: //usr/local/lp/apps/malre/scripts/stat_watch_job.sh
#! /bin/bash ### Modify the stat watch job such that it sends emails to salesforce ### Find out where we are d_PROGRAM='/usr/local/lp/apps/malre' f_PROGRAM='/usr/local/lp/apps/malre/malre.sh' d_WORKING="$d_PROGRAM"/.malre function fn_get_direc { ### Given the identifier for a directive, get the value of that directive if [[ -n "$f_JOB" ]]; then local v_DIREC_IDENT="$1" v_DIREC="$( grep -E "^\s*$v_DIREC_IDENT" "$f_JOB" | tail -n1 | sed "s/^[[:blank:]]*$v_DIREC_IDENT[[:blank:]]*//;s/[[:blank:]]*$//" )" else v_DIREC= fi } source "$d_PROGRAM"/source_includes/basic.shf if [[ "$1" == "--create" ]]; then ### Make sure that we're in a malre job if [[ -n "$v_MALWARE_REMEDIATION_IDENT" && $( echo "$v_MALWARE_REMEDIATION_IDENT" | egrep -c "^[A-Za-z0-9_]{12}-[A-Za-z0-9]{14}" ) -gt 0 ]]; then v_JIDENT="${v_MALWARE_REMEDIATION_IDENT%%-*}" v_AIDENT="${v_MALWARE_REMEDIATION_IDENT##*-}" d_JOB="$d_WORKING"/jobs/"$v_JIDENT" if [[ -z "$v_JIDENT" || ! -d "$d_JOB" || ! -f "$d_JOB"/account ]]; then echo "This command cannot be run outside of a Malre job" exit 1 fi echo -n "$( date +%s )" > "$d_JOB"/touch else echo "This command cannot be run outside of a Malre job" exit 1 fi read -ep "Ticket ID: " v_TICKET_ID read -ep "Full Path to Job File: " f_JOB echo if [[ -n "$f_JOB" && -f "$f_JOB" && -n "$v_TICKET_ID" && ( "${#v_TICKET_ID}" -eq 15 || "${#v_TICKET_ID}" -eq 18 ) ]]; then ### Get the 15 character Ticket ID v_TICKET_ID="${v_TICKET_ID:0:15}" v_TICKET="$( cat "$d_JOB"/tickets 2> /dev/null | head -n1 | cut -d ":" -f1 )" ### Find out what the name of the file we need to modify is fn_get_direc "Name"; v_NAME="$v_DIREC" if [[ -z "$v_NAME" ]]; then echo "Cannot find name in Job file. Exiting" exit fi fn_file_path "$f_JOB"; v_DIR="$s_DIR" fn_get_direc "Working-dir"; v_DIR2="$v_DIREC" if [[ -n "$v_DIR2" && -d "$v_DIR2" ]]; then v_DIR="$v_DIR2" fi ### Add the ticket reference to the Stat Watch Email echo "ref:_00D30pmDy._""$v_TICKET_ID"":ref" > "$s_DIR"/"$v_NAME"_message_end.txt ### Add a directive to run a script echo "Run-pre-e $d_PROGRAM/scripts/stat_watch_job.sh --job-id $v_JIDENT" >> "$f_JOB" echo "Email support@liquidweb.com" >> "$f_JOB" if [[ -n "$v_TICKET" ]]; then echo "### Original Ticket: $v_TICKET" >> "$f_JOB" fi ### Tell the user that the task has been done echo "Emails from the Stat Watch job will now go to the ticket" fi elif [[ "$1" == "--job-id" && -f "$f_EMAIL" ]]; then v_JIDENT="$2" d_JOB="$d_WORKING"/jobs/"$v_JIDENT" if [[ -d "$d_JOB" ]]; then v_LAST_TOUCH="$( cat "$d_JOB"/touch2 2> /dev/null )" v_TICKET="$( cat "$d_JOB"/tickets 2> /dev/null | head -n1 | cut -d ":" -f1 )" if [[ "$v_LAST_TOUCH" -lt $(( $( date --date +%s ) - $(( 86400 * 7 )) )) ]]; then ### If it's been more than seven days since the last time we ran 'dis', 'bak', 'note', or 'led' against a file, we should probably quit this job echo "----------------" > "$f_EMAIL"2 echo "The Malware Remediation job associated with ticket '$v_TICKET' has not been touched for more than seven days. It should probably be removed." >> "$f_EMAIL"2 echo "----------------" >> "$f_EMAIL"2 echo "" >> "$f_EMAIL"2 cat "$f_EMAIL" >> "$f_EMAIL"2 mv -f "$f_EMAIL"2 "$f_EMAIL" else ### Otherwise, make minor edits so that we know what other tickets to reference echo "" > "$f_EMAIL"2 echo "This ticket is in reference to the Malware Remediation job associated with ticket '$v_TICKET'." >> "$f_EMAIL"2 echo "" >> "$f_EMAIL"2 cat "$f_EMAIL" >> "$f_EMAIL"2 mv -f "$f_EMAIL"2 "$f_EMAIL" fi fi fi
Copyright ©2k19 -
Hexid
|
Tex7ure