Thursday, 28 July 2011

Duplicate a MySQL Database

Here is a simple script to duplicate a MySQL database:

mysqladmin create new_DB_name -u DB_user --password=DB_pass && \
mysqldump -u DB_user --password=DB_pass DB_name | mysql -u DB_user --password=DB_pass -h DB_host new_DB_name

Possibly Related Posts

Friday, 22 July 2011

Install oracle on 64b Ubuntu 10.04

This are the steps I took to install Oracle 11gR2 x86_64-bit in Ubuntu Linux 10.04 Intel x86_64-bit.

Oracle Installation:

Oracle Software PrerequisitesInstall required packages
sudo su - 
apt-get install build-essential libaio1 libaio-dev unixODBC unixODBC-dev pdksh expat sysstat libelf-dev elfutils lsb-cxx

To avoid error "linking ctx/lib/":
cd /tmp
dpkg-deb -x libstdc++5_3.3.6-17ubuntu1_amd64.deb ia64-libs
cp ia64-libs/usr/lib/ /usr/lib64/
cd /usr/lib64/
ln -s
cd /tmp
dpkg-deb -x ia32-libs_2.7ubuntu6.1_amd64.deb ia32-libs
cp ia32-libs/usr/lib32/ /usr/lib32/
cd /usr/lib32
ln -s
cd /tmp
rm *.deb
rm -r ia64-libs
rm -r ia32-libs

To avoid error invoking target 'idg4odbc' of makefile:
ln -s /usr/bin/basename /bin/basename
To avoid errors when executing the post-install script:
ln -s /usr/bin/awk /bin/awk
Kernel Parameters
sudo su -
Make a backup of the original kernel configuration file:
cp /etc/sysctl.conf /etc/sysctl.original
Modify the kernel parameter file
echo "#">> /etc/sysctl.conf
echo "# Oracle 11gR2 entries">> /etc/sysctl.conf
echo "fs.aio-max-nr=1048576" >> /etc/sysctl.conf
echo "fs.file-max=6815744" >> /etc/sysctl.conf
echo "kernel.shmall=2097152" >> /etc/sysctl.conf
echo "kernel.shmmni=4096" >> /etc/sysctl.conf
echo "kernel.sem=250 32000 100 128" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range=9000 65500" >> /etc/sysctl.conf
echo "net.core.rmem_default=262144" >> /etc/sysctl.conf
echo "net.core.rmem_max=4194304" >> /etc/sysctl.conf
echo "net.core.wmem_default=262144" >> /etc/sysctl.conf
echo "net.core.wmem_max=1048586" >> /etc/sysctl.conf
echo "kernel.shmmax=2147483648" >> /etc/sysctl.conf
Note: kernel.shmmax = max possible value, e.g. size of physical memory in bytes
Load new kernel parameters
sysctl -p
Oracle Groups and Accounts
sudo su -
groupadd oinstall
groupadd dba
useradd -m -g oinstall -G dba oracle
usermod -s /bin/bash oracle
passwd oracle
groupadd nobody
usermod -g nobody nobody
id oracle
uid=1001(oracle) gid=1001(oinstall) groups=1001(oinstall),1002(dba)
Make a backup of the original file:
cp /etc/security/limits.conf /etc/security/limits.conf.original
echo "#Oracle 11gR2 shell limits:">>/etc/security/limits.conf
echo "oracle soft nproc 2048">>/etc/security/limits.conf
echo "oracle hard nproc 16384">>/etc/security/limits.conf
echo "oracle soft nofile 1024">>/etc/security/limits.conf
echo "oracle hard nofile 65536">>/etc/security/limits.conf
Oracle Directories

i.e. /u01/app for Oracle software and /u02/oradata for database files
mkdir -p /u01/app/oracle
mkdir -p /u01/app/oraInventory
mkdir -p /u02/oradata
chown oracle:oinstall /u01/app/oracle
chown oracle:oinstall /u01/app/oraInventory
chown oracle:oinstall /u02/oradata
chmod 750 /u01/app/oracle
chmod 750 /u01/app/oraInventory
chmod 750 /u02/oradata
Execute the Oracle Universal Installer:
Login as the Oracle user - do not use 'su' command
ssh -Y oracle@server_address
See Tips below for mounting the Oracle installation source
Note: Select the "Ignore All" button at the Prerequisite Checks dialog.

Check some more tips after the jump.

Possibly Related Posts

Setting up a TFTP Server

atftp is Multi-threaded TFTP server implementing all options (option extension and multicast) as specified in RFC1350, RFC2090, RFC2347, RFC2348 and RFC2349. Atftpd also supports multicast protocol known as mtftp, defined in the PXE specification. The server supports being started from inetd as well as in daemon mode using init scripts.

Install atftp Server in Ubuntu
sudo aptitude install atftpd
Using atftpd

By default atftpd server starts using inetd so we need to tell atftpd to run as a server directly, not through inetd.Edit /etc/default/atftpd file using the following command
sudo gedit /etc/default/atftpd

Change the following line
save and exit the file

Now you need to run the following command
sudo invoke-rc.d atftpd start
Configuring atftpd

First you need to create a directory where you can place the files
sudo mkdir /tftpboot
sudo chmod -R 777 /tftpboot
sudo chown -R nobody /tftpboot
sudo /etc/init.d/atftpd restart
Security configuration for atftp

Some level of security can be gained using atftp libwrap support. Adding proper entry to /etc/hosts.allow and /etc/hosts.deny will restrict access to trusted hosts. Daemon name to use in these files is in.tftpd.

in.tftpd : FQD or IP
atftp client installation

Advance Trivial file transfer protocol client,atftp is the user interface to the Internet ATFTP (Advanced Trivial File Transfer Protocol), which allows users to transfer files to and from a remote machine. The remote host may be specified on the command line, in which case atftp uses host as the default host for future transfers.
sudo aptitude install atftp
That’s it you are ready to transfer your files using tftp clients

Testing tftp server

Tranfering file hda.txt from (Client using tftp) to (Server Get an example file to transfer (eg. hda.txt)
touch /tftpboot/hda.txt  
chmod 777 /tftpboot/hda.txt 
ls -l /tftpboot/
total 0
-rwxrwxrwx 1 ruchi ruchi 223 hda.txt 
atftp> put hda.txt
Sent 722 bytes in 0.0 seconds
atftp> quit
ls -l /tftpboot/
total 4
-rwxrwxrwx 1 ruchi ruchi 707 2008-07-07 23:07 hda.txt

Possibly Related Posts

Tuesday, 19 July 2011

How to configure multiple Cisco switch ports at the same time

To configure multiple switchports at the same time we use the interface range configuration command.
Switch(config)#interface range fastethernet0/1 – 20
Switch(config-if-range)#speed 100
Switch(config-if-range)#duplex full
The previous example will hardcode the speed and duplex settings on switchports 1 to 20. But this could well have been assinging them all to the same vlan.

We can even define multiple ranges.
Switch(config)#interface range fastethernet0/1 – 4 , fastethernet0/10 – 15
Notice the spaces between the ranges.

The interface range command works with vlan, port-channel, fastethernet and gigabitethernet interfaces.

Possibly Related Posts

Friday, 15 July 2011

Creating and editing Cisco Extended access lists

Extended ACLs allow you to permit or deny traffic from specific IP addresses to a specific destination IP address and port. It also allows you to specify different types of traffic such as ICMP, TCP, UDP, etc. Needless to say, it is very grangular and allows you to be very specific. If you intend to create a packet filtering firewall to protect your network it is an Extended ACL that you will need to create.

Here you have a few examples of how to interact with extended access lists:

To create a new extended acl:
router#conf t
router(config)#ip access-list extended 199
router(config)#10 permit tcp any any
router(config)#20 permit udp any any
router(config)#30 deny ip any any
Display the current rules:
router#show access-list 199
Extended IP access list 199
10 permit tcp any any
20 permit udp any any
30 deny ip any any
Add a new rule:
router#conf t
router(config)#ip access-list extended 199
router(config-ext-nacl)#21 permit gre any any

router#show access-list 199
Extended IP access list 199
10 permit tcp any any
20 permit udp any any
21 permit gre any any
30 deny ip any any
Rearrange the rules numbering:
router#ip access-list resequence 199 10 10
router#show access-list 199
Extended IP access list 199
10 permit tcp any any
20 permit udp any any
30 permit gre any any
40 deny ip any any

Possibly Related Posts

Thursday, 14 July 2011

How to disable Mailscanner for outgoing email only

You need to use a rules file. If you haven't already got one, modify MailScanner.conf so that
Spam Checks = %rules-dir%/spam.scanning.rules
Then create a file in the rules subdirectory called spam.scanning.rules and add the domains as follows:
To: * yes
To: * yes
FromOrTo: default no
The last one is a catchall to not scan domains that are not listed.

The key here is using To: instead of FromOrTo: to prevent outgoing email from being scanned for spam.

Stop and restart MailScanner after making any changes.

Possibly Related Posts

Wednesday, 13 July 2011

Shutdown a Windows machine from a Linux box

You can shutdown a windows box if you have samba installed.

net rpc SHUTDOWN -C "some comment here" -f -I x.x.x.x -U user_name%password
As long as the user you supplied has rights to shutdown the system it will work.

This bash script scans the network and turns off all systems that are left on over night.
wks=(`nmap -sL --dns-servers 10.x.x.x,10.x.x.x 10.x.x.x/22, 10.x.x.x.x/23 grep FQDN|cut -d" " -f2 |grep -v -f serverlist`)
for (( i=0; i < "${#wks[@]}"; i++)); do
net rpc SHUTDOWN -C "This system was left on after hours and is being shutdown" -f -I "${wks[$i]}" -U user_name%password
Basically what the script does is scans the network(s) with nmap, pipes it though grep and cut to get the FQDN. Then "grep -v -f serverlist" is an exclude list of servers we don't want to shutdown. From there it puts the workstations into an array and turns off each system.

Possibly Related Posts

Tuesday, 12 July 2011

How to hide query string in url with a .htaccess file

To masquerade the query string into a pretty SEO url you can use Apache's mod_rewrite.
Rewrite rules don't actually hide the query string, rewrite rules pretty much convert SEO friendly urls into the actual query string.

Example .htaccess:
RewriteEngine on
RewriteRule ([a-zA-Z0-9_]+)\.html$ viewPage.php?ID=$1 [L]
The above rewrite rule will allow you to do something like this:

url reads:
apache interprets as:
Therefore the following PHP code:
echo $id;
will output test.

What if we want to pass more than one value, like "" ?

We just have to convert /categories/coding/test.html into /viewPage.php?category=coding&ID=test

This will do the trick:
RewriteEngine On
RewriteRule ^categories/(\w+)/(\w+)\.html viewPage.php?category=$1&ID=$2 [L]

Possibly Related Posts

Sunday, 10 July 2011

VM Stuck in "Pending" State on XenServer (orange/yellow icon)

This happens when some task is staled, in this case, from the XenServer console CLI:

1. Get the list of Pending tasks
xe task-list
2. Cancel the pending task
xe task-cancel force=true uuid=<the UUID from the above command>

Possibly Related Posts

Saturday, 9 July 2011

Xenserver - Edit grub.conf of halted VM

If a VM doesn’t boot due to an incorrect grub configuration, you can use the xe-edit-bootloader script in the XenServer control domain to edit the grub.conf until the config works, example:
xe-edit-bootloader -n "VM Name" -p 1
This will open the grub.conf file of the specified VM in nano editor.

Possibly Related Posts

Resizing LUNs for Xenserver SRs with Script

Here is another solution for re-sizing a LUN on a ISCSI Xenserver SR without rebooting.

First you need to resize the lun on the iscsi server, then use the following script:

SR2GROW=$(xe sr-list params=uuid name-label=$SR_NAME | awk '{ print $NF }')
# find devices to resize
DEV2GROW=$(pvscan | grep $SR2GROW | awk '{ print $2 }')
# scan for resized devices
iscsiadm -m node -R
# do the resize
for dev in $DEV2GROW ; do
pvresize $dev
# tell xenapi to look for the new LVM size
xe sr-scan uuid=${SR2GROW}

Possibly Related Posts

Friday, 8 July 2011

Set Xenserver VMs Custom Fields with a script

On a previous post I've shown you a script that I use to backup my virtual machines on a XenServer Pool, but I have a lot of VMs so it's not easy to set the custom fields for every VM. So I've made another script that allows you set the custom fields on every VM or in a group of VMs using the tags from XenCenter.

you can use the script like this: [-t tag] [<template_frequency> <template_retention> <xva_frequency> <xva_retention>]

if you omit the -t flag it sets the custom fields for all VMs

And the script goes like this:

# Variables



if [ -f $LOCKFILE ]; then
echo "Lockfile $LOCKFILE exists, exiting!"
exit 1


# Don't modify below this line

# using getopts to parse arguments
while getopts 't:' OPTION
case $OPTION in
?) printf "Usage: %s: [-t tag] [<template_frequency> <template_retention> <xva_frequency> <xva_retention>]\n" $(basename $0) >&2
exit 2
shift $(($OPTIND - 1))



# Quick hack to grab the required paramater from the output of the xe command
function xe_param()
while read DATA; do
LINE=$(echo $DATA | egrep "$PARAM")
if [ $? -eq 0 ]; then
echo "$LINE" | awk 'BEGIN{FS=": "}{print $2}'

# Get all running VMs
RUNNING_VMS=$(xe vm-list power-state=running is-control-domain=false | xe_param uuid)

for VM in $RUNNING_VMS; do
VM_NAME="$(xe vm-list uuid=$VM | xe_param name-label)"

echo " "
echo "= Retrieving backup paramaters for $VM_NAME - $(date) ="
#echo "= $VM_NAME uuid is $VM ="
#Template backups
SCHEDULE=$(xe vm-param-get uuid=$VM param-name=other-config param-key=XenCenter.CustomFields.backup)
RETAIN=$(xe vm-param-get uuid=$VM param-name=other-config param-key=XenCenter.CustomFields.retain)
#XVA Backups
XVA_SCHEDULE=$(xe vm-param-get uuid=$VM param-name=other-config param-key=XenCenter.CustomFields.xva_backup)
XVA_RETAIN=$(xe vm-param-get uuid=$VM param-name=other-config param-key=XenCenter.CustomFields.xva_retain)

if [[ $TAG == "all" ]]
VM_TAGS=$(xe vm-param-get uuid=$VM param-name=tags)

if [[ $VM_TAGS == *$TAG* ]]

if [ "$SCHEDULE" != "$TEMPLATE_BACKUP" ]; then
echo "Updating template backup schedule..."
xe vm-param-set uuid=$VM other-config:XenCenter.CustomFields.backup="$TEMPLATE_BACKUP"

if [ "$RETAIN" != "$TEMPLATE_KEEP" ]; then
echo "Updating template backup retention..."
xe vm-param-set uuid=$VM other-config:XenCenter.CustomFields.retain="$TEMPLATE_KEEP"

if [ "$XVA_SCHEDULE" != "$XVA_BACKUP" ]; then
echo "Updating XVA backup schedule..."
xe vm-param-set uuid=$VM other-config:XenCenter.CustomFields.xva_backup="$XVA_BACKUP"

if [ "$XVA_RETAIN" != "$XVA_KEEP" ]; then
echo "Updating template XVA retention..."
xe vm-param-set uuid=$VM other-config:XenCenter.CustomFields.xva_retain="$XVA_KEEP"




Possibly Related Posts

Resizing LUNs for Xenserver SRs

Perform steps 2-7 on the Pool Master:

1. Extend the volume/LUN from the SAN management console

2.Execute the following command and note the uuid of the SR.
xe sr-list name-label=<your SR name you want to resize>
3.To get the device name (eg: PV /dev/sdj ) use:
pvscan | grep <the uuid you noted in the previous step>
4.Tell the serve to refresh the iscsi connection:
echo 1 > /sys/block/device/device/rescan (e.g. echo 1 > /sys/block/sdj/device/rescan)
5.Resize the volume
pvresize <device name> (eg: pvresize /dev/sdj )
6. Rescan the SR:
xe sr-scan <the uuid you noted in the previous step>
7. Verify that the XE host sees the larger physical disk:
pvscan | grep <the uuid you noted in step 2>


Possibly Related Posts

Wednesday, 6 July 2011

Upgrading Windows Server 2008 R2 Edition without media

You can accomplish this using DISM command line tool:

To determine the installed edition, run:
DISM /online /Get-CurrentEdition
To check the possible target editions, run:
DISM /online /Get-TargetEditions
Finally, to initiate an upgrade, run:
DISM /online /Set-Edition:<edition ID> /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
So, for example, to upgrade to Windows Server 2008 R2 Datacenter from a Standard edition, you would run:
DISM /online /Set-Edition:ServerDatacenter /productkey:ABCDE-ABCDE-ABCDE-ABCDE-ABCDE
After running the /Set-Edition command, DISM will prepare the operating system for the edition servicing operation, then reboot twice while it applies the changes to the operating system. After the final reboot, you’ll be running the new edition!

Note: that the server can't be a DC at the time of upgrade. If you demote a DC using dcpromo, you can upgrade, then re-promote it (you may need to migrate FSMO roles, etc, in order to succesfully demote.)

Possibly Related Posts

Tuesday, 5 July 2011

Reclaim Disk Space from Deleted XenServer Snapshots and Clones

Running this script will incur some downtime for the VM, due the suspend/resume operations performed.

This instructions are for XenServer 5.6 and later

Citrix recommends that you back up the VM on which you will run the space reclamation tool. You can use the XenCenter export option for this purpose.

Run the following command from the XenServer CLI:
xe host-call-plugin host-uuid=<host-UUID> plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=<VM-UUID>
The amount of time required varies based on the amount of data written to the disk since the last snapshot. Smaller VMs (that is, 10 GB or less) take less than a minute.

If the Virtual Disk Images (VDIs) to be coalesced are on shared storage, you must execute the off-line coalesce tool on the pool master.

To get Pool Master UUID you can use this command:
xe pool-list params=master | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"
To get uuids of all running VMs
xe vm-list is-control-domain=false power-state=running params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"
so you can create a script to execute the off-line coalescing tool on every VM like this:

MASTER=$(xe pool-list params=master | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")
#All VMs
RUNNING_VMS=$(xe vm-list is-control-domain=false params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")
#All running VMs
#RUNNING_VMS=$(xe vm-list is-control-domain=false power-state=running params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")
#All halted VMs
#RUNNING_VMS=$(xe vm-list is-control-domain=false power-state=halted  params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")

for VM in $RUNNING_VMS; do
    echo " "
    echo "=== Starting coalesce leaf process for $VM at $(date) ==="
    echo " "

    xe host-call-plugin host-uuid=$MASTER plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$VM

    echo " "
    echo "=== Coalesce leaf process for $VM ended at $(date) ==="
    echo " "

Possibly Related Posts