LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 11:29 AM   #16
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153

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, 11:52 AM   #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, 11:59 AM   #18
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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, 12: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, 12:43 PM   #20
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^ can you edit this and put it in [code] tags please.
 
Old 08-28-2014, 12: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, 12:52 PM   #22
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
what does
Code:
which mailx
produce ?
 
Old 08-28-2014, 12: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 12:59 PM.
 
Old 08-28-2014, 06:10 PM   #24
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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

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


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:55 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