Solved

how to print all unix command mesage to a mail

Posted on 2002-05-18
23
487 Views
Last Modified: 2010-04-21
my command:

%/usr/bin/rsync -Lpgtrzv --numeric-ids /afs/abc/RCS/projA /fs/abc/proj/valid/RCS/
building file list ... /afs/abc/RCS/projA : Permission denied
done
nothing to do

%/usr/bin/rsync -Lpgtrzv --numeric-ids /afs/abc/RCS/projA /fs/abc/proj/valid/RCS/ | mail -s "rsync /afs/abc/RCS/projA" hl@abc.com
/afs/pdx/proj/nwd/valid/RCS/wmt : Permission denied
nothing to do

My mail only show:
building file list ... done

how can i print all the full message to the mail?

thanks
hl
0
Comment
Question by:bhuey_ling
  • 8
  • 6
  • 6
  • +3
23 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 7019689
Fist you need to pine the messages to a logfile.
them email the login file to you.

eg:

cat /dev/null > mylogfile
command-1 > mylogfile 2&1
command-2 >> mylogfile 2&1
mail myemailadd < mylogfile
rm mylogfile

replace command-1/2 with you commands

you can writea a litte script to do the job
0
 
LVL 5

Accepted Solution

by:
ecw earned 300 total points
ID: 7020295
or run the commands in a subshell, and redirect stdout and stderr of the subshell through a pipe to mailx eg.

#!/bin/sh

(
command-1
command-2
) 2>&1 | mail myemailadd

then you can dispense with tmp files
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7022470
sh and firends:  rsync .... 2>&1 | mail ...
csh and friends: rsync .... |& mail ...
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:bhuey_ling
ID: 7044643
How can I separate sent my error message to the admin and successful process message to the developer?

my code:
-------
/usr/bin/rsync -Lgtrzv --numeric-ids /afs/proj/a /fs35/file213/proj/ >> $LOG

mail -s "Rsync Message" hl@hotmail.com < $LOG

This only sent out the successful message but not the error message.

thanks
hl
0
 
LVL 5

Expert Comment

by:ecw
ID: 7045144
as ahoffman showed, use 2>&1 ...
 usr/bin/rsync -Lgtrzv --numeric-ids /afs/proj/a /fs35/file213/proj/ >> $LOG 2>&1

so errors (stderr, fd==2), are dup'ed to stdout (fd==1)
0
 

Author Comment

by:bhuey_ling
ID: 7045474
Could you explain more on how i sent the error the error message with this command?

usr/bin/rsync -Lgtrzv --numeric-ids /afs/proj/a /fs35/file213/proj/ >> $LOG 2>&1

for the successful message i can sent by using

mail -s "Rsync Message" hl@hotmail.com < $LOG

for the error message i can sent by

usr/bin/rsync -Lgtrzv --numeric-ids /afs/proj/a /fs35/file213/proj/ >> $LOG 2>&1 | mail -s "Rsync error" hl@hotmail.com

means the whole code look like


ids /afs/proj/a /fs35/file213/proj/ >> $LOG 2>&1 | mail -s "Rsync error" hl@hotmail.com
mail -s "Rsync Message" hl@hotmail.com < $LOG

or make any mistake? how about if i look like to log the error message in a log file too cause i could be hv few rsync need to be call. And i would like to sent out all error message together in once.

thanks,
hl



0
 
LVL 5

Expert Comment

by:ecw
ID: 7045630
By redirecting stderr to the same file as stdout, normal output and errors get intermingled, so $LOG contains both.  Is this satisfactory?
0
 

Author Comment

by:bhuey_ling
ID: 7048092
Can I redirecting the stderr to different file. So that i don't need to write a script to parse the log file and extract the error message from the log file. In this case  i can direct get a separate 2 files, one for successful message and one for error message?
Then I can direct sent the meesage from different log file to different ppl in cron job, instead of calling another script..


thanks
hl
0
 

Author Comment

by:bhuey_ling
ID: 7048327
Hi ,

I urgently need a shell script for me to run rsync and can separate the error message and successful message (name of updated file) , then I can sent sent the error message and succesful message to different ppl.

thanks
hl
0
 
LVL 5

Expert Comment

by:ecw
ID: 7048517
ids /afs/proj/a /fs35/file213/proj/ >> $LOG 2>> $ERRLOG
mail -s "Rsync error" hl@hotmail.com < $ERRLOG
mail -s "Rsync Message" hl@hotmail.com < $LOG
0
 

Author Comment

by:bhuey_ling
ID: 7049489
hi,

what is "ids" for?
That is my testing shell script. I get error message "Ambiguous output redirect." when run the script.

#!/bin/sh
set LOG = "logfile"
set ERRLOG = "errlog"

ids rsync -raz /fs/proj/doTest/src   /fs2/proj/doTest/dest > $LOG 2> $ERRLOG
mail -s "Rsync error" hl@hotmail.com < $ERRLOG
mail -s "Rsync Message" hl@hotmail.com < $LOG


thanks,
hl
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7049781
remove the ids, and it shoulod work.
0
 
LVL 5

Expert Comment

by:ecw
ID: 7050897
ids? - dodgy cut and paste
0
 

Author Comment

by:bhuey_ling
ID: 7051175
hi,

I hv delete "ids" but still is get same error message "Ambiguous output redirect".


#!/bin/sh
set LOG = "logfile"
set ERRLOG = "errlog"

rsync -raz /fs35/wmtpe212/hboey1/doTest/src   /fs35/wmtpe212/hboey1/doTest/dest > $LOG 2> $ERRLOG
mail -s "Rsync error" huey.ling.boey@intel.com < $ERRLOG
mail -s "Rsync Message" huey.ling.boey@intel.com < $LOG

thanks,
hl
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7051281
#!/bin/sh
LOG="logfile"
ERRLOG="errlog"
rsync -raz /fs35/wmtpe212/hboey1/doTest/src /fs35/wmtpe212/hboey1/doTest/dest > $LOG 2>$ERRLOG
mail -s "Rsync error" huey.ling.boey@intel.com < $ERRLOG
mail -s "Rsync Message" huey.ling.boey@intel.com < $LOG
0
 

Author Comment

by:bhuey_ling
ID: 7052867
without using "set" i will get error "LOG: Command not found"

thanks
huey ling
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7053357
> without using "set" i will get error "LOG: Command not found"
then /bin/sh is not a Bourne shell at all. Could you please  posr result of
  ls -l /bin/sh
How did you start above script?
0
 

Author Comment

by:bhuey_ling
ID: 7074794
hi ,

the result of my ls -l /bin/sh is

-r-xr-xr-x   3 bin         89492 Aug  6  1996 /bin/sh

this is my whole script

#!/bin/sh
set LOG = "logfile"
set ERRLOG = "errlog"

rsync -raz /fs/hboey1/doTest/src   /fs1/hboey1/doTest/dest > $LOG 2> $ERRLOG
mail -s "Rsync error" hl@hotmal.com < $ERRLOG
mail -s "Rsync Message" hl@hotmail.com < $LOG

And i run the script by source the file

%source run_cron

0
 
LVL 5

Expert Comment

by:ecw
ID: 7075013
don't source, just run it
% ./run_cron
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7075148
what are you doing?

  1. source ./run_cron
     is csh syntax, not sh
  2. set var=val
     is wrong Bourne shell syntax. Dot.
  3. your /bin/sh has 3 hard links, what are the other ones named?

confused.

As ecw suggested, just run:

   ./run_cron

but remove the set commands before !
0
 
LVL 20

Expert Comment

by:tfewster
ID: 7921194
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by ecw

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7924133
agreed, but please mark ecw's very first suggestion as answer
0
 

Expert Comment

by:SpideyMod
ID: 7967082
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EMC VNX  storage pool  Vs  raid group  question 3 137
change HISTFILE for root user on AIX 3 87
aix tls version 6 422
Linux hostname change 2 83
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question