Archive for ‘General’

11/12/2010

A batchfile to check the status of Windows services and start them automatically if they have stopped

I deal with several applications on a day to day basis, and I was having problems with one in particular it’s associated windows services stopping for no tangible reason.

I therefore devised a batchfile to check the status of each of the services in turn, and start them if they stopped.

@echo off
:start
@ping 127.0.0.1 -n 60 -w 1000 > nul
@echo Checking if Control Manager is running @for /f "tokens=3" %%a in ('sc query "KmpCM"^|find "STATE"') do (
@if %%a==4 goto runningCM
@goto stoppedCM
)
:stoppedCM
net start KmpCM
:runningCM
@echo OK.
@echo.
@ping 127.0.0.1 -n 60 -w 1000 > nul
@echo Checking if Extension Manager is running @for /f "tokens=3" %%a in ('sc query "KmpEM"^|find "STATE"') do (
@if %%a==4 goto runningEM
@goto stoppedEM
)
:stoppedEM
net start KmpEM
:runningEM
@echo OK.
@echo.
@ping 127.0.0.1 -n 60 -w 1000 > nul
@echo Checking if Message Server is running @for /f "tokens=3" %%a in ('sc query "KmpMS"^|find "STATE"') do (
@if %%a==4 goto runningMS
@goto stoppedMS
)
:stoppedMS
net start KmpMS
:runningMS
@echo OK.
@echo.
@ping 127.0.0.1 -n 60 -w 1000 > nul
@echo Checking if Offline Manager is running @for /f "tokens=3" %%a in ('sc query "KmpOM"^|find "STATE"') do (
@if %%a==4 goto runningOM
@goto stoppedOM
)
:stoppedOM
net start KmpOM
:runningOM
@echo OK.
@echo.
@ping 127.0.0.1 -n 60 -w 1000 > nul
@echo Checking if Permission Manager is running @for /f "tokens=3" %%a in ('sc query "KmpPM"^|find "STATE"') do (
@if %%a==4 goto runningPM
@goto stoppedPM
)
:stoppedPM
net start KmpPM
:runningPM
@echo OK.
@echo.
@ping 127.0.0.1 -n 60 -w 1000 > nul
@echo Checking if Scheduler is running
@for /f "tokens=3" %%a in ('sc query "KmpSH"^|find "STATE"') do (
@if %%a==4 goto runningSH
@goto stoppedSH
)
:stoppedSH
net start KmpSH
:runningSH
@echo OK.
@echo.
@ping 127.0.0.1 -n 60 -w 1000 > nul
@echo Checking if Service Manager is running @for /f "tokens=3" %%a in ('sc query "KmpSM"^|find "STATE"') do (
@if %%a==4 goto runningSM
@goto stoppedSM
)
:stoppedSM
net start KmpSM
:runningSM
@echo OK.
@echo.
@goto start

Advertisements
06/12/2010

New look Chocolate Hedgehog website

Haven’t posted for a few days because I’ve been busy developing a new look for the website.

I’ve tried to give it a more striking and memorable appearance using some jQuery and CSS elements.

http://www.chocolatehedgehog.co.uk

23/11/2010

Batch file to perform SSH commands and transfer files from Windows to Linux

At my place of work, I routinely have to update firmware and database files from our office Windows PCs to ARM linux devices.

This used to involve connecting to the mini PC using PuTTY, killing a process, then logging in using an FTP client to transfer files across, finally rebooting the Linux device.

That is, until I automated the process with plink.exe and pscp.exe (available from the PuTTY download site) and a Windows batchfile:


@set /p IP="Enter the IP address of the Linux device, and press enter:"
@echo.
@echo Killing processx
@echo.
@C:\Path\plink.exe -ssh -pw password user@%IP% killall processx
@ping %IP% -n 2 -w 1000 > nul
@ping %IP% -n %1% -w 1000> nul
@echo Transferring FileX
@C:\Path\pscp.exe -scp -pw password C:\Path\FileX user@%IP%:/linux/path
@echo.
@echo Rebooting Controller at %IP%
@C:\Path\plink.exe -ssh -pw password user@%IP% reboot
@echo.
@echo Your Linux device will be back online shortly.
@echo.
@PAUSE;

In this example, you’d have to have your batch file, FileX, plink.exe and pscp.exe in the C:\Path\ directory on your Windows PC. Obviously substitute your real SSH username and password in for ‘user’ and ‘password’.

17/11/2010

Saving individual pages from a .pdf, as a new .pdf

Ever needed to save a specific page of a .pdf document as a new, separate .pdf?

Apparently you can do it if you purchase a full Adobe software licence, or you could use this free online tool:

http://www.splitpdf.net

Tags:
13/11/2010

Welcome! (introduction)

As a web developer I have been learning HTML, CSS, PHP, JavaScript and SQL (both MySQL and MSSQL) as I go along, and I thought it was about time to start keeping a record of useful tidbits and snippets of code so, if nothing else, I can refer back to it myself.

As with every ‘normal’ person, my knowledge of HTML, PHP etc. is far from complete. Don’t get me wrong – I’ve read some books and know a fair bit, but I’m not yet a walking reference manual. I find when I need a specific function on a web page, say PHP pagination, I’ll type it into my generic search engine. This will often lead me to visit blogging pages just like this one, where someone just like me has kindly posted a tutorial, code snippet, sometimes even link to an example. I then adapt what I find to use on the specific page I am working on.

If all goes well, then soon people like me will be finding and using this blog in a similar way. If nobody finds it, then it will serve as useful record of my work for me.