[Linux] gawk stuff
Kwan Lowe
linux@flux.org
Fri, 18 May 2007 14:26:44 -0400 (EDT)
While troubleshooting a problem at work I had to make a script that grabs some log
information from a remote server. There's probably a simpler way to do this, but
this is what I came up with:
#!/bin/sh
YESTERDAY=`date +%s | awk '{printf "%s%s\n", strftime("%m",($0-86400)),
strftime("%d",($0-86400) );}'`
REPORT_DIR=/var/www/html/nmon_all
echo Copying reports to Report Web Page
for SERVER in vm-web-01 vm-web-02 vm-web-03; do
# Copy only the previous day
scp -rp vm-loghost:reports/${SERVER}/*${YESTERDAY}.nmon
${REPORT_DIR}/${SERVER}/
done
No point to this post except that I thought the date/time handling stuff of gawk was
pretty cool. Some years ago I saw a similar script on a Solaris machine... Except
that script required some pretty heavy lifting to check the day of the week, month,
etc. and do subtractions based on it. With all the DST stuff recently, I doubt that
those old scripts would continue to work.
--
* The Digital Hermit http://www.digitalhermit.com
* Unix and Linux Solutions kwan@digitalhermit.com