Thursday, April 30, 2009

How to get dates as a String

public String getToday() {
SimpleDateFormat sdfbeginDate = new SimpleDateFormat("MM/dd/yyyy");
return sdfbeginDate.format(Calendar.getInstance().getTime());
}

public String getNowAsTimestampString() {
Calendar nowCalendar = Calendar.getInstance();
java.util.Date myDate = nowCalendar.getTime(); // ex: Thu Aug 09 13:20:36 EDT 2014
SimpleDateFormat sdf = new SimpleDateFormat( "MM/dd/yyyy/HH/mm/ss");
return sdf.format( myDate );
}

public String getNowAsDateString() {
Calendar nowCalendar = Calendar.getInstance();
java.util.Date myDate = nowCalendar.getTime(); // ex: Thu Aug 09 13:20:36 EDT 2014
SimpleDateFormat sdf = new SimpleDateFormat( "MM/dd/yyyy");
return sdf.format( myDate );
}

Tuesday, April 28, 2009

How to sync all your servers to use the same date and time

1. edit the ntpdate file:

root@Knoppix:/etc# cat /etc/default/ntpdate
# The settings in this file are used by the program ntpdate-debian, but not
# by the upstream program ntpdate.

# Set to "yes" to take the server list from /etc/ntp.conf, from package ntp,
# so you only have to keep it in one place.
NTPDATE_USE_NTP_CONF=no

# List of NTP servers to use (Separate multiple servers with spaces.)
# Not used if NTPDATE_USE_NTP_CONF is yes.
#NTPSERVERS="0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org"

NTPSERVERS="swisstime.ee.ethz.ch"

# Additional options to pass to ntpdate
NTPOPTIONS=""



2. invoke a time synchronization

root@Knoppix:/etc# ntpdate-debian
28 Apr 20:33:50 ntpdate[15046]: adjust time server 129.132.2.21 offset 0.370255 sec
root@Knoppix:/etc#


3. set up a cron job to invoke the time synchronization:

root@Knoppix:/# crontab -e

# every night at 2 am, sync/update the time
0 2 * * * ntpdate-debian


4. Optionally, update your time zone, by creating a symbolic link for /etc/localtime to the timezone of your choice. Example:

root@Knoppix:/ # ln -sf /usr/share/zoneinfo/EST /etc/localtime
(this changes the timezone to EST)

root@Knoppix:/ # ln -sf /usr/share/zoneinfo/GMT /etc/localtime
(this changes the timezone to GMT)

Monday, April 6, 2009

How to call a procedure using an OracleCallableStatement

OracleCallableStatement oracleCallableStatement = null;

try
{
oracleCallableStatement = (OracleCallableStatement)connection.prepareCall( YOUR_PROCEDURE );
oracleCallableStatement.setString( 1, VARIABLE_1 );
oracleCallableStatement.setString( 2, VARIABLE_2 );
oracleCallableStatement.setString( 3, VARIABLE_3 );
oracleCallableStatement.registerOutParameter(4, oracle.jdbc.OracleTypes.CURSOR);

oracleCallableStatement.execute();
rs = (ResultSet)oracleCallableStatement.getObject(4);
}
catch ( Exception e )
{
logerror("Error while setting up Oracle procedure. Error is: " + e.toString() );
fatalexit();
}

Wednesday, April 1, 2009

Simple shell scripting - how to test 4 Seagate drives

Title: Testing 4 seagate drives concurrently, 10 times each, and dumping all the results in different files, in different directories.

Downloaded the seagate test "st" utility. The command to run an extensive test on a drive is:

./st -G device
ex:
./st -G /dev/sg0
./st -G /dev/sg1
./st -G /dev/sg2
./st -G /dev/sg3


1. create 4 directories to dump each set of tests in:
mkdir TESTsg0
mkdir TESTsg1
mkdir TESTsg2
mkdir TESTsg3

2. create a run.sh script which takes as arguments the run number (a number such as 1, 2, 3 ... ) and the device to scan, such as sg0, sg1, sg2, sg3. This script outputs the result of the run into the TESTSG# directories created above. For example, running ./run.sh 8 sg3 will dump the outputs of the test into directory and file TESTsg3/test8sg3.txt

#!/bin/sh
RUN=$1
SG=$2
if [ "$RUN" == "" ] ; then
echo "You must run with an argument of the run number: ./run.sh 5 sg0"
RETURNCODE=1
exit $RETURNCODE
fi
echo "Now executing for run $RUN"
./st -G /dev/"$SG" > ./TEST"$SG"/test"$RUN""$SG".txt


3. create a script to test each drive individually, doing 10 runs.

sg0tests.sh

#!/bin/sh
./run.sh 1 sg0
./run.sh 2 sg0
./run.sh 3 sg0
./run.sh 4 sg0
./run.sh 5 sg0
./run.sh 6 sg0
./run.sh 7 sg0
./run.sh 8 sg0
./run.sh 9 sg0
./run.sh 10 sg0

for sg1tests.sh, sg2tests.sh, and sg3tests.sh, replace the sg0 argument with sg1, sg2, and sg3, respectively.


4. To watch the processes while they're running, create a script called myps.sh:

#!/bin/sh
while true
do
clear
ps aux | grep run.sh | grep -v grep
sleep 3
done