CRON

December 16, 2009 Leave a comment

If you have ever worked on a UNIX/UNIX-like OS, Im’ pretty sure how quick you’ll get to admire those amazing and powerful OS features and command lines. And if you also work on Windows and do a lot of automation, I’m sure you’ll love it that sometimes you wish you had that feature in Windows. One of my favorite is CRON, the time-based job scheduler in Unix-like computer operating systems. Yes, I know we have the good old Task Scheduler in Windows, but I really like how you can configure a complex scheduled job in one line of text with CRON.

It maybe a little over the top to create something like this on Windows, considering that Task Scheduler will be able to achieve the same goal. But I got this really strange error in one of my scheduled job that kept me head scratching for days. The job will just show in running state, it will never run and the “end task” option is greyed out so the only fix is to restart the scheduler service. I normally try to investigate the problem and find the root cause but this time I had enough that it made me decide to create the scheduler I want – one with a CRON-like syntax. And luckily, I dont have to. QUARTZ.NET, a .NET open source library already has this functionality. So I just need to build my program on top of it.

With the help of QUARTZ, I created a windows service that reads the configuration files for scheduled jobs. The time schedule uses a CRON like syntax.

Below is a section in the AppConfig where you can schedule the jobs:


 <section name="jobs"
    type="Assyst.JobProcessor.Scheduler.JobConfigurationHandler, Assyst.JobProcessor.Scheduler"/>

 <jobs>
 
  <job name="MyJob"
    type="MyProject.MyJobClass, MyProject"
    schedule="30 0/1 * * * ?" /> 
 </jobs>

JobConfigurationHandler is an implementation of IConfigurationSectionHandler interface, which reads the AppConfig for the scheduled jobs. And MyJobClass is a class which derives from an abstract class, AssystJobBase, which is simply a template class to easily create job class. This abstract class implements the IAssystJob Interface which is the only requirement for a class to be configured as scheduled job. The schedule attribute obviously is where you put your CRON-like syntax for scheduling the job.

I have temporarily uploaded the project here but it will soon be on my GITHUB repository.

Categories: C# Tags: , , ,

Monitor UNIX Disk Space

November 1, 2009 Leave a comment

A simple script for monitoring UNIX Disk space usage that sends an email alert if % usage is above the alert level.

THRESHOLD=90

RECIPIENTS="admin@company.com.qa"
DISK_ALERT_LOG="/tmp/diskalert.log"
DISK_ALERT_MAIL="/tmp/diskalert.mail"

touch ${DISK_ALERT_LOG}

df -h | awk '{if(NR>1){print$6" "$5}}' | while read output
do
  USAGE=`echo $output | sed 's/\%//' | awk '{print$2}'`
  MOUNT=`echo $output | awk '{print$1}'`
  if [ ${USAGE} -gt ${THRESHOLD} ];
  then
    echo "${MOUNT} = ${USAGE}%" >> ${DISK_ALERT_LOG}
  fi
done

cat ${DISK_ALERT_LOG}

if [ -s ${DISK_ALERT_LOG} ];
then
  echo "To: ${RECIPIENTS}" > ${DISK_ALERT_MAIL}
  echo "From: ${HOSTNAME}" >> ${DISK_ALERT_MAIL}
  echo "Subject: Disk space alert on ${HOSTNAME}" >> ${DISK_ALERT_MAIL}
  echo >> ${DISK_ALERT_MAIL}
  cat ${DISK_ALERT_LOG} >> ${DISK_ALERT_MAIL}
  cat ${DISK_ALERT_MAIL} | /bin/mail ${RECIPIENTS}
fi

rm ${DISK_ALERT_LOG}
Categories: Scripts, UNIX Tags: , ,

DTC Error

October 5, 2009 Leave a comment

Yesterday I was installing windows 2003 cluster on VMWare machines. Then I got this weird error message while I was configuring MS DTC (Distributed Transaction Coordinator) cluster application. The application and cluster resource was configured successfully but when I fail over, MS DTC failed to start and looking at the event logs gives me this error message:

The MS DTC log file is an incompatible version

This is really strange since the cluster nodes are exactly of the same VMWare image. A quick google shows me only few results, mostly from MS site. The first site does have the usual MS instructions – “Reinstall/Install”, which in my case doesn’t resolved the problem. The other sites are just lists of event ids and some tables which doesn’t help at all. So it seems that I have to use a bit more of my google-fu. And sure enough changing the search key words to “msdtc cluster failover error” yields more interesting results but in a quite overwhelming numbers (Maybe my google-fu is still not that strong enough). Going over through most of the sites and forums, a common advice is to delete and reset the MSDTC logs using the following instructions:

Delete the MSDTC.LOG file from %systemroot%\system32\Msdtc directory

Reset the logs:

msdtc -resetlogs

Unfortunately it still did not fix the problem. Until I checked the MSDTC properties from the “Component Services” console and noticed this:

DTC Property

DTC logs seems to be stored in the quorum disk if clustered. And since this is just a new installation, on a VMWare environment and will be used for testing purposes (If you are having the same issue on a production server, I strongly suggest that you contact Microsoft Premiere Support first before doing this stunt), I went on and deleted the log file stored in the quorum disk and reset the DTC log. And viola, I got my cluster working and ready for SQL 2005 Cluster installation.

The Git Effect

September 23, 2009 Leave a comment

git-logoMany developers, including those notable persons over the .NET community have been moving their open source projects to Git and Github lately. (Git is a free and open source, distributed version control system. And Github is an online project hosting that uses Git as its revision control system.)

Rob Conery’s SubSonic is now on Github. As of September 14, 2009, Sharp Architecture’s source repository is now being hosted at http://Github.com/codai/Sharp-Architecture. Oren Eini (aka Ayende Rahien) has recently moved to Git, not only he is a famous NHibernate developer and creator of RhinoMocks, but interestingly a long time user of SubVersion and a developer of SvnBridge (SvnBridge allows you to use TortoiseSVN and other Subversion clients with Team Foundation Server).

I’ve been using SubVersion for my hobby projects and I consider it as an excellent version control system. Far better than VSS - which unfortunately my company is still using.

But is there any compelling reason to try Git or even completely switch from SubVersion (or any other version control system) and not just because it’s what the “Kool Kids” are using? TBH, I really don’t know. But there is one thing that I am sure of - the recent noise about Git is something a developer cannot ignore (at least for the curious ones). And Aaron Jensen is right, maybe I heard  it enough that I want to give it a try and see why they think it’s so great.

And sure enough I did. I have setup a GitHub account to host my hobby projects. Currently I have only my “splotter-common” project uploaded. As of now, the project contains the common code base of my own implementation (inspired by Oren’s RhinoCommons) of Data Persistence, Repository and Unit of Work pattern using NHibernate, Linq for NHibernate and Linq to SQL.

Categories: Version Control Tags: ,

Learning Photography 101

September 8, 2009 Leave a comment

sx10isAfter struggling with our old, broken shutter button, 7 megapixel Sony compact digital camera, we decided to buy the Canon SX10 IS. A point and shoot superzoom camera with a whooping 20x optical zoom. We chose this camera because it has full sets of manual controls that can help me learn the basics of digital photography without spending for a more complex, bigger and expensive DSLRs.

I did not expect learning photography would be this fun and interesting. Somehow, it has already changed the way we capture those special moments. Applying the Rules of Thirds, playing with the Depth of Field to shoot Bokeh, shooting a moving subject by Panning.

But then recently, I just found out, that sometime back I was caught by an extremely fast Shutter Speed. But sadly, it wasn’t from my own camera…

radar

They say digital photography is expensive. Well, I guess I just found out. The picture cost me 500 Qatari Riyals, equivalent to about 137 US $ and about 6,686 Philippine Pesos.