Mailx command doubt

hi all,

I would need to add the description in the below syntax. let me know the below syntaxt how it can be changed to add the description in the below.

ps -ef | grep "server" | mailx -s "servers currently which are running" operational@acel.com
Server 62 -> Used for User acessing.
Server 65 -> Used for Database acessing.

---------- Post updated at 02:38 AM ---------- Previous update was at 02:23 AM ----------

currently, my script is sending the server running in the backend. I would need to add the
below body in my unix script with the existing unix syntax.

Server 62 -> Used for User acessing.
Server 65 -> Used for Database acessing.

Hello arun888,

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
 

Thanks,
R. Singh

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.

I hope this helps.

bakunin

1 Like

thanks for you update.

Currently, in crontab i have scheduled a script daily to let the user know what are the process running in the backend in daily basis.

unix]$ ps -ef | grep 'Srv634'
svr 11394  4120  1 04:15:05 pts/2     0:00 grep Srv634
  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

ps -ef | grep "Srv" | mailx -s "Server Running"  xyz@abc.com 

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.

Hello Arun888,

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.

Thanks,
R. Singh

1 Like

hi ravinder,

Thanks for your syntax. I could see

 { 

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

Try also

ps | { grep gvfs; printf "%s\n%s\n", srv1,srv2; } | mail ...
1 Like

This is the output i recieved.

ps -ef | awk -vs1="\"" '/Srv634P/ || /Srv634/'
Output :
[/home/unix]$ ps -ef | awk -vs1="\"" '/Srv634P/ || /Srv634/'
  dba  3108 17851  0  Jul  7  ?         2:55 exp63 /var/tmp/xsauthn /var/tmp/xsauthz Srv634P 27 32 33
soesvr  6853  4120  1 07:12:22 pts/2     0:00 awk -vs1=" /Srv634P/ || /Srv634/
  dba  6501 17851  0  Jul 17  ?         2:27 exp63 /var/tmp/xsauthn /var/tmp/xsauthz Srv634 27 32 33 3

---------- Post updated at 07:35 AM ---------- Previous update was at 07:16 AM ----------

hi ravi,

I get the output as follow.

ps -ef | awk -vs1="\"" '/Srv634P/ || /Srv634/'
Output :
[/home/unix]$ ps -ef | awk -vs1="\"" '/Srv634P/ || /Srv634/'
  dba  3108 17851  0  Jul  7  ?         2:55 exp63 /var/tmp/xsauthn /var/tmp/xsauthz Srv634P 27 32 33
soesvr  6853  4120  1 07:12:22 pts/2     0:00 awk -vs1=" /Srv634P/ || /Srv634/
  dba  6501 17851  0  Jul 17  ?         2:27 exp63 /var/tmp/xsauthn /var/tmp/xsauthz Srv634 27 32 33 3

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

Hello Arun,

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,
R. Singh

Hi ravi & all,

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

I am recieving email if i use the below syntax.

ps -ef | grep "Srv" | mailx -s "Server is running" xyz@gmail.com

Currently i am sending the list of process running in the backend to the user as below.

ps -ef | grep "Srv" | mailx -s "Server Currently Running " xyz@gmail.com

Current Output :

dba 3108 17851 0 Jul 7 ? 13:36 expres63 /var/tmp/xsauthn /var/tmp/xsauthz Srv634P 27 32 33
dba 6501 17851 0 Jul 17 ? 2:34 expres63 /var/tmp/xsauthn /var/tmp/xsauthz Srv634 27 32 33 3

Expected Output :

Need to amend the below email information in the body of the email.

dba 3108 17851 0 Jul 7 ? 13:36 expres63 /var/tmp/xsauthn /var/tmp/xsauthz Srv634P 27 32 33
dba 6501 17851 0 Jul 17 ? 2:34 expres63 /var/tmp/xsauthn /var/tmp/xsauthz Srv634 27 32 33 3

Srv634P -> used for client acecssing.
Srv634 -> Used for server acessing.

Hello Arun,

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:

1st: Try

 ps -ef | awk -vs1="\"" '/Srv634/ || /Srv634P/'
  

2nd: If results comes for above then:

 ps -ef | awk -vs1="\"" '/Srv634/ || /Srv634P/ {A++} END{print A}'
 

And so on for checking the command's reliability. Enjoy learning in each and every phase. :b: :slight_smile:

Thanks,
R. Singh

1 Like
{
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
1 Like

thanks a lot .. It works now as expected.

---------- Post updated at 08:40 AM ---------- Previous update was at 08:37 AM ----------

do you have any idea how to change the code if I need to use bold and underline in the below words.

 
Server 62 -> Used for User acessing.
Server 65 -> Used for Database accessing

Hello arun,

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
 

I hope this helps.

Thanks,
R. Singh

Current Output :

Instance running in the backend
  oesdba  6501 17851  0  Jul 17  ?         3:25 expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634 27 32 33 3
  oesdba   935 17851  0 02:08:45 ?         0:02 expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634P 27 32 33 

Instance Description
Srv634 Instance used for client.
Srv634P Instance used for database.

Expected Output : The line should be in bold.

Instance running in the backend
  oesdba  6501 17851  0  Jul 17  ?         3:25 expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634 27 32 33 3
  oesdba   935 17851  0 02:08:45 ?         0:02 expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634P 27 32 33 

Instance Description
Srv634 Instance used for client.
Srv634P Instance used for database.