From 8fca547f2c87e9a2131a5f67a0f307cb46e4ddba Mon Sep 17 00:00:00 2001 From: Incrediblenoble Date: Fri, 13 Dec 2024 13:27:26 +0000 Subject: [PATCH 1/2] Created a script to monitor and log the status of a process (sshd) --- bash/process.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bash/process.sh b/bash/process.sh index 32c3d8a..65aeb8b 100644 --- a/bash/process.sh +++ b/bash/process.sh @@ -1 +1,26 @@ -#Create a script to monitor and log the status of a process (sshd) \ No newline at end of file +#Create a script to monitor and log the status of a process (sshd) +#!/bin/bash + +# Log file path +LOG_FILE="/var/log/sshd_status.log" + +# Get the current date and time +CURRENT_TIME=$(date "+%Y-%m-%d %H:%M:%S") + +# Check if sshd process is running +if ps aux | grep "[s]shd" > /dev/null; then + STATUS="running" +else + STATUS="not running" +fi + +# Log the status with a timestamp +echo "$CURRENT_TIME - sshd is $STATUS" >> $LOG_FILE + +# Optional: Alert if sshd is not running +if [ "$STATUS" == "not running" ]; then + echo "ALERT: sshd process is not running!" | mail -s "sshd Alert" admin@example.com +fi + + + From 2cd8f9ff76c23c0e1df094b8b4b7ac5b3bf3ce88 Mon Sep 17 00:00:00 2001 From: Incrediblenoble Date: Fri, 13 Dec 2024 13:48:25 +0000 Subject: [PATCH 2/2] added my mail --- bash/process.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash/process.sh b/bash/process.sh index 65aeb8b..9841597 100644 --- a/bash/process.sh +++ b/bash/process.sh @@ -1,4 +1,4 @@ -#Create a script to monitor and log the status of a process (sshd) +tu#Create a script to monitor and log the status of a process (sshd) #!/bin/bash # Log file path @@ -19,7 +19,7 @@ echo "$CURRENT_TIME - sshd is $STATUS" >> $LOG_FILE # Optional: Alert if sshd is not running if [ "$STATUS" == "not running" ]; then - echo "ALERT: sshd process is not running!" | mail -s "sshd Alert" admin@example.com + echo "ALERT: sshd process is not running!" | mail -s "sshd Alert" tumson1000000@gmail.com fi