print output of a command in same as shell in mail : please help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print output of a command in same as shell in mail : please help
# 1  
Old 01-24-2011
print output of a command in same as shell in mail : please help

i have written a simple script to print the out of a command and send an mail but i am not getting a shell output here .please see my script

present output is like this i need an output as same as shell
Code:
Postfix log summaries for Jan 24 Grand Totals ------------ messages 1432 received 1439 delivered 0 forwarded 7 deferred (42 deferrals) 3 bounced 0 rejected (0%) 0 reject warnings 0 held 0 discarded (0%) 31472k bytes received 31774k bytes delivered 2 senders 1 sending hosts/domains 15 recipients 8 recipient hosts/domains Per-Hour Traffic Summary time received delivered deferred bounced rejected -------------------------------------------------------------------- 0000-0100 214 214 7 0 0 0100-0200 217 216 7 3 0 0200-0300 214 214 7 0 0 0300-0400 216 216 7 0 0 0400-0500 218 226 7 0 0 0500-0600 217 217 7 0 0 0600-0700 136 136 0 0 0 0700-0800 0 0 0 0 0 0800-0900 0 0 0 0 0 0900-1000 0 0 0 0 0 1000-1100 0 0 0 0 0 1100-1200 0 0 0 0 0 1200-1300 0 0 0 0 0 1300-1400 0 0 0 0 0 1400-1500 0 0 0 0 0 1500-1600 0 0 0 0 0 1600-1700 0 0 0 0 0 1700-1800 0 0 0 0 0 1800-1900 0 0 0 0 0 1900-2000 0 0 0 0 0 2000-2100 0 0 0 0 0 2100-2200 0 0 0 0 0 2200-2300 0 0 0 0 0 2300-2400 0 0 0 0 0 Host/Domain Summary: Message Delivery sent cnt bytes defers avg dly max dly host/domain -------- ----

Code:
#!/bin/bash
tmp="/tmp/check.tmp"
echo "to:bastian@unimaxlin.com">$tmp
echo "from:mail_stat@unimaxlin.com" >>$tmp
echo "subject:Mail status on $(hostname)">>$tmp
echo "Content-Type: text/html; charset="us-ascii"">>$tmp
echo "<html>" >> $tmp
date=`date | awk -F" "  '{print$2$3}'`
pflogsumm -d today /var/log/maillog > /tmp/mailres
result=`cat /tmp/mailres`
echo " $result" >> $tmp

i need a similar output please help

Code:
[dispatc  06:40 AM| ~]# cat /tmp/mailres                                  
Postfix log summaries for Jan 24

Grand Totals
------------
messages

   1441   received
   1448   delivered
      0   forwarded
      7   deferred  (42  deferrals)
      3   bounced
      0   rejected (0%)
      0   reject warnings
      0   held
      0   discarded (0%)

  31492k  bytes received
  31794k  bytes delivered
      2   senders
      1   sending hosts/domains
     15   recipients
      8   recipient hosts/domains


Per-Hour Traffic Summary
    time          received  delivered   deferred    bounced     rejected
    --------------------------------------------------------------------
    0000-0100         214        214          7          0          0 
    0100-0200         217        216          7          3          0 
    0200-0300         214        214          7          0          0



Code:
echo "</html>" >>$tmp
/usr/sbin/sendmail -t < $tmp

Moderator's Comments:
Mod Comment Please use code tags for listings and console output.

Last edited by pludi; 01-24-2011 at 07:53 AM..
# 2  
Old 01-24-2011
Are you reading the email with Outlook? Are you sure outlook just isn't formatting the email incorrectly?
# 3  
Old 01-24-2011
i am using gmail to read the mails

---------- Post updated at 08:18 AM ---------- Previous update was at 07:55 AM ----------

i have written a perl script an now it is working

Code:
!/usr/bin/perl -w
$h=`hostname`;
chomp($h);
$to= 'bastian@unimaxlin.com';
$from= 'mail_stat@unimaxlin.com';
open(MAIL, "|/usr/sbin/sendmail -t");
## Mail Header

print MAIL "To: $to\n";

print MAIL "From: $from\n";

print MAIL "Subject: Mail Log Summary for \t$h\n\n";

`/usr/local/bin/pflogsumm -d today /var/log/maillog > /tmp/mailer`;


$i=`cat /tmp/mailer`;

print MAIL $i;

close(MAIL);


Last edited by pludi; 01-24-2011 at 09:21 AM.. Reason: added code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to Print output in table using shell script

#! /bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( ... (4 Replies)
Discussion started by: ankit.mca.aaidu
4 Replies

2. Shell Programming and Scripting

[Solved] Shell script output in HTML or with table like results and mail

Hello, Currently i have a script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html and send that content as email. Please help me how i can do that. I am using... (10 Replies)
Discussion started by: joy lobo
10 Replies

3. Shell Programming and Scripting

How to print the output of a select query using shell script?

HI, I want to connect to database and fetch the count from a table. The sql query is as below : select count(*) from table_test where test_column='read'; How can I print the output of this statement using shell script. Thanks in advance. (4 Replies)
Discussion started by: confused_info
4 Replies

4. UNIX for Dummies Questions & Answers

Print each output of loop in new column using awk or shell

I have this output from a loop a11 1,2 3,4 5,6 7,8 12,8 5,4 3,6 a12 10,11 12,13 15,18 20,22 a13 ... (3 Replies)
Discussion started by: maryre89
3 Replies

5. Shell Programming and Scripting

awk command : To print the output to a file

half of the problem is already solved with the help of bartus11 suggestion I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. 50.000000 1 1 1 1000.00000 1000.00000 ... (5 Replies)
Discussion started by: shashi792
5 Replies

6. AIX

How to mail the output of a command in AIX

Hi, I have mastered how to mail to Windows in AIX. Can anyone tell me how I would mail the output command df -g to an email? I want to set a job in cron to mail df -g as the contents of a mail. Any ideas? Thanks John (4 Replies)
Discussion started by: jfd7000
4 Replies

7. Shell Programming and Scripting

how can i print the output of the shell script in bigger size

how can i print the output of the shell script in bigger size eg: echo " hello world" i want to print this in the output with bigger size in the middle of the screen. can someone please help me out in that (2 Replies)
Discussion started by: mail2sant
2 Replies

8. Shell Programming and Scripting

Shell script to search through numbers and print the output

Suppose u have a file like 1 30 ABCSAAHSNJQJALBALMKAANKAMLAMALK 4562676268836826826868268468368282972982 2863923792102370179372012792701739729291 31 60... (8 Replies)
Discussion started by: cdfd123
8 Replies

9. Shell Programming and Scripting

Can we use 'tr' command to print 5th column of output of 'ls -l'

Hi All, I know awk command can do it, but can we use tr command to print 5th column of out put 'ls -l' command???? Regards, Nidhi... (4 Replies)
Discussion started by: Nidhi2177
4 Replies

10. Shell Programming and Scripting

to print output using shell command

suppose u have 2 files ; where both files have one line in common. say one file like that >gi|62859953|ref|NP_001017322.1| plexin B2 MKEKERTKAITEIYLTRLLSVKGTLQQFVDNFFQSVLNSNQVVPPAVKYFFDFLDEQAEKYEIKDEDTVHIWKTNSLSLR... (13 Replies)
Discussion started by: cdfd123
13 Replies
Login or Register to Ask a Question