Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-14-2005, 04:30 AM
|
#1
|
|
Member
Registered: Oct 2003
Location: Linux world
Distribution: redhat,mandy,centos,debian,ubuntu
Posts: 209
Rep:
|
perl/bash script to monitor all processes running in my machine
hi
i would like to monitor the processes running in my linux machine,
ps ax >> day1.txt
ps ax>> day2.txt
diff day1.txt day2.txt
from here if there is any new process, there should be a mail forwarded to my mail id,
i am very much new to this perl script, if anyone has similar kind of perl script please help me
thanks
|
|
|
|
07-14-2005, 02:49 PM
|
#2
|
|
Senior Member
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197
Rep:
|
You can't do this with diff. The output of ps ax is going to change daily regardless of if there are new processes or not. The CPU time, state information and so forth are going to change constantly.
Having said that, you could do the whole thing in sh with a combination of ps, awk, sort, diff and mail. If you'd like an example, reply back.
|
|
|
|
07-14-2005, 04:29 PM
|
#3
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
Quote:
Originally posted by sigsegv
You can't do this with diff. The output of ps ax is going to change daily regardless of if there are new processes or not. The CPU time, state information and so forth are going to change constantly.
Having said that, you could do the whole thing in sh with a combination of ps, awk, sort, diff and mail. If you'd like an example, reply back.
|
Or just setup a monitoring application like nagios.. 
|
|
|
|
07-18-2005, 01:57 AM
|
#4
|
|
Member
Registered: Oct 2003
Location: Linux world
Distribution: redhat,mandy,centos,debian,ubuntu
Posts: 209
Original Poster
Rep:
|
thanks sigsegv
I would like to have an example?
will you please guide me?
|
|
|
|
07-19-2005, 02:09 PM
|
#5
|
|
Senior Member
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197
Rep:
|
Something like this should do the trick:
Code:
#!/bin/sh
# Set this to your email
EMAIL=you@yourdomain.com
# If this has already been run before, /root/pslist.tmp should be there from the last run
# If it is, it needs to be in /root/pslist.txt so that we can compare the two
if [ -f /root/pslist.tmp ]; then
mv /root/pslist.tmp /root/pslist.txt
fi
# Get the process list and sort them alphabetically
ps ax | awk '{print $1"\n"}' | sort > /root/pslist.tmp
# diff with the process list from the last time we ran
diff /root/pslist.txt /root/pslist.tmp >> /dev/null
# If this conditional is true, the files are different. Let's mail the report
if [ $? ]; then
DIFF=`diff /root/pslist.txt /root/pslist.tmp`
echo "The processes between this run and the last run differ. You can see the full list at /root/pslist.txt and /root/pslist.tmp. $DIFF" | mail $EMAIL
fi
This isn't tested at all, but I think it'll work, and if not it shouldn't take much to make it work.
Last edited by sigsegv; 07-19-2005 at 02:11 PM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:10 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|