Sunday, July 12, 2009

Schedule cron jobs to send sms on mobile

I've got a weekly shutdown for our Websphere servers for a Database backup. To keep an eye on the logs as the shutdown procedures happen, I've got this cron entry



# Shut down Websphere Portal for Oracle backup every Thursday 12:05 midnight and start next morning 4:15 AM
05 00 * * 5 /etc/init.d/websphere_portal stop 2>&1 > /root/portal-stop.log; echo $HOSTNAME >> /root/portal-stop.log; tail -n 6 /root/portal-stop.log | mailx 'nabeel@smsserver.domain.tld'
15 04 * * 5 /etc/init.d/websphere_portal start 2>&1 > /root/portal-start.log; echo $HOSTNAME >> /root/portal-start.log; tail -n 6 /root/portal-start.log | mailx 'nabeel@smsserver.domain.tld'

So I get the last 6 lines in my mobile inbox as SMS

Init script for Websphere Portal/DB2 on linux

Copy the following script to /etc/init.d/webpshere_portal or some name.



#!/bin/bash
# Websphere_portal # Startup script for IBM WebSphere Portal Server
#
# chkconfig: - 99 15
# description: Websphere Portal server startup
# processname: websphere_portal
# pidfile: /var/run/websphere_portal.pid
# author: Nabeel Moidu nabeelmoidu.at.gmail dot com
# Source function library.
. /etc/rc.d/init.d/functions

portal=/opt/IBM/PE/AppServer/profiles/wp_profile/bin
args=WebSphere_Portal
prog="WebSphere Portal Server"
proc=/opt/IBM/WebSphere/AppServer/java/bin/java
RETVAL=0
username=portaluser
password=password


# verify installation
if [ ! -x $portal ]; then
echo "$prog is not installed"
exit 0
fi

# source function library
. /etc/rc.d/init.d/functions


case "$1" in
start)

# Websphere should come up only if DB2 is up.
for (( ; ; ))
do

# Check status of DB2
su - wpdb2ins -c 'db2gcf -s' | grep Available;
PRC_EXT_STAT=$?;

# If DB2 is available, then startup the portal

if [ $PRC_EXT_STAT = "0" ]; then
echo -n "Starting $prog: "

# Set ulimit
ulimit -n 1000000

# setup environment variables
. /home/wpdb2ins/sqllib/db2profile

# Bring up the portal
$portal/startServer.sh $args
RETVAL=$?
if [ $RETVAL = 0 ]; then
touch /var/lock/subsys/websphere_portal
echo_success
else
echo_failure
fi
break;
# If DB2 is not up, then start DB2
else
su - wpdb2ins -c 'db2start'
fi
done

;;
stop)
echo -n "Shutting down $prog: "
$portal/stopServer.sh $args -username $username -password $password
RETVAL=$?
if [ $RETVAL = 0 ]; then
rm -f /var/lock/subsys/websphere_portal
# Shut down DB2
su - wpdb2ins -c 'db2stop';
echo_success
else
echo_failure
fi
echo
;;
restart)
$0 stop
$0 start
;;
status)
status $proc
;;
*)
echo "Usage: websphered {start|stop|restart|status}"
exit 1

esac

exit 0



Then execute the following commands



chmod +x /etc/init.d/websphere_portal
chkconfig --add /etc/init.d/websphere_portal
chkconfig --level 345 websphere_portal on

Thursday, May 28, 2009

SVN error

[root@up-subversion ~]# svn import NetBackup file:///test/ -m "test"
svn: The log message is a pathname (was -F intended?); use '--force-log' to override

Fix
[root@up-subversion ~]# svn import NetBackup file:///test/ -m "test message"

The message name was the same as the repo name and hence the error

Lotus Forms Error

One of the developers in our application team was deploying a forms app on a Websphere Portal and this error kept occuring

[com/PureEdge/xfdl/FormNodeP]: java.lang.NoClassDefFoundError: com/PureEdge/xfdl/FormNodeP

It turned out the Websphere Portal did not have the Shared Library LFS_API_LIB configured. Once I added it and restarted the Portal , it worked.

Wednesday, May 20, 2009

Set language firefox google search

It annoys me often when my google searches via the default firefox google extension directs me to an arabic page. Here's how you fix it on linux (thanks to Colin Verot http://www.verot.net/google_language.htm ).

Edit the file
/usr/lib64/firefox-x.x.x/searchplugins/google.xml
or
/usr/lib/firefox-x.x.x/searchplugins/google.xml

and add the line
Param name="hl" value="en"

Restart Firefox.

Tuesday, April 28, 2009

LVM Volume group extension fails

If it fails with a message about missing uuid, try


vgreduce --removemissing VolGroupName


This removes the mising volumes in the group and we can proceed with the volume group extension

Tuesday, April 21, 2009

Disabling security for Websphere Application Server

Quite a few times I've got my WAS installations having their security settings corrupted thereby denying me login into the admin console.
Here's how you disable security in such cases (of course you need to have root access to shell )

vim /opt/IBM/PE/AppServer/profiles/profile_name/config/cells/instance_name/security.xml

in the first line disable security

useLocalSecurityServer="false"
enabled="false"

Now login with any name, troubleshoot the login issues and switch it back.

Thursday, April 09, 2009

ISA unable to access site

One of my friends couldn't access the birlasunlife.com website on IE 8 when passed through a proxy.
It was working on firefox though. Looks like its a malformed url as mentioned here
http://blogs.technet.com/yuridiogenes/archive/2008/10/09/error-64-from-the-field-to-the-classroom.aspx
good article in there.

Sunday, January 25, 2009

ISA 2006 and migration troubles

Our ISA 2004 server got screwed up and from my previous experience I'd found that setting up a new one and importing the settings is easier than troubleshooting one. So while my colleague worked on troubleshooting the existing one, I put up a new server with ISA 2006 ( a FORCED upgrade ;) )
and tried importing the old settings to the new server.

I'd exported the configuration of the ISA 2004 server to an xml file some time back so that came in handy today. But while importing, it prompted for a password. I don't remember ever providing a password for the exported xml. I tried my usual ones but it was all in vain. I tried deleting the password line in the xml file.It didn't work. Finally after going through some forums etc. I figured out that the best way was to export the config of the new ISA 2006 to a new file, open the new and old xml files in an xml editor and identify the Array and Enterprise sections. Copy over the two sections from the old config to the newly exported file. Save it and import the configurations from the new xml file. You should have all the settings and rules of the old server working.

Wednesday, January 21, 2009

MySQL backup script



#!/bin/bash
# A simple shell script to backup all MySQL Server Database
# Each dump will be line as follows:
# Directory: /var/lib/mysql/backup/mm-dd-yyyy
# File: mysql-DBNAME.04-25-2008.gz
# -------------------------------------------------------------------------
NOW=$(date +"%m-%d-%Y") # mm-dd-yyyy format
FILE="db-full-$NOW.tar.gz"
BAK="/var/lib/mysql/backups/"

### Server Setup ###
#* MySQL login user name *#
MUSER="user"

#* MySQL login PASSWORD name *#
MPASS="pass"

#* MySQL binaries *#
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"

# get all application related databases
DBS="$($MYSQL -u $MUSER -p$MPASS -Bse 'show databases' | grep -v information_schema)"

# create backups securely
umask 006

# start to dump database one by one
for db in $DBS
do
FILE=$BAK/mysql-$db.$NOW.gz
# gzip compression for each backup file
$MYSQLDUMP -u $MUSER -p$MPASS $db | $GZIP -9 > $FILE
done

Websphere startup script for linux

Startup script for Websphere Application server on linux. Its got an added check for Oracle connectivity before the service is brought up.



#!/bin/bash
# Websphered # Startup script for IBM WebSphere Application Server
#
# chkconfig: - 99 15
# description: IBM's J2EE application server
# processname: websphered
# pidfile: /var/run/websphered.pid

# Source function library.
. /etc/rc.d/init.d/functions

websphered=/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin
args=server1
prog="WebSphere Application Server"
proc=/opt/IBM/WebSphere/AppServer/java/bin/java
RETVAL=0
username=user
password=password


# verify installation
if [ ! -x $websphered ]; then
echo "$prog is not installed"
exit 0
fi

# source function library
. /etc/rc.d/init.d/functions


case "$1" in
start)

# Continous loop to check Oracle connectivity. Websphere should come up only if Oracle is up.
for (( ; ; ))
do

# Check for Oracle connectivity

su - oracle -c '/opt/Oracle/product/10.2.0/client_1/bin/tnsping database_name ' | grep OK;
PRC_EXT_STAT=$?;

# If Oracle is pingable, then startup WAS and break out of loop

if [ $PRC_EXT_STAT = "0" ]; then
echo -n "Starting Websphere Application Server: "
$websphered/startServer.sh $args
RETVAL=$?
if [ $RETVAL = 0 ]; then
touch /var/lock/subsys/websphered
echo_success
else
echo_failure
fi
#Break out of loop
break;
echo
fi
# Wait 30 seconds before checking again
echo " Waiting for Oracle connectivity: "
sleep 30

done

;;
stop)
echo -n "Shutting down websphered: "
$websphered/stopServer.sh $args -username $username -password $password
RETVAL=$?
if [ $RETVAL = 0 ]; then
rm -f /var/lock/subsys/websphered
echo_success
else
echo_failure
fi
echo
;;
restart)
$0 stop
$0 start
;;
status)
status $proc
;;
*)
echo "Usage: websphered {start|stop|restart|status}"
exit 1

esac

exit 0

Wednesday, November 19, 2008

Uptime on Windows

If u need to know the uptime on windows,

use either systeminfo (doesn't work on win2k)
or
net statistics server

Tuesday, November 11, 2008

Some useful shell tips

When in vi use :split for split view of two files, use Ctrl+W to toggle

for rpm query of only names
rpm -qa --queryformat='%{NAME} \n' | sort -n
or using awk
rpm -qa | awk -F"-[0-9]" '{ print $1}'

for grep with highlight of matched word,
grep --color word file

Monday, August 11, 2008

PHP script to monitor servers.


<title>Code</title>

<title>Server Status</title>

<center> <b><font style="" size="5" face="Times New Roman,Times,serif"> Servers - Status of critical services </font></b> </center>

<p><font style="" size="2" face="Verdana,Arial,Helvetica,sans-serif">

<b>Servers</b> ";
for( $j=0; $servicenames[$j]; $j++)
{ echo "<font color="blue"> <b> $servicenames[$j]</b></font> "; }


$serviceports_array = $ini_array['service_ports'];
$serviceports = explode (",",$serviceports_array);
sort($serviceports,SORT_NUMERIC);

for($i=0;$hostnames[$i];$i++)
{
$hostname = $hostnames[$i];
$port_array = $ini_array[$hostname];
$ports = explode (",",$port_array);
sort ($ports,SORT_NUMERIC);

echo " <font color="green"> <b> $hostname </b></font> ";
for($m=0,$n=0;$serviceports[$m];$m++)
{ if ($serviceports[$m] == $ports[$n])
{ disp_status($hostname,$ports[$n],'Y'); $n++;
} else {
disp_status($hostname,$ports[$n],'N');}
}
}

function disp_status($_hostname, $_port, $_status){

error_reporting(0);
// header("Content-type: image/gif");
if ($_status == 'Y')
{
$fp = fsockopen($_hostname, $_port);
if (!$fp)
{ echo " <img src="http://www.blogger.com/%27offline.png%27">";}
else
{ echo " <img src="http://www.blogger.com/%27online.png%27">";}
fclose($fp);
}
else
{ echo " <img src="http://www.blogger.com/%27NA.png%27">";}
}

?>


</font>
</p><p> <b>KEY : <img src="http://www.blogger.com/%27offline.png%27"> OFFLINE <img src="http://www.blogger.com/%27online.png%27"> ONLINE <img src="http://www.blogger.com/%27NA.png%27"> NOT MONITORED </b></p><b>



</b>

Wednesday, August 06, 2008

DBORA script for oracle startup in RHEL



[root@myserver ~]# cat /etc/init.d/dbora
#!/bin/bash
#
# chkconfig: 345 60 50
# description: Oracle auto start-stop script.

# Modify the variables $ORA_HOME, $ORA_OWNER and $LOG as appropriate for each server.
# - Nabeel Moidu

# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network

# Modify the variables $ORA_HOME, $ORA_OWNER and $LOG as appropriate for each server.
# - Nabeel Moidu
ORA_HOME=/u01/oracle/product/10.2.0.1
ORA_OWNER=ora10g
LOG=$ORA_HOME/log/server/dbora/dbora.log


if [ ! -f $ORA_HOME/bin/dbstart -o ! -d $ORA_HOME ]
then
echo "Oracle startup: cannot start"
exit
fi

case "$1" in
start)
echo "$0: starting up" >> $LOG
# Start the Oracle databases:
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart &" >> $LOG
# Start Oracle listener
date >> $LOG
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >> $LOG 2>&1
touch /var/lock/subsys/dbora
echo "Refer to $LOG for details"
;;
stop)
echo "$0: stopping down" >> $LOG
date >> $LOG
# Stop Oracle Net
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >> $LOG 2>&1
# Stop the Oracle databases:
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut &" >> $LOG
rm -f /var/lock/subsys/dbora
;;
restart)
$0 stop
sleep 120
$0 start
;;
status)
if [ -f /var/lock/subsys/dbora ]; then
echo $0 started.
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl status"
else
echo $0 stopped.
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl status"
fi
;;
*)
echo "usage: dbora {start|stop|restart|status}"
exit 1
esac
exit 0

Wednesday, July 09, 2008

Bash script for renaming files en masse


#! /bin/bash
x=0
for i in `ls $1/*.$2`
do
mv $i `printf "%03x.$2" $x`
x=$(($x+1))
done



Usage : (say call the script a.sh )
./a.sh /var/www/html/images jpeg
will sequentially rename all jpeg files in /var/www/html/images to 001.jpeg 002.jpeg etc.

Wednesday, June 25, 2008

Updating RHEL to a specific version


1) Download the isos for the specific version from https://rhn.redhat.com/rhn/software/downloads/SupportedISOs.do using the rhn login.

2) Mount the CDs/DVD and copy the rpm packages in the RPMS folder in it to a particular folder like say /var/spool/RPMS/.

3) Open the file /etc/sysconfig/rhn/sources and comment the line

   #up2date default

Modify the line beginning ”# dir my-favorite-rpms ”

   dir UPDATE-RPMS /var/spool/RPMS/

Save the file and exit.

4) Run the following command

  [root@rhel ~]# up2date --configure
0. adminAddress ['root@localhost', '']
1. debug No
==SNIPPED==
19. pkgSkipList ['kernel*', '']
20. pkgsToInstallNotUp ['kernel', 'kernel-modules', 'kernel-devel', '']
==SNIPPED==
Enter number of item to edit :

Edit the pkgSkipList to include the kernel rpms for update.

5) Make sure the server is backed up in the current state ( A lot of softwares might not work after the update or might face reconfiguration etc, especially third party softwares ). Then run the command

   [root@rhel ~]# up2date -u

If all goes well the system will update to the version of the dvd we have put in the /var/spool/RPMS folder.

6) Reboot the server for the new kernel to be loaded. To verify the update, run

   [root@rhel ~]# cat /etc/redhat-release

Tuesday, June 03, 2008

Remote boot upload image error HP RADIA Dell Optiplex 755

One of my colleagues was trying to upload a boot image of an xp install on a dell optiplex 755 using the HP OpenView configuration management tool (formerly radia) and it was showing up an error
no BootDisk found (actually something like that)

It's backend was (of course ;) ) linux so I tried switching the terminal and did an lsmod and tail of the /log/rnl.log file. An empty fdisk -l output confirmed it was a case of driver not being loaded for the sata.
I changed the SATA Operation parameter in the BIOS to AHCI from ATA and it worked fine.

UPDATE:
This didn't solve the issue. It doesn't install using an image uploaded this way. HP later released a patch for this .

Monday, March 31, 2008

Veritas NBU Installation on HPUX

I was getting stuck at this message while trying to install a Veritas Net Backup Agent on an HPUX box.
Can't call method "info" on an undefined value at VxIF/4.2.2.12/VxIF/Installer.pm line 231

Googling suggested that it was an issue with the hostname resolution. The hostname looked fine in /etc/hosts and /etc/rc.config.d/netconf but the script still gave errors. Finally I set the hostname using
uname -S hostname
and the thing worked :)

Tuesday, February 05, 2008

Oracle and network detection

I recently had to do a rhel server setup for Oracle 10g. I'd configured static networking for the server but Oracle started complaining I had dhcp set for the NIC. I verified my network settings and tried again but it still kept complaining about the same. Finally I added an entry to the /etc/hosts file and Oracle was happy about it. I don't understand the logic in looking at the /etc/hosts file to determine whether the network configuration is static or dhcp. But anyhow "it works" :)