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" :)

Sunday, January 27, 2008

Oracle 10g installation on RHEL4 AS x86_64 bit HP Blade BL 480c

Hardware:
HP ProLiant BL480c G1, Intel Xeon E5345 (x86_64) 2 * Quad Core 2.33GHz
Memory 8192 MB, Hard disk 440 GB - RAID 5 H/w array of 146.8 * 4 SAS disks

Software:
Operating System Red Hat Enterprise Linux 4 AS Update 6 x86_64 bit
Kernel Version Linux 2.6.967.ELsmp #1 SMP x86_64 GNU/Linux
Database Oracle 10g Release 2 Database

Installation procedure:

Note: Many of the special notes and parameters are specific to this installation on this hardware only. While installing other servers on a different type of hardware or different versions of the OS or any software used, choose the values accordingly.

1. Login as Administrator into iLO homepage. Choose the Integrated Remote Console option.( You'll need a Windows machine with IE for this)

Note: The RHEL Installation DVD needs to be connected to the server via the

Virtual Media option and hence the other options in iLO via serial/web/java
based cannot be used for installation since they don't have this option.
The other option is use the DVD ROM in the blade chassis. I'm lazy to go all the way to the data center for this . So I prefer the virtual media stuff ;)

2. Boot from the RHEL 4 AS Update 6 x86_64bit DVD ROM

Note: The RHEL 4 versions prior to U 6 do not contain the drivers for the SAS

disks and will not detect a hard disk on the server. The driver though can be
separately downloaded from the HP site and loaded from a floppy during the
installation.

3. Choose “linux text” method of installation since the mouse doesn't work during the graphical installation on the HP BL480c blade servers. Proceed with default options till the partitioning stage is reached.

4. Select to manually partition disk with Disk Druid and build the following disk
configuration:
/boot 100 MB
/ 50 GB
Ignore the swap warning and proceed.
Note: The rest of the partitions can be created on lvm ONLY using the graphical system-config-lvm tool once the installation is completed. The swap can be configured on a logical volume so that in case of memory upgrades we can easily increase the swap space accordingly. Its recommended to place the /boot partition on a non-lvm partition.

5. Configure the IP Address and hostname , select the adapter to activate on boot.

6. Select “customize the packages for installation” and choose the following :
a) X Window System
b) Gnome Desktop Environment
c) Editors
d) Graphical Internet
e) Text based Internet
f) Server configuration tools
g) Web Server
h) Windows File Server
i) FTP Server
j) Development tools
k) X software development
l) Legacy software development
m) Administration tools
n) System Tools

Leave the default options unchanged for the remaining steps and proceed.

7. Reboot the server once the package installation is complete and login as root.

8. Create an LVM (8e) partition with the remaining space on the disk using fdisk.
Issue the partprobe command so that the kernel reloads the new partition table.

9. Create a Physical Volume on the new partition using
[root@server1 ~]# pvcreate /dev/cciss/c0d0p5
Physical volume "/dev/cciss/c0d0p5" successfully created

10. Launch the system-config-lvm tool and create individual Logical Volumes on the newly created Physical Volume Vol0 with the sizes and mount points as below ( Set the mount points to be mounted only after reboot as we need to rsync the existing /tmp and /var directories before we move them to the newly created LVs ):
/dev/mapper/Vol0-u01 20G /u01
/dev/mapper/Vol0-u02 15G /u02
/dev/mapper/Vol0-u03 20G /u03
/dev/mapper/Vol0-u04 20G /u04
/dev/mapper/Vol0-u05 40G /u05
/dev/mapper/Vol0-u06 20G /u06
/dev/mapper/Vol0-u07 25G /u07
/dev/mapper/Vol0-u08 20G /u08
/dev/mapper/Vol0-u10 20G /u10
/dev/mapper/Vol0-backup 79G /backup
/dev/mapper/Vol0-archive 40G /archive
/dev/mapper/Vol0-tmp 9.9G /tmp
/dev/mapper/Vol0-var 15G /var
/dev/mapper/Vol0-swap 16 GB

11. Exit the system-config-lvm tool.

12. Prepare the /dev/Vol0/swap partition for swap.
[root@server1 ~] mkswap /dev/Vol0/swap
[root@server1 ~] swapon /dev/Vol0/swap

13. Move the /var and /tmp directories to LVs so that in case they get filled up due to any unexpected reasons, the system and the root ( “/” ) partition is not affected and so that in case they need to be expanded later on, it can be done easily. Create two temporary folders in /tmp for mounting the LVs var and tmp
temporarily. rsync the existing var and tmp directories to the corresponding LVs.
[root@server1 ~]mkdir /tmp/{var,tmp}
[root@server1 ~]mount /dev/mapper/Vol0-tmp /tmp/tmp
[root@server1 ~]mount /dev/mapper/Vol0-var /tmp/var
[root@server1 ~]rsync -av /var /tmp/var
[root@server1 ~]rsync -av /tmp /tmp/tmp
[root@server1 ~]

14. Add entries to /etc/fstab for all the newly created LVs.
/dev/Vol0/swap swap swap defaults 0 0
/dev/Vol0/u01 /u01 ext3 defaults 1 2
/dev/Vol0/u02 /u02 ext3 defaults 1 2
/dev/Vol0/u03 /u03 ext3 defaults 1 2
/dev/Vol0/u04 /u04 ext3 defaults 1 2
/dev/Vol0/u05 /u05 ext3 defaults 1 2
/dev/Vol0/u06 /u06 ext3 defaults 1 2
/dev/Vol0/u07 /u07 ext3 defaults 1 2
/dev/Vol0/u08 /u08 ext3 defaults 1 2
/dev/Vol0/u10 /u10 ext3 defaults 1 2
/dev/Vol0/backup /backup ext3 defaults 1 2
/dev/Vol0/archive /archive ext3 defaults 1 2
/dev/Vol0/tmp /tmp ext3 defaults 1 2
/dev/Vol0/var /var ext3 defaults 1 2

15. Reboot system and login as root. Ensure all the filesystems have been mounted.

16. Make sure the following packages do not exist so that there's no package conflict with the oracle prerequisites.
a) Ksh2004022912
b) Ipw2200firmware2.03
c) Ipw2100firmware1.31
Use the command #rpm –e to remove the packages.

17. Make sure the following packages (or later versions if available) are available and install/upgrade if necessary. The packages can be installed/upgraded either by manually downloading the rpm packages from RHN with subscription account.
kernel-2.6.9-42.0.3.EL
libstdc++-3.4.6-3

kernel-smp-2.6.9-42.0.3.EL
make-3.80-5

compat-db-4.1.25-9
pdksh-5.2.14-30.3

control-center-2.8.0-12.rhel4.5
sysstat-5.0.5-1

xscreensaver-4.18-5.rhel4.11
gcc-3.4.6-3

compat-libstdc++-33-3.2.3-47.3
libaio-0.3.102-1

openmotif21-2.1.30-11.RHEL4.2
gcc-c++-3.4.6-3

compat-libstdc++-296-2.96-132.7.2
glibc-2.3.4-2.25

glibc-common-2.3.4-2.25
gcc-g77-3.4.6-3

gnome-libs-1.4.1.2.90-44.1
mkinitrd-4.2.1.8-1


18. Configure the VNC server for remote administration.
[root@server1 ~]# cat /etc/sysconfig/vncservers
VNCSERVERS="1:ora10g"
VNCSERVERARGS[1]="-geometry 1024x768"
[root@server1 ~]# cat ~ora10g/.vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

19. Download and install the latest HP Proliant Service Pack from the HP website
for x86_64 bit RHEL 4 AS to remotely administer the system and monitor the
server health. Untar the tarball and extract it to a folder. cd into the directory and
execute the following command:
[root@server1#]chmod u+x install791.sh ;
[root@server1#]./install791.sh

21. Reboot the server and get ready for the Oracle Database installation.


Oracle Database 10g Release 2 installation.

1. Check the prerequisite RPMs (Get the latest list from the oracle website)

2. Create the Oracle Groups
#/usr/sbin/groupadd oinstall
#/usr/sbin/groupadd dba

3. Create the oracle user
#/usr/sbin/useradd --home /u01/oracle/product/10.2.0.1 -g oinstall -G dba ora10g
Note: g for primary group and –G for other group

4. Change the password of the oracle user
#passwd oracle

5. Create oracle directories for binaries and data files
Creation of the ORACLE_HOME
#mkdir -p /u01/oracle/product/10.2.0.1
#chown -R ora10g:oinstall /u01/oracle/product/10.2.0.1
Creation of directories for oracle files
#mkdir -p /u01/oradata/prod
#chown -R ora10g:oinstall /u01/oradata/prod
Change ownership of /backup directory to the ora10g user.
#chown -R ora10g:oinstall /backup

6. Change the kernel parameters by appending the following to /etc/sysctl.conf:
#vi /etc/sysctl.conf
# For Oracle
kernel.shmall = 2097152
kernel.shmmax = 4294967296 # Set this to half of physical RAM
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 192000
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 262144

Enter the following command to change the current values of the kernel
parameters (Reboot the machine if the command fails)
#/sbin/sysctl -p

7. Set the shell limits for the oracle user
Add the following lines in the /etc/security/limits.conf file
Ora10g soft nproc 2047
Ora10g hard nproc 16384
Ora10g soft nofile 1024
Ora10g hard nofile 65536
Add the following line to the /etc/pam.d/login file, if it does not exist
Session required /lib/security/pam_limits.so

8. Create the .bash_profile
#su - ora10g
$vi .bash_profile
ORACLE_BASE=/u01/oracle
Export ORACLE_BASE
ORACLE_HOME=/u01/oracle/product/10.2.0.1
Export ORACLE_HOME
ORACLE_SID-prod
Export ORACLE_SID
PATH=$PATH:$ORACLE_HOME/bin
Export PATH
Umask 022

9. Copy the oracle database installation file 10201_database_linux_x86_64.cpio
to /tmp and extract it
#cpio -idmv <10201_database_linux_x86_64.cpio

10. Start the installation by running runinstaller and proceed with the installation.

11. After completing the installation apply the oracle patch version 10.2.0.3 (latest).

Tuesday, January 22, 2008

If you uninstall the rpm package itself!!!!!!!!!!!!

Installing rpm's rpm without... rpm!
A friend of mine recently uninstalled the rpm package on his system and panicked. Now thats sure a tough situation. rpm is the lifeline of red hat based distros. Here's what to do in case it happens to you

Download the rpm-4.x.x.i386.rpm package (the version depends upon the version of your distro )
Download this script and make it executable (chmod 775 rpm2cpio.sh)
http://www.rpm.org/tools/scripts/rpm2cpio.sh

Copy the script and the rpm-4.x.x.i386.rpm package in the / directory.
From the / directory, run the following command as root:

./rpm2cpio.sh rpm-4.x.x.i386.rpm | cpio -ivd

This will extract the files from the rpm-4.x.x.i386.rpm package and place them in the right directories, as if you installed it with the rpm command, but without updating the rpm database nor executing any postinstall script.

The pre- and post-install script are described in the attached file, that can be extracted from the rpm-4.x.x.i386.rpm package. You have to run them manually in a console window.

At the end, as extra security option, you could run

rpm -ivh --force rpm-x.x.i386.rpm

This should install rpm over itself, updating the rpm database and executing the pre- and post-install scripts as usual.