Posts

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.

Useful RDP Keyboard Shortcuts

CTRL+ALT+END : Open the Microsoft Windows Security dialog box (CTRL+ALT+DEL) ALT+PAGE UP : Switch between programs from left to right (CTRL+PAGE UP) ALT+PAGE DOWN : Switch between programs from right to left (CTRL+PAGE DOWN) ALT+INSERT : Cycle through the programs in most recently used order (ALT+TAB) ALT+HOME : Display the Start menu (CTRL+ESC) CTRL+ALT+BREAK : Switch the client computer between a window and a full screen ALT+DELETE : Display the Windows menu CTRL+ALT+Minus sign : Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing ALT+PRINT SCREEN on a local computer (ALT+PRT SC) CTRL+ALT+Plus sign : Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer (PRT SC)

Add Multiple IP Addresses to a Windows Server From the Command Line

Say you want to add 192.168.1.2 through to 192.168.1.14 with a /28 netmask (255.255.255.240). for /L %a in (2,1,14) do netsh in ip add address "Local Area Connection" 192.168.1.%a 255.255.255.240 Which is: for /L (tell for that it's a range of numbers) %a in (placeholder variable) (start, step, end) (self explanatory) do (command goes here) This page FOR /L has more detail and is part of this very useful site ss64.com

Troubleshooting Windows RDP Connection

To cut a long story short, the first thing to do is try and create an RDP connection locally, to rule out external firewalling and routing. The problem was that even though "Terminal Services" was up and running, "Don't allow connections to this computer" was selected under "System Properties" -> "Remote". Selecting "Allow connections from computers running any version of Remote Desktop (less secure)" resolved the problem. Not exactly intuitive...