Friday, August 24, 2012

PowerCLI script to get the status of CPU/Memory Hot-Plug in vSphere5

Get-VM | Get-View | Select Name, `
@{N="CpuHotAddEnabled";E={$_.Config.CpuHotAddEnabled}}, `
@{N="CpuHotRemoveEnabled";E={$_.Config.CpuHotRemoveEnabled}}, `
@{N="MemoryHotAddEnabled";E={$_.Config.MemoryHotAddEnabled}} | Export-Csv C:\<path>\file.csv

Wednesday, August 22, 2012

Bash script to stop and disable list of services in Linux

# Defining List of unwanted services
SERVICES="rhnsd sendmail cups netfs autofs nfslock mdmonitor isdn cpuspeed rpcidmapd rpcgssd iptables xfs pcmcia smartd"

# Finding each service status
for service in $SERVICES; do
  if [ -f /etc/init.d/$service ]; then
     # Turning off the service
      chkconfig $service off
     if_running=`service $service status | egrep -i running`
      # Stopping the service if it is running
      [ ! -z "$if_running" ] && service $service stop
  fi
done

Tuesday, August 21, 2012

Sample script to change JDK version

#!/bin/bash
# Purpose      :  For changing JDK version to 1.6.0_14 non-interactively. This script could be useful for
#                      changing the JDK version automatically on multiple servers. I have used this script in a
#                      production change where we got to update JDK version simultaneously on 60+ servers.  
# Assumption :  The Binary version of JDK version 1.6.0_14 already installed under /usr/java/jdk1.6.0_14"

/usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_14/bin/java 1
/usr/sbin/alternatives --set java /usr/java/jdk1.6.0_14/bin/java

/usr/sbin/alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_14/bin/javac 1
/usr/sbin/alternatives --set javac /usr/java/jdk1.6.0_14/bin/javac

unlink /usr/bin/java
ln -s /usr/java/jdk1.6.0_14/bin/java /usr/bin/java

sed -i.bak '/export/ i JAVA_HOME=/usr/java/jdk1.6.0_14\nPATH=$PATH:$JAVA_HOME/bin\nJAVAPTH=$JAVA_HOME/bin\n' /etc/profile

sed -i.bak 's/export.*$/export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME JAVAPTH/' /etc/profile

java -version 2&> java_ver

java_ver=`cat java_ver | grep java | cut -c 15-22`

if [ "$java_ver" != "1.6.0_14" ]; then
echo -e "Updating JDK version to 1.6.0_14 Failed. Please check manually.\n"
exit 1
else
rm -f ./java_ver
echo -e "\n\n\nJDK version has been successfully changed to 1.6.0_14.\n\n"
fi

Popular Posts

About Me

My photo
I have started this blog to share my work experience and spread some smart solutions on Linux to Internet community. I'm hoping more people will get benefited from this blog. Brief about me: I have 14+ years experience working as System Admin and currently work with VMware.