This blog contains experience gained over the years of implementing (and de-implementing) large scale IT applications/software.

Convert SAP AS Java Trace Timestamp

Sometimes, just sometimes, you wish you could just take a look at the defaulttrace.log or one of the other many log files at the O/S level for an SAP AS Java based system.
Except, it’s not that simple.  Whilst the file is text based, you’re not able to read the date/time stamp that exists on each line.
Well, here’s a simple couple of methods to do this conversion, which is basically converting from the epoch.
The first method is using a pure Korn Shell (KSH) method, useful for converting maybe one or two values:

echo $(date -d “1970-01-01 ${dt:0:10} seconds”)

This second method uses AWK which makes it much better at converting all values by simpling piping in the original file to see the output:

NOTE: Below I’m searching for entries related to “”.
NOTE 2: The below command is all on one line.

cat responses.0.trc | awk -F# ‘/  { print strftime(“%F %T”,substr($4,1,10))”#”$24 }’

Starting and Stopping Individual SAP AS Java Server Processes

Should you need to restart either manually or automatically (via script) a specific AS Java server node, it’s possible to use the sapcontrol tool to provide precise control.

The method detailed below is based on the documentation provided here:
Performs a given control function (EnableProcess/StartProcess, DisableProcess/StopProcess,
SoftStopProcess, ActivateProcess, DeactivateProcess, RestartProcess, SoftRestartProcess,
DumpStackTrace, EnableDebugging, DisableDebugging, IncrementTrace, DecrementTrace) on a given AS
Java process. processname must match a process name in the AS Java process list returned by
J2EEGetProcessList. To perform AS Java instance-wide operations (StartInstance, StopInstance,
RestartInstance, BootInstance, RebootInstance), use processname “all”.
Based on the above information, we can query the AS Java processes for a specific AS Java instance, using the following command line as the sidadm user:

sidadm> sapcontrol -host [host] -nr [sys##] -function J2EEGetProcessList
You should substitute the “host” and “sys##” with the host of your application server (virtual host) and the SAP instance number.
The command will return a list of the processes that the instance is running.
For a 2 node AS Java system, you can see the Server0 and Server1 processes in the list.
To restart Server0 on the AS Java instance use the below command line as the sidadm user:

sidadm> sapcontrol -host [host] -nr [sys##] -function J2EEControlProcess “server0” “RestartProcess”
You should substitute the “host” and “sys##” with the host of your application server (virtual host) and the SAP instance number.
Change “server0” for “server1” if you want to restart server1.
Based on the above restart, you can monitor the restart by using the below command line to see when the restart is completed:
sidadm> sapcontrol -host [host] -nr [sys##] -function J2EEGetProcessList | awk -F, ‘{ if ( $2 != “” && FNR > 5 ){ print “Name: “$2″ttState: “$8″ttStarted: “$9 }}’
You should substitute the “host” and “sys##” with the host of your application server (virtual host) and the SAP instance number.

Netgear ReadyNAS & DynDNS Replacement

With the demise of free DNS services from companies such as DynDNS, I was left with no free method of reliably accessing my Netgear ReadyNAS via the internet.

Before these free services closed down, my ReadyNAS was configured to automatically update it’s IP address to the DynDNS service website, which allowed me to use a DynDNS provided host address (e.g. to access the ReadyNAS no matter what it’s IP address was changed to by my home ISP provider.

When the free service eventually stopped, I decided that I didn’t want to pay for such a small service offering, so I wrote a small script to perform the same sort of service.
The script simply checks my current ISP assigned IP address and compares it to the previous run of the script.  If the IP address has changed between checked, the script sends an email to my email account, which I can then use to access the device by directly entering the IP address into my web browser.

It’s not neat, but it works.
Here’s how I did it.

What you’ll need:
– Root access to your ReadyNAS (you need the SSH addon installed).
– Configure email alerting on your ReadyNAS (do this in FrontView by giving it access to your email provider e.g.

Step 1 – Create the script.

As the root user connected to your ReadyNAS via SSH, use vi to create a small script in the home directory of the root user:

# cd $HOME
# vi check_ip_address

#  Get IP address and mail it to us.
#  Place this script in $HOME/root
#  Call it from crontab.
#——————————————————– user=”ReadyNAS”
email_from=$(grep ‘^from’ /etc/msmtprc | cut -f2 -d’ ‘)
email_addr=`grep email /etc/frontview/alert.conf | awk -F ‘!!’ ‘{ print $2 }’ | awk -F ‘,’ ‘{ print $1 ” ” $2 ” ” $3 }’`

subject=”IP Address Changed” newfile=/tmp/myip.html

# Call a generic site to get our IP.
wget –no-cookies –no-cache –user-agent=”Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36″ –no-verbose –output-document=/tmp/myip.html

# Read output.
myipnew=`awk -F “tt>” ‘{ if($2 ~/./){ sub(/<//,””,$2); print $2} }’ $newfile`
myipold=`cat $oldfile 2>&1`
if [ “$myipnew” != “$myipold” ]; then
  # IP is different to last, so save it and mail it.
  echo “$myipnew” > $oldfile
  mesg=”New IP Address: $myipnew”   headers=”From: $email_fromnTo: $email_addrn”
  full_content=”${headers}Subject: ${subject}n${content}nn$mesg”
  echo -e “$full_content” | /usr/sbin/sendmail -B8BITMIME -f $email_from $email_addr &> /dev/null
  echo “RC: $?”

Set permissions on the script:

# chmod 750 check_ip_address

Step 2 – Schedule the Script.

Add the script to a cron schedule:

# export EDITOR=vi
# crontab -e
30 09 * * * /root/check_ip_address
30 14 * * * /root/check_ip_address

The above schedules the script to run at 09:30am every day, and again at 14:30.
That’s it!

SQL Server Shrink Transaction Log Script

Below is a script that shrinks SQL Server transaction logs tested on SQL Server 2008R2.
Before running the script, you should ensure that you take a transaction log backup of your databases (which obviously means you should have already taken a full backup).  The transaction log backup will free the virtual logs from within the transaction log file.

The script simply tries to shrink the transaction log file by 25% for any databases that are not called “MASTER”, “MODEL”, “MSDB” or “TEMPDB”.

If you wish to shrink logs by more than 25%, either change the script, or run it multiple times until it can’t shrink the logs any further.

NOTE: When executing the script in SQL Management Studio, you should set the results output to “Text”, so that you can see the output of the script.

USE master

DECLARE @database_id    int,
        @database_name  nvarchar(128),
        @file_id        int,
        @file_name      nvarchar(128),
        @size_mb        int,
        @new_size       int;

DECLARE @dbcc_output    char(5);
  SELECT database_id,
         UPPER(DB_NAME(database_id)) database_name,
         name file_name,
         (size*8)/1024 size_mb
   FROM  master.sys.master_files
   WHERE type_desc = 'LOG'
     AND state_desc = 'ONLINE'
   ORDER BY size_mb DESC;

    OPEN Cur_LogFiles
    FETCH NEXT FROM Cur_LogFiles
       INTO @database_id, @database_name, @file_id, @file_name, @size_mb
      -- Determine 25% of our current logfile size.
      SET @new_size = @size_mb*0.75;
      -- Set context to the database that owns the file and shrink the file with DBCC.
      PRINT 'Database: ' + @database_name + ', file: ' + @file_name + ', size: ' + CONVERT(varchar,@size_mb,25) + 'mb';
      PRINT 'Attempting to shrink file: ' + @file_name + ' by 25% to: '+ CONVERT(varchar,@new_size,25) + 'mb';

      EXEC ('USE [' + @database_name + ']; DBCC SHRINKFILE (['+@file_name+'],'+@new_size+');');

      FETCH NEXT FROM Cur_LogFiles
         INTO @database_id, @database_name, @file_id, @file_name, @size_mb

    CLOSE Cur_LogFiles
    DEALLOCATE Cur_LogFiles