rblog

Excel 2007 – Conditional Formatting: Compare 3 columns with text – find unique values

Raised a question at Superuser.com which got answered in just a few seconds, see http://superuser.com/questions/488367/excel-2007-conditional-formatting-compare-3-columns-with-text-find-unique-v

The magic was achieved by using Conditional Formatting and adding a formula =COUNTIFS($A:$C;A1)<=2. Still having some issues, seems to be caused by me having imported the text from csv-files. Might be that if all had been typed in it would have worked without errors. Maybe need a newer version of Excel…

Windows .bat-file that stops and starts services, kills processes and rename files

Needed to automate rotation of the IBM WebSphere HTTP Server plugin log-file, and in addition I needed to make sure that all processes of rotatelogs.exe have been stopped. This due to a bug in Apache for Windows, at least old versions, where the rotatelogs.exe processes does not end while restarting Apache. In addtion I wanted to make the script working for both our IBM HTTP Server v 6.1 and 7.0 servers. Could off course just edit the script based on which server, but hey…coming from a Linux environment and using bash-scripting, I wanted to test out what could be done on Windows.

Must admit that I hate the GOTO’s and also I find the scripting language itself a pain. I realize that I need to dive into the Powershell, see this table on Wikipedia showing what I really love – commands equal to Unix/Linux, yeah man!!!

Anyhow, here is the script I have created.


:: See https://apps.klp.no/confluence/display/FILENET/Administration+-+IBM+HTTP+Server+%28Apache%29#Administration-IBMHTTPServer%28Apache%29-Logrotation
ECHO off
:: Get the hostname of server as a variable
:: http://stackoverflow.com/questions/998366/how-to-store-the-hostname-in-a-variable-in-a-bat-file
FOR /F "usebackq" %%i IN (`hostname`) DO SET _HOSTNAME_=%%i

:: ***************************
:: Stop the IBM HTTP Server 
:: ***************************
:: Which version is installed
:: http://stackoverflow.com/questions/9445223/how-to-check-in-windows-xp-if-the-service-is-not-installed-using-batch-file
sc query IBMHTTPServer7.0  | find "IBMHTTPServer7.0" >nul
IF ERRORLEVEL 1 GOTO STOP_AS_61SERVICE
ECHO Stopping service named IBMHTTPServer7.0
sc stop IBMHTTPServer7.0 >nul
GOTO END_OF_STOP
:STOP_AS_61SERVICE
:: Is version 6.1 installed?
ECHO Did not find IBMHTTPServer7.0 service, trying IBMHTTPServer6.1 
sc query IBMHTTPServer6.1  | find "IBMHTTPServer6.1" >nul
ECHO Stopping service named IBMHTTPServer6.1
sc stop IBMHTTPServer6.1 
GOTO END_OF_STOP
:NO_WEB_SERVICE
ECHO Not able to find the IBM HTTP Service
GOTO TotalFailure
:END_OF_STOP

:: Sleep for 30 seconds
:: http://stackoverflow.com/questions/4317020/windows-batch-sleep
ECHO 
ECHO Sleep for 30 seconds ....
ping -n 30 127.0.0.1 >nul


:: ***************************************
:: Kill all instances of rotatelogs.exe
:: ***************************************
ECHO Kill all pending rotatelogs.exe processes
taskkill /F /IM rotatelogs.exe 2>nul

:: ***************************************
:: Rotate the http_plugin.log
:: ***************************************
cd D:\HTTPServer\Plugins\logs\ 2>nul
IF ERRORLEVEL 1 GOTO IBM_HTTP_61_FOLDER
GOTO Rename
:IBM_HTTP_61_FOLDER
ECHO cd D:\HTTPServer61\Plugins\logs\
cd D:\HTTPServer61\Plugins\logs\
IF ERRORLEVEL 1 GOTO TotalFailure

:Rename

for /f "tokens=5 delims=\" %%I in ('dir /S /B http_plugin.log') do for %%A in (%%~I) do (
	ECHO Name of folder where http_plugin.log is found: %%A
	cd %%A
	ren http_plugin.log http_plugin-%date:~0%.log
	IF ERRORLEVEL 1 GOTO RENFAIL
	ECHO File has been renamed to http_plugin-%date:~0%.log
	cd ..
)
GOTO RENAME_END
:RENFAIL
ECHO Failed to rename http_plugin.log, exit
GOTO TotalFailure
:RENAME_END

:: ****************************
:: Start the http-server
:: ****************************
:: Is version 7 installed?
sc query IBMHTTPServer7.0  | find "IBMHTTPServer7.0" >nul
IF ERRORLEVEL 1 GOTO START_AS_61SERVICE
ECHO Starting service named IBMHTTPServer7.0
sc start IBMHTTPServer7.0
GOTO END_OF_START
:START_AS_61SERVICE
:: Is version 6.1 installed?
:: If 6.1 is not installed, the stop will got to totalfailuere
ECHO Did not find IBMHTTPServer7.0 service, trying IBMHTTPServer6.1 
sc query IBMHTTPServer6.1  | find "IBMHTTPServer6.1" >nul
ECHO Starting service named IBMHTTPServer6.1
sc start IBMHTTPServer6.1 
:END_OF_START
:: Return to current directory
:: http://weblogs.asp.net/whaggard/archive/2005/01/28/get-directory-path-of-an-executing-batch-file.aspx
cd /d %~dp0
exit /b

:TotalFailure
:: Return errorcode
:: http://www.robvanderwoude.com/errorlevel.php
cd /d %~dp0
ECHO Failed, have to exit
ECHO 1 | CHOICE /C:1234567890 /N

Beautiful – but not right

Pictures taken yesterday when at my in-laws. The first frost has covered my car, -3 when we got up in the morning.

The leafes have turned yellow and started to fall of.

View towards the neighbor, seems beautiful, but … and there is a big but … the crop has not been harvested, it has been to wet this year, and to cold.

Samewise here, nice, but the same but. I do not like it…even some think that the climate changes might shake the earth.

Verify Windows service status from command line

The command to use is sc. First you need to know that every service has a display name and a service name. I banged my head into the wall until I realized that I could just type sc query to list all. Actually I typed sc query >> result.txt
Then I found the real name of the IBM HTTP Server 6.1-service and I could type


D:\HTTPServer61\bin>sc query IBMHTTPServer6.1
SERVICE_NAME: IBMHTTPServer6.1
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN))
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0