Find the answer to your Linux question:
Results 1 to 9 of 9
Hi all, This is my first post. I am new with the field. I have a script running on server which monitor backup taken by RMAN, store these status to ...
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    3

    shell script + image

    Hi all,

    This is my first post. I am new with the field.

    I have a script running on server which monitor backup taken by RMAN, store these status to a file (called bkpstatus.html) in server side and then send mail to me on my outlook.

    Script is running find and giving me expected output.

    Now I am thinking that if is it possible to add some code into script which call image and send it to me on my mail along with output.

    I don't know wheter I open my question properly

    any way Thanks in ADV

  2. #2
    Just Joined!
    Join Date
    Mar 2007
    Location
    Bogotá, Colombia
    Posts
    39
    If what you want is to attach an image to an email and send it, it can be done with openssl, like this:

    Code:
    (echo "EHLO `hostname`"
    sleep 1
    echo "mail from: sender@example.com"
    sleep 1
    echo "rcpt to: recipient@example.com"
    sleep 1
    echo "data"
    sleep 1
    echo "MIME-Version: 1.0
    Subject: A Simple Example
    From: sender@example.com
    To: recipient@example.com
    Content-Type: multipart/mixed; boundary=sep
    
    --sep
    Content-Type: text/plain; charset=UTF-8
    
    ... In here you can write whatever you want, for instance, your results ....
    
    --sep
    Content-Type: image/png;
        name=\"someimage.png\"
    Content-Disposition: attachment;
        filename=\"someimage.png\"
    Content-Transfer-Encoding: base64
    
    "
    cat someimage.png | openssl base64
    echo "
    
    --sep--
    
    ."
    sleep 1
    echo "quit" ) | telnet smtp.example.com 25
    It is very important to put each sleep between commands, to give some time to the server to process each command, otherwise it might not work.

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    68
    Hi,
    I would probably not use the sleep statements... The chances are good that this will fail randomly as it's not checking the return codes from the mail server and it's just assuming each command was processed correctly.

    Have a look at the info on MIME here:
    SHELLdorado - Sending files as mail attachments

    The uuencode example is super easy - but the image may or may not be displayed correctly depending on the mail reader you are using. The most reliable way to send an attachment is using the mutt or metamail (samples on the above URL).

  4. #4
    Just Joined!
    Join Date
    Jul 2007
    Location
    Chennai, India
    Posts
    8
    If you post the script, we can see the exaact mail program the script is using and help you effectively.

  5. #5
    Just Joined!
    Join Date
    Apr 2011
    Posts
    3
    Hi all,

    Thanks for your all reply.

    Here is script which running fine
    #!/bin/bash
    ADMIN="abc@zyz.com"
    . $HOME/.profile
    SID=PROD
    for SID in PROD
    do
    cd /d05_prod/scr
    echo "<B><U><font size="2" face="Verdana" color=blue>Error In RMAN Backup If Any :</B></U></font><BR><BR>" > rman_bkp_st.html
    cp /rman_bkp/logs/level0_backup_DB*.log /d05_prod/scr/dbbkp.lst
    grep RMAN- /d05_prod/scr/dbbkp.lst > /d05_prod/dbbkp_err.lst
    if [ `wc -l < /d05_prodscr/dbbkp_err.lst` -gt 0 ]
    then
    echo "<font size="2" face="Verdana" color=red>DB BKP gone in ERROR :<BR></font><PRE>"
    cat /d05_prod/scr/dbbkp_err.lst
    echo "</PRE>"
    else
    echo "<font size="2" face="Verdana" color=green>All DB bkp Completed Successfully.</font><BR><BR>"
    fi >> rman_bkp_st.html

    tail -11 /d05_prod/scr/abc.lst >> rman_bkp_st.html
    echo "<BR><BR><B><font size="+1"><center>######### END OF SCRIPT ##########</B></center></font>" >> rman_bkp_st.html

    (
    echo "Subject: ${SID} RMAN BACKUP STATUS"
    echo "Content-Type: text/html"
    echo "To: abc@xyz.com"
    echo "Cc: abc@xyz.com"
    cat rman_bkp_st.html
    ) | /usr/sbin/sendmail $ADMIN


    Now I need to add some imange if i am getting mail from script like DB BKP gone in ERROR

    and some other imange if getting mail from scrtipt that DB BKP completed successfully.

    please suggest if this is possible!

    Thanks

  6. #6
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    If you have sendmail configured properly, then, well, using telnet is for bonus geek points of course but...

    ...why not use a more human readable approach?

    Code:
    mailx -s "subject line" -a /path/to/attachment recipient@domain.com

    ---


    Oh wait, I see I had a read error myself. You want to include one image if all went well, and another if an error occurred? I must say, I have a little trouble understanding your script, what with HTML, Bash and such intertwined without formatting (I'm a bit to lazy I suppose )

    Easiest way I can think of is just something like this:

    Code:
    command && IMAGE="all.is.well.jpg" || IMAGE="trouble.ahead.jpg"
    cat <<EOF>>outputfile.html
         <p>One picture is worth 128k words</p>
         <img src="$IMAGE" width="100">
    EOF
    Can't tell an OS by it's GUI

  7. #7
    Just Joined!
    Join Date
    Apr 2011
    Posts
    3
    Hi,

    Thanks for your reply !

    I am sorry to say but I did'nt get you, will you please elabrate.

    where can I fix this provided code by you in my script ??
    Do I need to store some image in server side then I call that image withing the script ??
    means what exaclty i have to do to fix both the images ??

    Please suggest !

  8. #8
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    68
    lol. I think there is a disconnect here somewhere.
    You were the one that said you wanted to send an image...

    "Now I am thinking that if is it possible to add some code into script which call image and send it to me on my mail along with output."

    So yes, if you want to send an image along with your email, you will need to put those images on the server side where the script that sends the email is running. If this is not what you want, please re-explain.

    If you are running a distro that has a mailx that supports the "-a" option, then Freston's solution is the most elegant. (RHEL 6 has the "-a", RHEL 5.5 does not)

    Something like this:

    Code:
    # do the stuff in your script to create the text/html part of the mail
    # put it in a file called /tmp/content.txt
    # Run some command to test for success of the rman (like your wc)
    if [ $? = 0 ]
    then
        mailx -s "RMAN good" -a good.png  recipient@domain.com </tmp/content.txt
    else
       mailx -s "RMAN bad" -a bad.png  recipient@domain.com </tmp/content.txt
    fi
    Last edited by abarclay; 04-29-2011 at 02:01 AM. Reason: trying to get the formatting right

  9. #9
    Just Joined!
    Join Date
    Jul 2007
    Location
    Chennai, India
    Posts
    8
    Code:
    if [ `wc -l < /d05_prodscr/dbbkp_err.lst` -gt 0 ]
    then
    echo "<img>" the image tag for error"
    echo "<font size="2" face="Verdana" color=red>DB BKP gone in ERROR :<BR></font><PRE>"
    cat /d05_prod/scr/dbbkp_err.lst
    echo "</PRE>"
    else
    echo "<img>" the image tag for OK
    echo "<font size="2" face="Verdana" color=green>All DB bkp Completed Successfully.</font><BR><BR>"
    fi >> rman_bkp_st.html
    I would add it in the places indicated. Get the help of a local person who knows HTML to complete the <img> tags appropriately and dont forget to send the image also by mail

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...