A
shell script that checks the status of three specified processes every hour and sends an email to three different email IDs with a summary of the processes’ status (whether they are running or stopped):
Scripts can make your work easy. Implement it now
#!/bin/bash
# Processes to monitor
processes=(“process1” “process2” “process3”)
# Email addresses
email1=”email1@example.com”
email2=”email2@example.com”
email3=”email3@example.com”
# Function to check process status
check_process_status() {
process_name=”$1″
if ps -ef | grep “$process_name” | grep -v grep > /dev/null; then
echo “[$process_name] RUNNING”
else
echo “[$process_name] STOPPED”
fi
}
# Function to send email with process status summary
send_email() {
summary=”$1″
echo -e “Subject: Process Status Summary\n\n$summary” | sendmail “$email1,$email2,$email3”
}
# Loop to check process status every hour
while true; do
# Get current time
current_time=$(date “+%Y-%m-%d %H:%M:%S”)
echo “[$current_time] Checking Process Status:”
# Check status for each process
status_summary=””
for process_name in “${processes[@]}”; do
status=$(check_process_status “$process_name”)
status_summary+=”\n$status”
echo “$status”
done
# Send email with process status summary
send_email “$status_summary”
# Wait for an hour before checking again
sleep 3600
done