LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-14-2005, 04:30 AM   #1
pudhiyavan
Member
 
Registered: Oct 2003
Location: Linux world
Distribution: redhat,mandy,centos,debian,ubuntu
Posts: 209

Rep: Reputation: 30
Question 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
 
Old 07-14-2005, 02:49 PM   #2
sigsegv
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: Reputation: 47
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.
 
Old 07-14-2005, 04:29 PM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 270Reputation: 270Reputation: 270
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..
 
Old 07-18-2005, 01:57 AM   #4
pudhiyavan
Member
 
Registered: Oct 2003
Location: Linux world
Distribution: redhat,mandy,centos,debian,ubuntu
Posts: 209

Original Poster
Rep: Reputation: 30
thanks sigsegv

I would like to have an example?

will you please guide me?
 
Old 07-19-2005, 02:09 PM   #5
sigsegv
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: Reputation: 47
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
embedded bash in perl script paul_mat Linux - Software 3 11-21-2005 01:46 PM
Help: Perl or Bash Script help embsupafly Programming 1 08-11-2005 06:01 PM
How to get how many processes running on a Linx machine? appforce Programming 10 07-24-2005 07:22 PM
script/command to kill processes running on particular port varunbihani Linux - General 2 07-08-2005 03:35 AM
Embedding perl in bash script MikHud Programming 4 02-02-2005 06:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 12:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration