Mailx command doubt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mailx command doubt
# 8  
Old 07-20-2015
This is the output i recieved.

Code:
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.
Code:
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
Code:
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

# 9  
Old 07-20-2015
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.
Code:
 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
# 10  
Old 07-20-2015
Hi ravi & all,

Thanks for helping me.
1st -> Using HP-Unix.
I tried the below script.
Code:
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.
Code:
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 :
Code:
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.

Code:
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.


Last edited by arun888; 07-20-2015 at 12:02 PM..
# 11  
Old 07-20-2015
Quote:
Originally Posted by arun888
Hi ravi & all,

Thanks for helping me.
1st -> Using HP-Unix.
I tried the below script.
Code:
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.
Code:
ps -ef | grep "Srv" | mailx -s "Server is running" xyz@gmail.com

Output Expected :

Along with the process, i would need to some default description added in the body of the email.
Hello Arun,

Not sure but seems command you have mentioned doesn't have the complete command try as follows and let me know then.
Code:
 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
Code:
 ps -ef | awk -vs1="\"" '/Srv634/ || /Srv634P/'

2nd: If results comes for above then:
Code:
 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. Smilie Smilie


Thanks,
R. Singh

Last edited by RavinderSingh13; 07-20-2015 at 12:12 PM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 12  
Old 07-20-2015
Code:
{
ps -ef | grep "[S]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
Code:
mailx -s "Server Running"  xyz@abc.com << EOT
`ps -ef | grep "[S]rv"`

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

This User Gave Thanks to MadeInGermany For This Post:
# 13  
Old 07-21-2015
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.

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

# 14  
Old 07-21-2015
Hello arun,

Could you please try following and let us know if this helps you.
Code:
 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep command doubt

Hi all, I need to find the line by using grep command with the two occurence of word in the same line. I tried the below example it prints the word choice. cat nohup.out Dictionary utl is completed. file is completed. Dictionary file is completed. grep 'Dictionary\|file'... (0 Replies)
Discussion started by: arun888
0 Replies

2. UNIX for Dummies Questions & Answers

Doubt in ls command

dear users and experts, i am stuck withis command and i am unable to understand what is it doing?? ls -d * (7 Replies)
Discussion started by: seshank
7 Replies

3. HP-UX

mailx usage doubt

How to use mailx to send a mail by specifying the from: address, considering that i am the root user (3 Replies)
Discussion started by: Amit Kulkarni
3 Replies

4. Shell Programming and Scripting

Mailx: How to send a attachment using mailx command

Hi All, Can anyone please provide the command for sending an mail with attachment using mailx command. Thanks in Advance :) Regards, Siram. (3 Replies)
Discussion started by: Sriram.Vedula53
3 Replies

5. Shell Programming and Scripting

sed command doubt

i have input files like this SFE_DOC_DATE (SFE_DOC_DATE:UniChar.:): "04/18/20" SFE_PSTNG_DATE (SFE_PSTNG_DATE:UniChar.:): "04/18/20" SFE_CREATEDON (SFE_CREATEDON:UniChar.:): "05/31/20" SFE_CLEAR_DATE (SFE_CLEAR_DATE:UniChar.:): "(NULL)" SFE_CLR_DOC_NO... (3 Replies)
Discussion started by: Gopal_Engg
3 Replies

6. Solaris

doubt reg mailx command

Hi, Am trying to send mail from solaris host to my mailbox, but while executing mailx command am getting the follow error.Is this syntax corect? #mailx -s "subject" <myid> The flags you gave are used only when sending mail. (1 Reply)
Discussion started by: rogerben
1 Replies

7. Shell Programming and Scripting

doubt in grep command

Hello i am new shell scripting. I have a file like this, $ cat myfile ;/abc/abc.cpp@@/main/1;xyz ;/abc/abc.cpp@@/main/2;usr2 ;/abc/abc.cpp@@/main/1;abc ;/abc/abc.cpp@@/main/2;usr2 ;/abc/abc.cpp@@/main/1;usr1 when i grep the file. $ grep "abc" myfile... (8 Replies)
Discussion started by: tsaravanan
8 Replies

8. UNIX for Dummies Questions & Answers

doubt in tr command

Hi, I am trying to understand a script and found a line as follows: tr '\211\233\240' '\040' < $IN_FILE | tr -cd '\11\12\15\40-\176' > $TEMP_FILE Can any one explain the above line .. What are they trying to translate using the tr command.. I have not used tr command.. so feeling little bit... (2 Replies)
Discussion started by: risshanth
2 Replies

9. UNIX for Advanced & Expert Users

Mailx Doubt

Hi, I just wanted send corbon copy in mailx command, could you please assist me? I tried the below but it didn't work cat sample.txt|mailx -s "hi" -c xyz@gmail.com abc@gmail.com Shahnaz. (2 Replies)
Discussion started by: shahnazurs
2 Replies

10. Shell Programming and Scripting

doubt in mailx

Does not supplying a file to mailx cause it to run long? Cmd is like this: mailx -s "subject" recipient. Would the foll. cmd run fast: echo "content" | mailx -s "subject" recipient The recipient is a group id. Unix version:HP-UX B.11.11. Any help is appreciated. Thanks. (2 Replies)
Discussion started by: ranj@tcs
2 Replies
Login or Register to Ask a Question