//View Tip #311
» Random IP addresses
» Find and Grep
» Reverse geocode with bash
» Quit bash without saving history
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.
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
Comments
Add your comment
No Comments

