Could you please try following and let us know if this helps you.
ps -ef | grep "server" | mailx -s "servers currently which are running" xyz@abc.com <<EOF
Server 62 -> Used for User acessing.
Server 65 -> Used for Database acessing.
EOF
The "ps" output will perhaps never give you the information you want, even if you can patch the output to something similar to what you want (using grep/awk/sed/...). The problem is that "ps" lists processes and processes are indifferent in regards to their (organisational) use. That is, if you have a one mail server instance used for DB access and another for user access you will - from the ps output - not be able to differentiate between them.
But maybe you could tell us more (in plain English) about what you want to achieve and we can figure out some way to do just that. So, please elaborate about your project.
Currently, it send the list of server running in the server.
Along with that right now i need to amend description of server63 & server634.
Server 63 -> Used for User acessing.
Server 634 -> Used for Database acessing.
If I am using the below syntax the server which are currently running are not mentioned in the email.
ps -ef | grep "server" | mailx -s "servers currently which are running" xyz@abc.com <<EOF
Server 62 -> Used for User acessing.
Server 65 -> Used for Database acessing.
EOF
Output Expected as :
dba 3108 17851 0 Jul 7 ? 2:53 server63 /var/tmp/xsauthn /var/tmp/xsauthz Srv634P 27 32 33
dba 6501 17851 0 Jul 17 ? 2:20 server634 /var/tmp/xsauthn /var/tmp/xsauthz Srv634 27 32 33 3
Server 62 -> Used for User acessing.
Server 65 -> Used for Database acessing.
Could you please try following and let us know if this helps you(Not tested it though).
ps -ef | awk -vs1="\"" '/server63/ || /server634/ {A++} END{if(A==2){print "mailx -s " s1 " servers currently which are running " s1 " xyz@abc.com <<EOF" ORS "Server 62 -> Used for User acessing. ORS Server 65 -> Used for Database acessing." ORS "EOF"}'
Above will only look for processes which has contain server63 and server634 in it. If happy with the above results then you can put final command as follows too.
ps -ef | awk -vs1="\"" '/server63/ || /server634/ {A++} END{if(A==2){print "mailx -s " s1 " servers currently which are running " s1 " xyz@abc.com <<EOF" ORS "Server 62 -> Used for User acessing. ORS Server 65 -> Used for Database acessing." ORS "EOF"}' | sh
You can take it as a startup and then try to modify the solution according to your need too, hope this helps.
is missing in your syntax. I have added in the below synatax. Its executed without any error message but still the output is not delivered.
mailx -s " s1 " servers currently which are running " s1 " xyz@abc.com <<EOF" ORS "Server 62 -> Used for User acessing. ORS Server 65 -> Used for Database acessing." ORS "EOF"}}' | sh
Please check the below syntax is correct i have added { in the last
ps -ef | awk -vs1="\"" '/server63/ || /server634/ {A++} END{if(A==2){print "mailx -s " s1 " servers currently which are running " s1 " xyz@abc.com <<EOF" ORS "Server 62 -> Used for User acessing. ORS Server 65 -> Used for Database acessing." ORS "EOF"}}' | sh
Could you please let us know following points please.
1st: Which O.S you are using? It is always good practice to let us know the same.
2nd: Please try following command and let us know if you are getting any results for same.
awk -vs1=" /Srv634/ || /Srv634P/ {A++} END{if(A==2){print "mailx -s " s1 " servers currently which are running " s1 " test@xyz.com <<EOF" ORS "Server 62 -> Used for User acessing. ORS Server 65 -> Used for Database acessing." ORS "EOF"}}
3rd: If you are getting any results for above then please check your email if that is working fine in your box or not.
Please come back to us with all information and add additional information too if you have for us to understand the issue exactly. Because for me I just created dummy sleep processes and tried command and it worked. So only I have requested you to take this as a startup.
Thanks for helping me.
1st -> Using HP-Unix.
I tried the below script.
awk -vs1=" /Srv634/ || /Srv634P/ {A++} END{if(A==2){print "mailx -s " s1 " servers currently which are running " s1 " test@xyz.com <<EOF" ORS "Server 62 -> Used for User acessing. ORS Server 65 -> Used for Database acessing." ORS "EOF"}}
2nd-> test.sh[3]: syntax error at line 6 : `"' unmatched
Not sure but seems command you have mentioned doesn't have the complete command try as follows and let me know then.
ps -ef | awk -vs1="\"" '/Srv634/ || /Srv634P/ {A++} END{if(A==2){print "mailx -s " s1 " servers currently which are running " s1 " xyz@abc.com <<EOF" ORS "Server 62 -> Used for User acessing. ORS Server 65 -> Used for Database acessing." ORS "EOF"}'
If above doesn't work then try to be TRUE developer and try to check the command line by line. For example:
{
ps -ef | grep "rv" # A [ ] is the trick to prevent matching the grep process
echo "
Server 62 -> Used for User acessing.
Server 65 -> Used for Database acessing."
} | mailx -s "Server Running" xyz@abc.com
Or
mailx -s "Server Running" xyz@abc.com << EOT
`ps -ef | grep "rv"`
Server 62 -> Used for User acessing.
Server 65 -> Used for Database acessing.
EOT
Could you please try following and let us know if this helps you.
cat script_email.ksh
values=`ps -ef | grep -v grep | grep "Srv"` ### You can grep exact word which you want to search here please.
if [[ -n $values ]]
then
echo "Server 62 -> Used for User acessing." > Input_file
echo "Server 65 -> Used for Database acessing." >> Input_file
else
mailx -s"Please check server seems to be Srv process NOT running." test@chumma.com
fi
echo "<html>" > html_file
echo "<body>" >> html_file
echo "<p><b><u>" >> html_file
while read line
do
echo $line >> html_file
done < "Input_file"
echo "</b></u></p>" >> html_file
echo "</body>" >> html_file
echo "</html>" >> html_file
cat - html_file <<EOF | /usr/sbin/sendmail -oi -t
From: test@test.com
To: test@chumma.com
Subject: Srv process status email
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF