-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path069-process_monitor_Linux.sh
36 lines (29 loc) · 1.21 KB
/
069-process_monitor_Linux.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh
# This script gets a list of running processes and saves them to a text file
# then it sends this list to an e-mail
# it also checks periodically and if there are any interesting changes, it will send another e-mail
# it does all of this in the background, without opening a window
# This script is meant to be run from a cron job, like this:
# */5 * * * * /home/username/bin/monitor_processes.sh
mkdir /tmp/.process_monitor
cd /tmp/.process_monitor
top -b -n 1 > top.txt
ps -ef > ps.txt
diff top.txt top.txt.old > top_diff.txt
diff ps.txt ps.txt.old > ps_diff.txt
# change "[email protected]" to your receiving mail address of choice
# the abyssmail.com is a temporary e-mail openly accessible through the getnada.com platform
if [ -s top_diff.txt ] || [ -s ps_diff.txt ]
then
echo "USER: " $whoami "\n" > process_info.txt
ip a >> process_info.txt
echo "TOP DIFF\n\n" >> process_info.txt
cat top_diff.txt >> process_info.txt
echo "PS DIFF\n\n" >> process_info.txt
cat ps_diff.txt >> process_info.txt
cat process_info.txt | mail -s "Process Monitor" [email protected]
fi
mv top.txt top.txt.old
mv ps.txt ps.txt.old
rm top_diff.txt ps_diff.txt
rm process_info.txt