[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Email output + logging too?

From: Matthew Cengia
Subject: Re: [Help-bash] Email output + logging too?
Date: Sun, 15 Sep 2013 10:39:41 +1000
User-agent: Mutt/1.5.21 (2010-09-15)

On 2013-09-14 09:15, Sharon Kimble wrote:
> I have this script which uses obnam to back up my /home/$USER
> directory, and it outputs to 2 logs, and should also output to an
> email. 

Use 'tee' for this:

  du -sh /media/boudiccas/backup/obnam-home 2>&1 | tee -a "$LOGGING2"

  echo 'Sending Backup report : Backup of obnam-home completed', $(date \
    -R) 'logged to' 2>&1 | tee -a "$LOGFILE"

To send the output of these commands to both their respective files, and
to stdout, which will get emailed out by cron.

Also, don't use capitalised variable names:

  By convention, environment variables (PATH, EDITOR, SHELL,
  ...) and internal shell variables (BASH_VERSION, RANDOM, ...) are fully
  capitalized. All other variable names should be lowercase. Since
  variable names are case-sensitive, this convention avoids accidentally
  overriding environmental and internal variables.

And finally, use more quotes, specifically around $LOGGING2, $LOGFILE, and
$(date ...):

  "Double quote" _every_ expansion, and anything that could contain a
  special character, eg. "$var", "$@", "address@hidden", "$(command)". Use
  'single quotes' to make something literal, eg. 'Costs $5 USD'. See
  <> and

Good luck!

Matthew Cengia

Attachment: signature.asc
Description: Digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]