Posts

Showing posts from 2013

FreeBSD: Increment the serial number of every zone file by 1

I needed to increment the serial number of every zone on a master server to trigger an update to a new slave. Since I know next to nothing about csh the easiest way was the following one liner in sh: for i in `ls -1 | xargs`; do j="`awk '$3 == "Serial"{print $1 + 1}' $i`"; sed -i "" "s/^[[:digit:]]\{10\}\([[:space:]]\;[[:space:]]Serial\)/$j\1/" $i; echo -n "$i "; rndc reload $i; sleep 2; done

Linux: Display Hard Drive Serial Number For Each Device

I needed to physically replace a drive in an array and to do that I needed the serial number of the drive. for i in $(awk '/sd[a-z]+$/ { print $4 }' /proc/partitions | sort); do printf "%-5s%s\n" $i "$(smartctl -i /dev/$i | grep Serial | sed 's/^[^:]\+:[[:space:]]\+\([[:alnum:]\-]\+\)/\1/')"; done sda  WD-WXL708065381 sdaa Z1F1HLJN sdb  Z1F0YPP2 sdc  Z1F136GZ sdd  Z1F0X9X7 sde  Z1F136DE sdf  Z1F1HM91 sdg  9WM66QZP sdh  9WM73LV3 sdi  9WM6JLJT sdj  9WM73600 sdk  9WM6Y6B5 sdl  Z1F1HLMY sdm  9XH024P1 sdn  9XH025HS sdo  9XH01Y60 sdp  9XH025PY sdq  9WM6KMP3 sdr  9WM6PESG sds  9WM6QFZP sdt  9WM66ZY9 sdu  9WM6SAL6 sdv  Z1F1LVP2 sdw  Z1F11NKT sdx  Z1F11LB7 sdy  Z1F11NVV sdz  Z1F11MEF

Postfix: Delete from queue by header content

Normally you can use mailq to delete by sender or receipient, but postfix doesn't really have any tools to delete based on any other content in the email. Following is a quick and nasty one liner that I came up with to help a customer out. One of the websites he hosted had been compromised and was being used to send out spam. The only thing the emails had in common was a header. X-PHP-Originating-Script: 33:index2Xv6C.php for i in $(mailq | tail -n +2 | awk 'BEGIN { RS = "" } $1 ~ /^[[:alnum:]]/ { print $1 } ' | tr -d '*!' ); do if [[ $(postcat -hq "$i" | grep index2Xv6C.php) ]] ; then postsuper -d $i; fi; done It wasn't particularly quick but it didn't cause much load either.

Cron jobs running in UTC timezone on Virtuozzo 4.0 containers

Symptoms / etc / crontab showed that cron . daily should be running at 05:08 in the morning, but a grep of the syslogs showed that it was running at 18:08 at night. # grep daily / etc / crontab 8 5 * * * root test -x / usr / sbin / anacron || ( cd / && run-parts --report / etc / cron . daily ) # grep daily / var /log/ syslog . 0 Mar 25 18:08:01 vps /USR/SBIN/CRON [ 8110]: (root) CMD (test -x / usr / sbin / anacron || ( cd / && run-parts --report / etc / cron . daily )) The 'date' command showed the right timezone. # date Tue Mar 26 16:56:00 NZDT 2013 Cause / etc / timezone was malformed by having the the local timezone  appended, instead of overwritten, in the final stages of customisation  by Virtuozzo, when the container was installed. # cat / etc / timezone   Etc /UTC Pacific/Auckland Solution Removing the bogus "Etc/UTC" line from / etc / timezone fixed the problem.