Solved

how to print all unix command mesage to a mail

Posted on 2002-05-18
23
473 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now