Casper Posted February 12, 2009 Report Share Posted February 12, 2009 Okay, I'm writing a script to run as a cron job. The script will do a df -Pm, sort reverse order column 4, then awk to format the spacing. The results are written to a file, then emailed. Here's what I've got for the df:df -Pm | sort +4rn | awk '{printf "%-22s %-15s %-15s %-15s %-10s %s\n", $1, $2, $3, $4, $5, $6}' >> $LOGFILEProblem is, when sent to our email client (Groupwise) the default font for viewing emails is not a fixed width font, so the columns are all fucked up. I'm using sendmail, so I can send html emails. Sweet. Ah, but another problem.What I would need is something like this:df -Pm | sort +4rn | awk '{sub(/[/, " ");printf "%-22s %-15s %-15s %-15s %-10s %s\n", $1, $2, $3, $4, $5, $6}' >> $LOGFILEThis would, in theory, put <br> at the end of every row. This is needed if I'm sending html emails. Otherwise, all of the rows continue on one line. However, <br> is not allowed because < and > are operators. How can I get around this? Quote Link to comment Share on other sites More sharing options...
Casper Posted February 12, 2009 Author Report Share Posted February 12, 2009 Nevermind, using the <pre> html tag fixed my problems. Quote Link to comment Share on other sites More sharing options...
Disclaimer Posted February 12, 2009 Report Share Posted February 12, 2009 Duh! Silly Casper.I have no fucking clue what he's talking about. Quote Link to comment Share on other sites More sharing options...
wolfman Posted February 12, 2009 Report Share Posted February 12, 2009 Nevermind, using the <pre> html tag fixed my problems.Duh! :grin: Quote Link to comment Share on other sites More sharing options...
justin0469 Posted February 12, 2009 Report Share Posted February 12, 2009 Just like you did with the [, it doesn't work if you surround the operator with some backslashes? Like "/<br>/"? That's usually the escape character to ignore operators right?Edit: too late, by the time I came back and posted, you already got a solution! Quote Link to comment Share on other sites More sharing options...
Paddy O Furniture Posted February 12, 2009 Report Share Posted February 12, 2009 Don't you have to use format specifiers instead of the operators? Awk sees < as an operator but you have to use something like printf(%s%s%s%sn",60,98,114,62) to print the string you want "<br>"? I haven't used awk in a while, but I recall doing something similar. Quote Link to comment Share on other sites More sharing options...
Casper Posted February 12, 2009 Author Report Share Posted February 12, 2009 Just like you did with the [, it doesn't work if you surround the operator with some backslashes? Like "/<br>/"? That's usually the escape character to ignore operators right?Edit: too late, by the time I came back and posted, you already got a solution!I think you're right. I think using "/<br>/" would work. But it was a lot less code to use <pre> once instead.For anybody interested, here's the finished working script:#!/bin/ksh## Set Environmentumask 022LOGDIR=/log_file_directoryLOGFILE=$LOGDIR/disk_usage.htmlexport MAILTO='jdoe@email.com,jblow@email.com,test@email.com'export CONTENT=$LOGFILEexport SUBJECT="Daily Disk Usage Report"DATE=`date`## Begin SCRIPT# Validationsif [ ! -d $LOGDIR ]then echo "$LOGDIR does not exist, exiting." exit 1ficd $LOGDIRif [ -f $LOGFILE ]then cp $LOGFILE ${LOGFILE}.prev rm $LOGFILEfitouch $LOGFILEif [ ! -f $LOGFILE ]then echo "Unable to create $LOGFILE, exiting." exit 1fichmod 666 $LOGFILE# Main Scriptecho "<html>" >> $LOGFILEecho "<pre>" >> $LOGFILEecho "Date executed: $DATE " >> $LOGFILEecho " " >> $LOGFILEecho "Daily Disk Usage Report" >> $LOGFILEecho "*************************************" >> $LOGFILEecho "Filesystem Total Used Available Capacity Mount" >> $LOGFILEdf -Pm | sort +4rn | awk '{printf "%-22s %-15s %-15s %-15s %-10s %s\n", $1, $2, $3, $4, $5, $6}' >> $LOGFILEecho "</pre>" >> $LOGFILEecho "</html>" >> $LOGFILE## Email results( echo "Subject: $SUBJECT" echo "MIME-Version: 1.0" echo "Content-Type: text/html" echo "Content-Disposition: inline" cat $CONTENT) | /usr/sbin/sendmail $MAILTOIt runs df -Pm to get the disk usage info, then sorts it so the highest % used is at the top, prints labels for the columns, formats the columns, then emails it. It checks to make sure the LOGDIR is there. If there is already a LOGFILE, it renames it to .prev and touches the new LOGFILE. Quote Link to comment Share on other sites More sharing options...
Disclaimer Posted February 12, 2009 Report Share Posted February 12, 2009 Who's JDoe, and how'd they get an address at email.com?Ohh, you ninjaedit'd it to add more you sneaky bastard. Quote Link to comment Share on other sites More sharing options...
flounder Posted February 12, 2009 Report Share Posted February 12, 2009 The only suggestion I would give is to set it so that the log file is appended with the system date. Then for each time its run, instead of renaming to .prev just have it check for a file with the current system date and if that doesnt exist then create the file with the current system date. This would allow you to historically track utilization and graph it if you ever wanted not to mention that appending the date to the filename is always helpful.. Just a thought. Quote Link to comment Share on other sites More sharing options...
Casper Posted February 12, 2009 Author Report Share Posted February 12, 2009 The only suggestion I would give is to set it so that the log file is appended with the system date. Then for each time its run, instead of renaming to .prev just have it check for a file with the current system date and if that doesnt exist then create the file with the current system date. This would allow you to historically track utilization and graph it if you ever wanted not to mention that appending the date to the filename is always helpful.. Just a thought.We don't want to keep copies. We use Nimbus for statistics tracking. This is just to send a daily report. We have a problem with disks filling up. This is the Oracle box, so archive logs have a tendency to get a bit out of hand when huge batch jobs are ran. This script is just to alert us of the disks running out of space. We have alerts set at 90% and 95%, but this script will give us more of a heads up. I have it running at 7a every day so it'll be in my email when I get to work. You're idea would be great if we weren't already using Nimbus. Quote Link to comment Share on other sites More sharing options...
flounder Posted February 12, 2009 Report Share Posted February 12, 2009 We don't want to keep copies. We use Nimbus for statistics tracking. This is just to send a daily report. We have a problem with disks filling up. This is the Oracle box, so archive logs have a tendency to get a bit out of hand when huge batch jobs are ran. This script is just to alert us of the disks running out of space. We have alerts set at 90% and 95%, but this script will give us more of a heads up. I have it running at 7a every day so it'll be in my email when I get to work. You're idea would be great if we weren't already using Nimbus.Ah gotcha.. yeah oracle logs can be a big bitch.. I used to have the servers set up to page me (yeah, actual pager) back when I ran the labs at UD for various performance issues. I had the servers and the firewalls doing a round robin checks on each other just in case one actually crashed in which case I would get an page also. The shady part was that I also had cron jobs set to page me at certain times during my classes so if I was bored, I had an excuse to leave class without re-percussions. Since I worked for the engineering dept, they knew I had to go when the pager went off. Quote Link to comment Share on other sites More sharing options...
jon_SV650 Posted February 12, 2009 Report Share Posted February 12, 2009 We don't want to keep copies. We use Nimbus for statistics tracking. This is just to send a daily report. We have a problem with disks filling up. This is the Oracle box, so archive logs have a tendency to get a bit out of hand when huge batch jobs are ran. This script is just to alert us of the disks running out of space. We have alerts set at 90% and 95%, but this script will give us more of a heads up. I have it running at 7a every day so it'll be in my email when I get to work. You're idea would be great if we weren't already using Nimbus.dude you should use nagios (http://www.nagios.org/) to monitor all of that. You can setup different services to check a million different things, then page/email you if something were to go down....but you would need to either install on that server or get a separate one to run it, it also has a few third party web interfaces that are great for configuring it if you dont want to keep editing files....its a great app! Quote Link to comment Share on other sites More sharing options...
Casper Posted February 12, 2009 Author Report Share Posted February 12, 2009 dude you should use nagios (http://www.nagios.org/) to monitor all of that. You can setup different services to check a million different things, then page/email you if something were to go down....but you would need to either install on that server or get a separate one to run it, it also has a few third party web interfaces that are great for configuring it if you dont want to keep editing files....its a great app!Nimbus > NagiosAt least in my opinion. Quote Link to comment Share on other sites More sharing options...
jon_SV650 Posted February 12, 2009 Report Share Posted February 12, 2009 Nimbus > NagiosAt least in my opinion.well i can't disagree, ive never used nimbus...im all about the free open source stuff that you can write your own plugins etc for.are you able to that with nimbus? i have might have to give it a try Quote Link to comment Share on other sites More sharing options...
12oclocker Posted February 13, 2009 Report Share Posted February 13, 2009 We don't want to keep copies. We use Nimbus for statistics tracking. This is just to send a daily report. We have a problem with disks filling up. This is the Oracle box, so archive logs have a tendency to get a bit out of hand when huge batch jobs are ran. This script is just to alert us of the disks running out of space. We have alerts set at 90% and 95%, but this script will give us more of a heads up. I have it running at 7a every day so it'll be in my email when I get to work. You're idea would be great if we weren't already using Nimbus.I write a script to flush my log files every like month or so. Quote Link to comment Share on other sites More sharing options...
wolfman Posted February 13, 2009 Report Share Posted February 13, 2009 I write a script to flush my log files every like month or so.You only flush your logs once a month?......ewwwww Quote Link to comment Share on other sites More sharing options...
cmoosego Posted February 13, 2009 Report Share Posted February 13, 2009 you tech guys make my freakin head hurt.... I'll stick to swinging a hammer and building stuff that I can see.... but I'm glad you guys are around to figure this complex shit out.... Quote Link to comment Share on other sites More sharing options...
skrewloose Posted February 13, 2009 Report Share Posted February 13, 2009 I like zabbix for monitoring .... had some experience with nagios and didn't think I could do enough with it, with what little time I had to get something going on all the desperate OSes in the environment... good to see there are others that live in the CLI .... Quote Link to comment Share on other sites More sharing options...
ReconRat Posted February 13, 2009 Report Share Posted February 13, 2009 you tech guys make my freakin head hurt.... I'll stick to swinging a hammer and building stuff that I can see.... but I'm glad you guys are around to figure this complex shit out....Yeah, the Geeks come out... and here I thought I was nearly all alone. Guess again. Quote Link to comment Share on other sites More sharing options...
max power Posted February 13, 2009 Report Share Posted February 13, 2009 Quote Link to comment Share on other sites More sharing options...
Casper Posted February 13, 2009 Author Report Share Posted February 13, 2009 I write a script to flush my log files every like month or so.We never delete the logs. They're written to SQL Server DBs. Quote Link to comment Share on other sites More sharing options...
Casper Posted February 13, 2009 Author Report Share Posted February 13, 2009 well i can't disagree, ive never used nimbus...im all about the free open source stuff that you can write your own plugins etc for.are you able to that with nimbus? i have might have to give it a tryNimbus is EXPENSIVE. I think we paid around $75k for our setup. We monitor 100+ Windows servers, 5 AIX servers, and a hand full of Linux servers, plus the Oracle and SQL servers. Quote Link to comment Share on other sites More sharing options...
jon_SV650 Posted February 13, 2009 Report Share Posted February 13, 2009 Nimbus is EXPENSIVE. I think we paid around $75k for our setup. We monitor 100+ Windows servers, 5 AIX servers, and a hand full of Linux servers, plus the Oracle and SQL servers.daaaamn!! yeah i think i will stick with nagios..... we monitor about 100 different hosts including servers, routers, etc...and about 300 services (disks, pings, memory, etc) it works great for what we need. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.