Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to print all unix command mesage to a mail

Posted on 2002-05-18
23
Medium Priority
?
529 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 1200 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 21

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

824 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