Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 811
  • Last Modified:

What is daemon monitor + shell script

1) What is daemon monitor  ?

How to implement ?

Example :

I just want to mointor a file called abc.pl (perl file) and if it not running then i need to notify my admin via mail (using mailx) and it needs to automatically starts my process ( say it is under /home/user/abcd.pl)


2) I just want to remove the .txt file  (older than 15 days ) which is present in the /root

for that i am using this

find . -type f -mtime +15 | egrep -v -e 'Current/' -e '\.txt$'

For the above two problem i need two separate shell script file

advance thanks
kamaraj.s
find . -type f -mtime +15 | egrep -v -e 'Current/' -e '\.txt$'

Open in new window

0
Kamaraj Subramanian
Asked:
Kamaraj Subramanian
  • 5
  • 4
  • 3
2 Solutions
 
omarfaridCommented:
to remove the .txt file, run

find . -type f -mtime +15 -name "*.txt" -exec rm {} \;

to monitor a process then run

count=`/usr/bin/ps -ef | /usr/bin/grep -v grep | /usr/bin/grep abc.pl | wc -l`
if [ $count -gt 0 ]
then
      exit
else
     /usr/bin/mailx -s "Process was not running" username@domain
     /usr/bin/nohup /home/user/abcd.pl &
fi
0
 
Kamaraj SubramanianApplication Support AnalystAuthor Commented:
Hi,

i dont want to search recursively,

can you make this for /root only:
find /root -type f -mtime +15 -name "*.txt" -exec rm {} \;

and also, i am not able to find out the process in background

can you please answer for my question

thanks
kamaraj.s

 Also, for the process monitor it is not recognizing the processes:
root@server129 [~]# ps aux |grep backend
root 8326 0.0 0.1 6544 2744 ? Ss 10:46 0:00 /usr/bin/perl -w /home/mailmon/backend.pl
root 8561 0.0 0.1 4984 2812 ? Ss 10:47 0:00 /usr/bin/perl -w /home/mailmon/backend.pl
root 8799 0.0 0.1 5776 2812 ? Ss 10:48 0:00 /usr/bin/perl -w /home/mailmon/backend.pl
root 9272 0.0 0.1 6144 2812 ? Ss 10:49 0:00 /usr/bin/perl -w /home/mailmon/backend.pl
root 9525 0.0 0.1 5768 2812 ? Ss 10:50 0:00 /usr/bin/perl -w /home/mailmon/backend.pl
root 10319 0.0 0.0 6132 652 pts/1 S+ 10:51 0:00 grep backend
root@server129 [~]# count=`/bin/ps -ef | /bin/grep -v grep | /bin/grep backend.pl | wc -l`
root@server129 [~]#

Open in new window

0
 
TintinCommented:
1.

#!/bin/ksh
if [ `ps aux | grep -c "[b]ackend.pl"` -eq 0 ]
then
      echo "backend.pl stopped.  Restarting" | mailx -s "backend.pl stopped" root
     /home/mailmon/backend.pl
fi
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Kamaraj SubramanianApplication Support AnalystAuthor Commented:
Can anyone help me out

2) I just want to remove the .txt file  (older than 15 days ) which is present in the /root

Now, this is searching recursively.  I need to search only in /root directory



find /root -type f -mtime +15 -name "*.txt" -exec rm {} \;

Open in new window

0
 
omarfaridCommented:
see if find on your system supports the option -maxdepth
0
 
Kamaraj SubramanianApplication Support AnalystAuthor Commented:
Sorry, i am not getting what you are saying,

can you please explain little bit more

thanks
kamaraj.s
0
 
omarfaridCommented:
the find command has different versions. check on your system (man find) and see if your version of find command supports the mentioned option (-maxdepth). if yes then try adding -maxdepth 1 and see if it helps
0
 
TintinCommented:
AIX find does not have a -maxdepth option.  What you need to do is
find /root/* -prune  -type f -mtime +15 -name "*.txt" -exec rm {} \;

Open in new window

0
 
Kamaraj SubramanianApplication Support AnalystAuthor Commented:
I am using centos Linux version

and the find command version is

# find --version
GNU find version 4.1.20

0
 
TintinCommented:
Why did you add an AIX tag to your question if it was on Linux?

Anyway, all Linux distros have GNU find, you you can use the -maxdepth flag like

find /rooot -type f -mtime +15 -,maxdepth 1 -name "*.txt" -exec rm {} \;

or use the solution I previously gave which will run on any Unix/Linux system.
0
 
omarfaridCommented:
try

find /root -type f -mtime +15 -maxdepth 1 -name "*.txt" -exec rm {} \;
0
 
Kamaraj SubramanianApplication Support AnalystAuthor Commented:
Ok, i will check and let you know

thanks to all for your help
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now