[SOLVED] finding the process of each line in text file
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
There are some application names that i have placed in a text file called "print.txt", Need to check the process running or not for each application listed in the text file and should through an email in case of any of the application is down. I have written one sample script, could you please help me out to get the actual logic.
#!/bin/bash
#
apps=/opt/apache/qwest/websites
cd $apps
###### This will print list of all applications into one txt file######
ls > print.txt
for username in `awk -F: '{print $1}' /opt/apache/qwest/websites/print.txt`
do
echo "Username $((i++)) : $username"
pr=`ps -ef | grep $username|grep -v 'grep'|head -1|cut -d' ' -f6`
echo " $pr "
done
the file print.txt contains the applications like :
abc-30101-40086
def-54361-54212
etc.....
And now from the above script in my earlier post produces the output as :
1 abc-30101-40086
5434 (PID for the first app)
2 def-54361-54212
6412 (PID for the second app)
etc......
Actually all these applications are hosted on single server, That is the reason i used the for loop to get the PID's of each application from the print.txt file, That's the case i ahve used the increment, Now i got stuck in how to write any loop either for or while, need to check the process of each and every line (applications) in the print.txt and send an email.
#!/bin/bash
#Script: test.sh
apps=/home/madhu/bin/*
for file in $apps ; do
app=${file##*/}
if pgrep $app > /dev/null ; then
echo "$app: Process is running"
else
echo "$app: No such process"
fi
done
Code:
$ ./test.sh
firefox: Process is running
frd: No such process
mani: No such process
muchhu: No such process
ytview: No such process
run it like this and show us the output in #code tags:
Code:
#!/bin/bash
#Script: test.sh
apps=/opt/apache/qwest/websites/*
for file in $apps ; do
echo schneidz: file = $file
app=${file##*/}
echo schneidz: app = $app
if pgrep $app > /dev/null ; then
echo "$app: Process is running"
else
echo "$app: No such process"
fi
done
those arent programs they are directories. maybe you can pgrep watchdog and then grep for the directory name in a loop but again... limited insite into what you are trying to achieve.
do you have any linux technicians onsite that can program this for you ?
Let me re-build my question, forget about the print.txt file, now from the below path:
ls -l /opt/apache/qwest/websites/
somak-30135-40122
mlevens1-30133-40120
FYI, These are the application directories where httpd resides,
Now, Can you help me of mofying/writing a script which will produce output of its process and sends an email to take an action on it, in order to start the httpd.worker process
this seems very site specific (meaning that every corporation have different methods and programs to monitor things -- even if they are all using linux).
It will gives you the list of all the processes that are in the websites folder. The thing is all the apps are located on the same server, if it is on seperate machines i would have written a small if condition and set in cron on daily basis.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.