Add Scroogle to your search area in Firefox 2.0 Install the 'Scroogle Scraper' search plugin.

October 2011


you can pipe the output of a crontab cron to the mail command to get its output, for example:

0 6 * * *  /usr/bin/php script.php | /bin/mail -s `daily_order_validation` spencer@example.com

Sends an email to spencer every day.

But what if you only want NONBLANK emails? You could do something like:

data=$(/usr/bin/php script.php); [[ -n "$data" ]] && mail -s 'only non blank email' spencer@example.com<<< "$data"

what if you only want an email if the script output has the word ERROR in it?

data=$(/usr/bin/php script.php); [[ $data == *ERROR* ]] && mail -s 'only non ERROR email' spencer@example.com<<< "$data"

src: http://unix.stackexchange.com/questions/13326/how-to-pipe-output-from-one-process-to-another-but-only-execute-if-the-first-has/13337#13337
and http://unix.stackexchange.com/questions/13326/how-to-pipe-output-from-one-process-to-another-but-only-execute-if-the-first-has

#!/bin/bash
 
HOSTNAME=`hostname`
LOADAVG1=`/usr/bin/top -b -n 1|head -n 1|awk '{print $12}'`
LOADAVG1=`echo "$LOADAVG1"|sed 's/\(.*\)./\1/'`
 
LOADAVG5=`/usr/bin/top -b -n 1|head -n 1|awk '{print $13}'`
LOADAVG5=`echo "$LOADAVG5"|sed 's/\(.*\)./\1/'`
 
LOADAVG10=`/usr/bin/top -b -n 1|head -n 1|awk '{print $14}'`
 
PROCESSES=`/usr/bin/top -b -n 1|head -n 2|tail -n 1|awk '{print $2}'`
MEMUSED=`/usr/bin/top -b -n 1|head -n 4|tail -n 1|awk '{print $4}'`
SWAP=`/usr/bin/top -b -n 1|head -n 5|tail -n 1|awk '{print $2","$4}'`
NOW=`date '+%Y-%m-%d %H:%M:%S'`
 
echo "$NOW,$HOSTNAME,$LOADAVG1,$LOADAVG5,$LOADAVG10,$PROCESSES,$MEMUSED,$SWAP"

then make it executable

chmod +x systemstats.sh

and then in crontab:

* * * * * /root/systemstats.sh >>/root/systemstats.log

Send to a friend * Print this page * Join the club * Talk with my robot * Advertise here * Search this Site * Donate * Link to me


Web hosting by Utah Hub *  Powered by CreativeTap *  In association with Segomo
Unless otherwise noted, Copyright 2004-2013, Ryan Byrd. All Rights Reserved.
Ryan Byrd dot net -- probably the coolest site in Utah