//View Tip #311
Similar Tips
» Add header/footer to command output
» Random IP addresses
» Find and Grep
» Reverse geocode with bash
» Quit bash without saving history

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Tired to get your mailbox full of cron information messages?
Eg.: some programs (pg_dump, /etc/init.d/xxx, ...) output informational messages on stderr, but you can't close stderr because it may also contain failure informations.

#!/bin/bash

LOG="/tmp/myscript-`date +%s`.tmp" IGNORE='^(Username: Password:|)[[:space:]]*$' # message to ignore, for demonstration only exec 3<&2; exec 2>$LOG # duplicate stderr for later use; redirect stderr to $LOG file
# insert your code (eg.: echo -e "login\npassword"|pg_dump -u user > file.dump)
exec 2<&3 # restore stderr # if $LOG file is not empty and contain anything else than what should be ignored, output it to stderr (for demonstration purpose) [ -s $LOG ] && egrep -vq $IGNORE $LOG && egrep -v $IGNORE $LOG >&2 rm -f $LOG


View Comments »



Comments 

Add your comment

CAPTCHA

No HTML allowed. URLs will be linked with nofollow attribute. Whitespace is preserved.

No Comments

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit