corrupted Windows Update causes full disk

During the last week I had alot of Windows 2008 R2 server with a full disk. The C:\windows\temp was filled with cab_XXXX_X files. They are save to delete but this will not fix the cause of this. Because of some Windows Update corruption there will be so hugh log files in C:\windows\logs\cbs. I havent tried to simply delete them. What i did instead:
Regarding this (yes check_mk is installed on that server) posting I fired up an elevated command prompt and did

sfc /scannow

… which fixed my problem on some server after hiting 100% … others reported

Beginning system scan.  This process will take some time.

Beginning verification phase of system scan.
Verification 10% complete.

Windows Resource Protection could not perform the requested operation.

What is the problem here? The disk is simply to full to perform this action.

Update 1:
Turns out that you may need to delete the logs in c:\windows\logs\cbs manually

Update 2:
The sfc /scannow helped to get the Windows Update back to work

fill PDF forms with powershell

there are some tutorials on how to create pdf files with powershell like this one here: http://www.powershell.nu/2009/09/08/scripting-pdf-documents-through-powershell/

i had some troubles to open and change an already created pdf – here is how it needs to be done

# load the pdf library
[System.Reflection.Assembly]::LoadFrom("itextsharp.dll") 

# read the form
$reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList "form.pdf" 

# create a new file with the read content
$writer = New-Object iTextSharp.text.pdf.pdfstamper($reader, [System.IO.File]::Create("filled-form.pdf")) 

# set content to a form field
$writer.AcroFields.SetField('key','value') 

# close the filestream
$writer.Close() 

this will work for unencrypted pdf files

delete comments on nagios hosts/services which are not critical anymore

As i googled around and hadnt found anything for Nagios 3.x i decided to write that script myself. It will only delete the comments of checks which are okay again since Nagios is not taking care of that.

#!/bin/bash
# Deletes comments from host and services no longer in critical status. Developed for Nagios 3.x
# Author: Mathias Decker, <mathias@itgweb.de>
# Date: 27/12/2011


# Global Vars
NAGIOS_CMD='/var/nagios/rw/nagios.cmd'
LOG='/var/nagios/status.dat'


# Remove no longer used service comments
# explanation: convert blanks -> get all comments and 3 lines up -> get rid of tabs -> make 1 line not for -> skip the other 'blocks'
for c in $(cat $LOG | sed 's/ /+blank+/g' | grep -B3 "^ comment_id=" | sed 's/	//g' | sed ':a;N;$!ba;s/\n/;/g' | sed 's/--/\n/g')
do
        comment_id=$(echo $c | sed 's/;/\n/g' | grep "^comment_id" | sed 's/comment_id=//g')
        host_name=$(echo $c | sed 's/;/\n/g' | grep host_name | sed 's/host_name=//g')
        service_name=$(echo $c | sed 's/;/\n/g' | grep service_description | sed 's/service_description=//g')

        if [ ! -z $service_name ]
        then
                service_name=$(echo $service_name | sed 's/+blank+/ /g') #get back the blanks
                host_name=$(echo $host_name | sed 's/+blank+/ /g')
                state=$(cat $LOG | grep -B15 current_state | grep "$host_name$" -A14 | grep "=$service_name$" -A13 | grep "current_state=" | sed 's/	current_state=//g') # theres a tab in front of current_state
                # get all services which got state=0 which is okay
                if [ $state = 0 ]
                then
#                       echo "$host_name - $service_name - $comment_id - '$state'" # uncomment for debugging
                        NOW='date +%s'
                        echo "[$NOW] DEL_SVC_COMMENT;$comment_id;$NOW" >> $NAGIOS_CMD # this will get rid of the comment
                fi
        fi
done

#remove no longer used host comments
for c in $(cat $LOG | sed 's/ /+blank+/g' | grep -A3 "hostcomment" | sed 's/	//g' | sed ':a;N;$!ba;s/\n/;/g' | sed 's/--/\n/g')
do
        comment_id=$(echo $c | sed 's/;/\n/g' | grep "^comment_id" | sed 's/comment_id=//g')
        host_name=$(echo $c | sed 's/;/\n/g' | grep host_name | sed 's/host_name=//g')
        if [ ! -z $host_name ]
        then
                host_name=$(echo $host_name | sed 's/+blank+/ /g')
                state=$(cat $LOG | grep -B15 current_state | grep "$host_name$" -A14 -B1 | grep "hoststatus" -A14 | grep "current_state=" | sed 's/	current_state=//g')
                if [ $state = 0 ]
                then
#                       echo "$host_name - $comment_id - $state"
                        NOW='date +%s'
                        echo "[$NOW] DEL_HOST_COMMENT;$comment_id;$NOW" >> $NAGIOS_CMD
                fi
        fi
done

resize images in a single line

you got a bunch of photos you wanna resize in width and height … lets say 800px will be enough. Fire up a shell, cd in the directory where your photos stored.

for i in $(ls -1 *.jpg | sed 's/ /;/g'); do 
   convert -resize 800x800 "$(echo $i | sed 's/;/ /g')" "/path/to/destiantion/$(echo $i | sed 's/;/ /g')"
done

The “sed ‘s/ /;/g'” is to handle filenames with a blank.

get progress of dd

Guess you clone a disk with dd, which can take a long time. After some hours you like to know how far has the program been gone so far. Open up a new shell and put in

$ kill -USR1 $(prgep dd)

… and you gonna get something like

xxx bytes (xx MB) copied, xxx s, x MB/s

… and the dd progress doesnt get killed.