Showing posts with label Open Source. Show all posts
Showing posts with label Open Source. Show all posts

Monday, December 28, 2009

Script to turn off PoE power using Energywise

My environment: Cisco 3560E

Besides shutting down the switchport, you can turn off the PoE power via the Energywise command.  Before you run this script, setup your energywise domain with the command “energywise domain panda security shared-secret eatsbamboo”

#!/usr/bin/expect

set timeout 5
log_user 1
set hostlist "pandasw01"
set prompt "pandasw01"
foreach host $hostlist {
#set prompt [append $host "#"]
set promptcfg [append $prompt "(config)#"]
spawn telnet $host
expect $prompt
send "conf t\r"
expect $promptcfg
send "int range fa0/1 - 23\r"
expect $promptcfg
send "energywise level 0\r"
expect $promptcfg
send "end\r"
expect $prompt
send "exit\r"
}

Script to Turn off Cisco Autonomous Access Point radio interface

My environment: Cisco 861W

You can turn off the radio interface of the autonomous AP when you don’t use it to save power.

#!/usr/bin/expect

set timeout 5
log_user 1
set hostlist "pandaap01"
foreach host $hostlist {
set prompt [append $host "#"]
set promptcfg [append $prompt "(config)#"]
spawn telnet $host
expect $prompt
send "conf t\r"
expect $promptcfg
send "int dot11radio0\r"
expect $promptcfg
send "shut\r"
expect $promptcfg
send "end\r"
}

Friday, December 18, 2009

Script to backup Cisco Device Config

A handy expect script on Linux to backup your routers, switches, AP, or other IOS devices configuration.  Make sure you have “expect” installed on your Linux box.

#!/usr/bin/expect

set timeout 5
log_user 1

# Include your hosts in the hostlist
set hostlist "rt01 rt02 sw01 sw02"
foreach host $hostlist {
set prompt [append $host "#"]
spawn telnet $host
expect $prompt
send "term len 0\r"
expect $prompt
set time [exec date \+\%y\%m\%dT\%H\%MJ]
set filename [append host "-" $time]

# The config file storage location
log_file /home/pandaeatsbamboo/cfgbackup/$filename
send "show run\r"
expect $prompt
send "exit\r"
log_file
}

Tuesday, December 15, 2009

CIFS Mounted Drive for Apache

My environment: Apache 2.2.9 on Fedora Core 10 x86_64

Although it is not a good idea to do something like this, I’ve come across a case that I need to mount a CIFS drive and serve the content inside for an apache web server on Linux.  After some googling, the trick to make this work is to turn off a parameter called EnableSendfile in httpd.conf

#
# EnableSendfile: Control whether the sendfile kernel support is
# used to deliver files (assuming that the OS supports it).
# The default is on; turn this off if you serve from NFS-mounted
# filesystems.  Please see
#
http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile
#
EnableSendfile off

Sunday, December 6, 2009

IPv6 PTR Record configuration in BIND

My environment: RedHat Fedora Core 12 x86_64

BIND version: bind-9.6.1-11.P1.fc12.x86_64

Let’s see an example how to configure IPv6 reverse lookup record in BIND.

Forward Lookup:

www   AAAA   2001:123:45:678:20c:29ff:fe6a:7f93

It just like normal IPv4 host record, except it is a “AAAA” record instead of an “A” record.

Reverse Lookup zone configuration in named.conf:

zone "8.7.6.0.5.4.0.0.3.2.1.0.1.0.0.2.ip6.arpa" {
        type master;
        file "2001.123.45.678-db";
};

The name of the zone is the reverse of the /64 prefix 2001:123:45:678::/64

In the reverse lookup zone file, the PTR record is:

3.9.f.7.a.6.e.f.f.f.9.2.c.0.2.0   IN   PTR   www

The PTR record is the reverse of the host portion of the IPv6 address.

Try a dig -x 2001:123:45:678:20c:29ff:fe6a:7f93 and see if the BIND server replies with the reverse lookup record correctly.

Friday, August 14, 2009

802.1q configuration on Linux

My environment: RH FC8 x86_64

1. Make sure the 802.1q module is added to the kernel 

modprobe 8021q

2. Add a subinterface.  In this example 170 is the 802.1q VLAN ID.

vconfig add eth0 170

3. Create the NIC configuration file

/etc/sysconfig/network-scripts/ifcfg-eth0.170

DEVICE=eth0.170
BOOTPROTO=none
IPADDR=192.168.170.1
NETMASK=255.255.255.0

4. Restart the network service

/etc/init.d/network restart

Tuesday, August 4, 2009

Configuring IPv6 address on Linux

My environment: RH FC8 x86_64

To enable IPv6 globally, modify the file

# vi /etc/sysconfig/network

And append the following:

NETWORKING_IPV6=yes

Then change the NIC config file

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

And append the following IPv6 parameters:

IPV6INIT=yes
IPV6ADDR=<IPv6-IP-Address>
IPV6_DEFAULTGW=<IPv6-IP-Gateway-Address>

If you want to acquire the IPv6 address via DHCPv6 server, first make sure you have the DHCPv6 client installed:

# rpm –q dhcpv6-client

then modifiy the NIC config file and append the following parameters:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

IPV6INIT=yes
DHCPV6C=yes

Edit the main DHCPv6 client config file

# cp /usr/share/doc/dhcpv6-client-*/dhcp6c.conf /etc/
# vi /etc/dhcp6c.conf

interface eth0 {
    send rapid-commit;
    request domain-name-servers;
};

Restart the network service

# /etc/init.d/network restart

Then check your eth0 configuration to make sure you get the ipv6 address:

# ifconfig eth0

Monday, July 27, 2009

Enable RH FC 10 root login

My environment: RH FC 10 x86_64

Although it is not recommended to login GNOME GUI as root, sometimes you just need to do it.  Firstly, type the following in your terminal prompt:

1. su

2. Enter your root password
3. vi /etc/pam.d/gdm

and comment the following line:

# auth required pam_succeed_if.so user != root quiet

Sunday, July 19, 2009

Getting Flash Player to work on 64-bit Linux

My environment: RH FC8 x86_64
Flash Player version: 10.0.22.87
Firefox version: 3.0.9

Adobe has released an alpha version of flash player on 64-bit Linux and to get this working on your 64-bit Linux box, go to Adobe site to download the shared object library:

http://labs.adobe.com/downloads/flashplayer10.html

Untar the file then you will get the flash player .so file:
libflashplayer.so

Copy it to ~/.mozilla/plugins, if the folder doesn't exist, create the folder by yourselves. Restart the browser then you are now able to view Flash content via your firefox on your 64-bit Linux box.

Monday, July 13, 2009

Clear the route cache on your Linux box

My environment: RH FC8 x86_64

Routing cache is a hash table in the kernel which contains recently used routes.  I have had a problem about traceroute on my Linux box after changing the default route, it still redirecting the packets to the old default gateway.  So what I have done is to remove the route cache.

To show the route cache:

ip route show cache

To clear the route cache:

ip route flush cache

Slow Performance when query MySQL Database

My environment: RH FC8 X86_64

MySQL server version: mysql-server-5.0.45-6.fc8

Just hit a problem that takes me several hours to get it solve.  The symptom is extremely slow performance when connecting the database remotely either via JDBC connection from my JSP page or using MySQL front GUI.

After hours and hours of troubleshooting, I’ve found out the MySQL server need some sort of DNS lookup when an external client attempts to connect to it, and in my demo environment unfortunately the name server is down.

The trick is to comment the name server entry in /etc/resolv.conf.  After I did that, it resumes to normal!

Thursday, June 4, 2009

Pktgen – a tool to generate packets at very high speed in the kernel

My environment: RedHat Fedora Core 8 x86_64

Firstly check if your pktgen is running:

[root@pandaeatsbamboo pktgen]# ps -e | grep pktgen
8913 ?        00:01:55 kpktgend_0
8914 ?        00:01:55 kpktgend_1
8915 ?        00:00:01 kpktgend_2
8916 ?        00:00:01 kpktgend_3


I have a quad-core AMD CPU therefore you will see 4 processes there.  Pktgen creates 1 thread per CPU.

If you can’t see that, try to:
modprobe pktgen

I have 2 NIC card, eth0 and eth1, here is my sample shell script to kick start the pktgen:

#! /bin/sh



 



#modprobe pktgen



 



 



function pgset() {



    local result



 



    echo $1 > $PGDEV



 



    result=`cat $PGDEV | fgrep "Result: OK:"`



    if [ "$result" = "" ]; then



         cat $PGDEV | fgrep Result:



    fi



}



 



function pg() {



    echo inject > $PGDEV



    cat $PGDEV



}



 



# Config Start Here -----------------------------------------------------------



 



 



# thread config



# Each CPU has own thread. Two CPU exammple. We add eth1, eth2 respectivly.



 



PGDEV=/proc/net/pktgen/kpktgend_0



  echo "Removing all devices"



 pgset "rem_device_all"



  echo "Adding eth0"



 pgset "add_device eth0"



  echo "Setting max_before_softirq 10000"



 pgset "max_before_softirq 10000"



 



PGDEV=/proc/net/pktgen/kpktgend_1



  echo "Removing all devices"



 pgset "rem_device_all"



  echo "Adding eth1"



 pgset "add_device eth1"



  echo "Setting max_before_softirq 10000"



 pgset "max_before_softirq 10000"



 



 



# device config



# delay 0 means maximum speed.



 



CLONE_SKB="clone_skb 1000000"



# NIC adds 4 bytes CRC



PKT_SIZE="pkt_size 60"



 



# COUNT 0 means forever



#COUNT="count 0"



COUNT="count 10000000"



DELAY="delay 0"



 



PGDEV=/proc/net/pktgen/eth0



  echo "Configuring $PGDEV"



 pgset "$COUNT"



 pgset "$CLONE_SKB"



 pgset "$PKT_SIZE"



 pgset "$DELAY"



 pgset "dst 168.106.1.248"



 pgset "dst_mac  00:24:51:13:06:41"



 



PGDEV=/proc/net/pktgen/eth1



  echo "Configuring $PGDEV"



 pgset "$COUNT"



 pgset "$CLONE_SKB"



 pgset "$PKT_SIZE"



 pgset "$DELAY"



 pgset "dst 192.168.10.1"



 pgset "dst_mac  00:24:51:13:06:43"



 



# Time to run



PGDEV=/proc/net/pktgen/pgctrl



 



 echo "Running... ctrl^C to stop"



 pgset "start"



 echo "Done"




To view the statistics, check the files in /proc/net/pktgen/ethX





[root@pandaeatsbamboo pktgen]# less /proc/net/pktgen/eth0



Params: count 10000000  min_pkt_size: 60  max_pkt_size: 60



     frags: 0  delay: 0  clone_skb: 1000000  ifname: eth0



     flows: 0 flowlen: 0



     queue_map_min: 0  queue_map_max: 0



     dst_min: 168.106.1.248  dst_max:



     src_min:   src_max:



     src_mac: 00:1f:d0:50:19:6d dst_mac: 00:24:51:13:06:41



     udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9



     src_mac_count: 0  dst_mac_count: 0



     Flags:



Current:



     pkts-sofar: 10000000  errors: 0



     started: 1244025262231283us  stopped: 1244025310237392us idle: 11640574us



     seq_num: 10000001  cur_dst_mac_offset: 0  cur_src_mac_offset: 0



     cur_saddr: 0xfa016aa8  cur_daddr: 0xf8016aa8



     cur_udp_dst: 9  cur_udp_src: 9



     cur_queue_map: 0



     flows: 0



Result: OK: 48006109(c36365535+d11640574) usec, 10000000 (60byte,0frags)



  208306pps 99Mb/sec (99986880bps) errors: 0




To learn more you can visit here:



http://www.linuxfoundation.org/en/Net:Pktgen

Wednesday, April 29, 2009

Playing ASF on Linux

My environment: RH FC 10 x86_64

To play asf file on linux, you can use VLC as your media player. To install VLC by yum:

1. rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm

2. yum install vlc

Tuesday, April 28, 2009

Network backup with Rsync

My environment: RH FC8 x86_64
Rsync Version: rsync-2.6.9-3.2.fc8

 

1. Enable rsync server in xinetd:

vi /etc/xinetd.d/rsync

disable = no

2. Start xinetd on server side

3. Generate password-less inter-host key for SSH connection between rsync server and client.  Follow the tutorial here.

4. Run this on rsync server:

rsync -ave ssh --numeric-ids rsync-client-hostname:/files-to-be-backup /backup-location-on-server

Thursday, April 9, 2009

Create public folder on samba

My environment: Samba 3.0.28 on RH FC8

Nothing better than learn by example, let see the following 2 examples on /etc/samba/smb.conf to create a writable and read-only share

Writable share - A publicly accessible directory, but read only, except for people in software group

[software]
comment = Software Share
path = /media/disk/software
public = yes
writable = yes
printable = no
browseable = yes
write list = +software

A read-only share

[VM]
comment = VM
path = /media/disk/VM
public = yes
writable = no
printable = no
browseable = yes

Start your samba server in 5 mins

My environment: Samba 3.0.28 on RH FC8

Again it’s time for our quick and dirty series – the samba episode.  Let's create a samba share in 5 mins!

1. Make sure you have samba server installed.  If not, yum –y install samba-common
2. Add your existing users to samba, say I have an user pandaeatsbamboo already in the system:
smbpasswd -a pandaeatsbamboo
3. Restart your samba server:

/etc/init.d/smb restart

4. Access your share via UNC path, \\192.168.1.10 and you’ll see your home folder as a shared folder.

Friday, April 3, 2009

Quick and Dirty way to allow remote access to your MySQL server

I usually do this in my lab environment.  I'm sure you will use it with care when you do it in production environment, and to make it more securely and restrictive.

GRANT ALL ON *.* TO 'someuser'@'somehost';

'somehost' could be '%', it will allow all hosts to access.  Again use it with great care!

Then you can use some GUI tools (e.g. MySQL-Front, my favorite GUI for MySQL) to remote access and administer your MySQL database.

http://dev.mysql.com/doc/refman/5.1/en/grant.html

Basic Text-to-Speech example with Festival

My environment: Festival 1.9.6 on RH FC8

A simple example on Festival TTS

echo “I love to visit this blog and I’m going to visit it everyday” | text2wave -o pandaeatsbamboo.wav

External Database integration with Cisco Unified Contact Center Express 5.0

My environment:

Unified Communications Manager 6.1

Unified Contact Center 5.0

MySQL Server 5.0.45 on RH FC8

You can use query or update the external database (e.g. MySQL in my example) in your call flow, by creating an aef script with Cisco CRS Editor. 

1. Download MySQL ODBC connector from MySQL’s website:

http://dev.mysql.com/downloads/connector/odbc/5.1.html

2. Install it on the CRS server.  Add a new system DSN in Administrative tools > Data Sources (ODBC).

mysql-connector

3. Under CRS Web admin page, go to Subsystems > Database, add a new datasource.

image

image

4. In CRS Editor, create a script or modify your existing script using the Database Steps.  Below are several example screen shots on how to use the Database Steps.

DB Read Step

image

Press “Refresh Database Schema” if you don’t see the data source name you’ve just created in step 3.

image

DB Get Step

You should define DB Read Step before the DB Get Step.  DB Read step is used to define the SQL statement, and DB Get step is used to store the resultset to local variable.

image

image

DB Write Step

DB Write Step is used for INSERT and UPDATE statement.

image

image

The last one DB release step is used to release the database connection.

Playing Audio file on Cisco Digital Media Player

My environment:

Cisco Digital Media Player 4400, version 5.0.2

Cisco Digital Media Manager 5.0.2

It is easy to play video on digital media player, you just need to put your video file link in the video playlist via the digital media designer (DMD).  But if you want to play an audio file on DMP, it is not supported natively in this version.  So the workaround is you can convert the audio file to a video file.  One of the option is using Cisco Media Experience Engine (MXE) 3000, another alternative is to use an open source utility ffmpeg.  Here is an example on to do the conversion:

ffmpeg -i /var/www/html/dms/audio.wav -target pal-vcd /var/www/html/dms/video.mpg

Put the resulting video file inside the video playlist then you can play this “audio” on DMP!