INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Mail X command

Mail X command

(OP)
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.

RE: Mail X command

Hi

If I understand you correctly :

CODE --> shell

(
    echo 'Need to amend the below email information in the body of the email.'
    ps -ef | grep "Srv"
    echo 'Srv634P -> used for client acecssing.'
    echo 'Srv634 -> Used for server acessing.'
) | mailx -s "Server Currently Running " xyz@gmail.com 

Feherke.
feherke.ga

RE: Mail X command

(OP)
yes you are right. I am receiving the output as expected.
Output Reicieved :

1. oesdba 3108 17851 0 Jul 7 ? expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634P
2. oesdba 6501 17851 0 Jul 17 ? expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634

3. efsoesvr 17644 17641 1 11:16:42 pts/2 0:00 grep Srv

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


Please let me know how to remove the 3rd line which we used to search in the unix command.

Thanks a lot for providing solution.

RE: Mail X command

Hi

Quote (keerthi2016)

Please let me know how to remove the 3rd line which we used to search in the unix command.

There are two usual ways :
  1. Use another grep call to exclude lines containing "grep" :

    CODE

    ps -ef | grep 'Srv' | grep -v 'grep' 
  2. Use a regular expression that matches the needed string but not matches itself :

    CODE

    ps -ef | grep '[S]rv' 

Feherke.
feherke.ga

RE: Mail X command

(OP)
Thanks a lot it works.

Your answers make me to learn.

RE: Mail X command

(OP)
hi feherka,

I need one more help from you.

Currently I am getting output as .

oesdba 3108 17851 0 Jul 7 expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634P 27 32 33
oesdba 6501 17851 0 Jul 17 expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634 27 32 33 3
ExpSrv634P Instance used for acessing
ExpSrv634 Instance used for acessing


I need to provide a space as below for the output. can you help me out.
Expected Output :

oesdba 3108 17851 0 Jul 7 expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634P 27 32 33
oesdba 6501 17851 0 Jul 17 expres63 /var/tmp/xsauthn /var/tmp/xsauthz ExpSrv634 27 32 33 3

Instance Description :

ExpSrv634P Instance used for accessing
ExpSrv634 Instance used for accessing

RE: Mail X command

Hi

That is more difficult question, as echo is not fully portable. So you have to pick one of the solutions that works on your system :

CODE

echo   # without parameters usually displays just a newline

echo 'line one
line two

line four ( yepp, line three was empty and so will be line five )
'      # not echo's trick, but the shell's : embed literal newlines in the parameter

cat <<ENDOFTEXT # similar as above, but with cat and here-document
line one
line two

line four ( yepp, line three was empty and so will be line five )

ENDOFTEXT

echo 'line one\nline two'   # some implementations interpret embedded \n as newlines

echo -e 'line one\nline two'   # other implementations does it only when asked to by using the -e option

echo $'line one\nline two'   # somehow similar, but here Bash interprets the \n, not echo

printf 'line one\nline two\n'   # printf is standard, just note that it outputs no implicit newline 

Feherke.
feherke.ga

RE: Mail X command

(OP)
Thanks for your solution. All the options worked out.

Cam tell me also let me know how to make the 1st line with bold and underlined.

1st line "Instance Description/"

RE: Mail X command

Hi

Quote (keerthi2016)

Cam tell me also let me know how to make the 1st line with bold and underlined.
By default e-mails are plain texts, so no formatting. Some clients may honor some conventions of plain text formatting, like *bold* and _underline_, but that is each client's own decision.

What you can do, is send the content as HTML document. Then you can use some usual HTML and CSS formatting. ( Not all. And they will not appear the same way in every client. )

To tell the mail clients the content is HTML document, add those -a parameters to mailx as below :

CODE

(

cat <<ENDHEADER
<html>
<body>
<pre>
ENDHEADER

    ps -ef | grep '[S]rv'

cat <<ENDFOOTER
</pre>
<p><b><u>Instance Description :</u></b></p>
<p>
Srv634P -> used for client acecssing.<br>
Srv634 -> Used for server acessing.
</p>
</body>
</html>
ENDFOOTER

) | mailx -s "Server Currently Running " -a 'MIME-Version: 1.0' -a 'Content-Type: text/html' xyz@gmail.com 

Warning ! The above code was not tested.

Feherke.
feherke.ga

RE: Mail X command

(OP)
thanks for your update.

I am getting the below error when I tried to execute the above code.

mailx: illegal option -- a

RE: Mail X command

(OP)
I have pasted the given code html in the name of testt.html and called the html code in the shell script.

home/unix >cat testt.html

(

cat <<ENDHEADER
<html>
<body>
<pre>
ENDHEADER

ps -ef | grep '[S]rv'

cat <<ENDFOOTER
</pre>
<p><b><u>Instance Description :</u></b></p>
<p>
Srv634P -> used for client acecssing.<br>
Srv634 -> Used for server acessing.
</p>
</body>
</html>
ENDFOOTER

/home/unix]$ ksh -x lkl.sh
set -x
cat testt.html

But I could see the emails are not sent to the id.

RE: Mail X command

(OP)
I am wrongly executing the html tag. it would be great if you can help me how to execute the html tag.

RE: Mail X command

Hi

Quote (keerthi2016)

mailx: illegal option -- a
That is bad. That -a option is an addition, not part of the standard. Some such tools have it, others not.

You need -a or something equivalent to specify a mail header. The manual of the mailx implementation on my machine describes it like this :

Quote (man mailx)

     -a      Specify additional header fields on the command line such as "X-
             Loop: foo@bar" etc.  You have to use quotes if the string con‐
             tains spaces.  This argument may be specified more than once, the
             headers will then be concatenated. 

Look in the manual of your mailx to see whether it mentions another way to specify headers.

Alternatively, check if sendmail is available on your machine.

Feherke.
feherke.ga

RE: Mail X command

(OP)
can you please tell me how to run the file test.html file.

Previously i have run the file with the .sh extension hence i got the error.

RE: Mail X command

Sendmail can do it. Something like this...

CODE

export SUBJECT="Servers Currently Running"
export MAILTO=xyz@gmail.com

(
cat <<-EMAILHEADER
To: ${MAILTO}
Subject: ${SUBJECT}
MIME-Version: 1.0
Content-Type: text/html
Content-Disposition: inline
EMAILHEADER

cat <<-DOCHEADER
<html>
<body>
<pre>
DOCHEADER

    ps -ef | grep '[S]rv' | grep -v grep

cat <<-DOCFOOTER
</pre>
<p><b><u>Instance Description :</u></b></p>
<p>
Srv634P -> used for client accessing.<br>
Srv634 -> Used for server accessing.
</p>
</body>
</html>
DOCFOOTER

) | /usr/sbin/sendmail ${MAILTO} 

RE: Mail X command

Hi

SamBones, an empty line is missing there, right before closing the EMAILHEADER here-document, to separate e-mail headers and e-mail body.

Feherke.
feherke.ga

RE: Mail X command

(OP)
hi sambones,

Everything worked as expected. thanks for your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close