LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-28-2014, 12:29 PM   #16
mddnix
Member
 
Registered: Mar 2013
Location: Bangalore, India
Distribution: Redhat, Arch, Ubuntu
Posts: 512

Rep: Reputation: 139Reputation: 139

Those listings are folders!!!

What I understand is - there are process running which have the same name as of the folder name. In that case instead of iterating through files, do it on folders.

This will check for folders:
Code:
#!/bin/bash
#Script: test.sh

apps=/opt/apache/qwest/websites/*/

for dir in $apps ; do
  trim1=${dir%/*}
  trim2=${trim1##*/}
  if pgrep $trim2 > /dev/null ; then
    echo "$trim2: Process is running"
  else
    echo "$trim2: No such process"
 fi
done
 
Old 08-28-2014, 12:52 PM   #17
Saicharan Burle
LQ Newbie
 
Registered: Aug 2014
Posts: 24

Original Poster
Rep: Reputation: Disabled
Unhappy

Seems like pgrep command is not working, I have tried giving the command directly , it's not listing any process.

because of that getting below output all the time.

aa99036-eap-int1-30101-40086: No such process
ace-30115-40102: No such process
ace-voip-30107-40097: No such process
amrtws-int1-30109-40095: No such process
aqcb-40015: No such process
armordev1-smx-30108-40094: No such process
armordev2-smx-30116-40103: No such process
 
Old 08-28-2014, 12:59 PM   #18
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,029

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
if the name of the program (not directory) is watchdog what does this yield:
Code:
ps auxw | grep somak-30135-40122/watchdog
 
Old 08-28-2014, 01:41 PM   #19
Saicharan Burle
LQ Newbie
 
Registered: Aug 2014
Posts: 24

Original Poster
Rep: Reputation: Disabled
#!/bin/bash
#
#MailList=saicharan.burle@gmail.com
Distro_server=qtdenvmdt066
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`
pr=`ps auxw | grep $username| grep -v grep | head -1| awk '{print $2}'`
echo " $pr "

if [ $pr > 0 ]
then
echo " $apps has been started successfully "
else
echo " $apps has not started Please check......." |mailx -s "Health Check for $Distro_server" saicharan.burle@gmail.com
fi
done


The command worked, I just did some changes, This is the modified script which is working now.....

Please find the output:

Username 1 : aa99036-eap-int1-30101-40086

test.sh: line 21: mailx: command not found
Username 2 : ace-30115-40102
29868
/opt/apache/qwest/websites has been started successfully
Username 3 : ace-voip-30107-40097
3478
/opt/apache/qwest/websites has been started successfully
Username 4 : amrtws-int1-30109-40095
4397
/opt/apache/qwest/websites has been started successfully
Username 5 : aqcb-40015
4774


The only thing left is mailx command
 
Old 08-28-2014, 01:43 PM   #20
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,029

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
^ can you edit this and put it in [code] tags please.
 
Old 08-28-2014, 01:45 PM   #21
Saicharan Burle
LQ Newbie
 
Registered: Aug 2014
Posts: 24

Original Poster
Rep: Reputation: Disabled
What to edit exactly?
 
Old 08-28-2014, 01:52 PM   #22
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,029

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
what does
Code:
which mailx
produce ?
 
Old 08-28-2014, 01:56 PM   #23
Saicharan Burle
LQ Newbie
 
Registered: Aug 2014
Posts: 24

Original Poster
Rep: Reputation: Disabled
echo " $apps has not started Please check......." |mail -s "Health Check for $Distro_server" saicharan.burle@gmail.com < /dev/null

Username 1 : aa99036-eap-int1-30101-40086

Null message body; hope that's ok

Seems like mailx will not work in Bash, with mail it is working, Can you just filter the above command, I am getting an email now but the body is not displaying, moreover if you see one of the application output which is down showing as Null message body

Last edited by Saicharan Burle; 08-28-2014 at 01:59 PM.
 
Old 08-28-2014, 07:10 PM   #24
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,029

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
mailx is probably not installed.

if you don't want null input then why are you redirecting /dev/null to the mail command ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Help with awk finding line number and deleteing text puth Programming 1 02-24-2010 12:29 PM
help with c program to read each line from text file, split line , process and output gkoumantaris Programming 12 07-01-2008 01:38 PM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 09:22 AM


All times are GMT -5. The time now is 07:33 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration