Thursday, June 30, 2011

Using grep to extract specific FIX protocol tags values from a file

grep -o -w '\(48\|55\)=[^[:cntrl:]]\+' FILE | perl -pe 's/(\d+=[^\n]+)\n/\1~/' | perl -pe 's/([^~]+~[^~]+)~/\1\n/g'

grep -o -w '\(48\|55\)=[^[:cntrl:]]\+' FILE | tr '\n' '~' | perl -pe 's/([^~]+~[^~]+)~/\1\n/g'

grep -o -w '\(48\|55\)=[^[:cntrl:]]\+' FILE | sed 'N;s/\n/ /'

-o Print only the matched parts of a matching line
-w Select lines containing matches that form whole words (a whole char is a letter, digit and underscore)

Tuesday, June 28, 2011

Static routes after restart/reboot in Fedora/RedHat/CentOS

Static routing is the term used to refer to the manual method used to set up routing. An administrator enters routes into the router using configuration commands. This method has the advantage of being predictable, and simple to set up. It is easy to manage in small networks but does not scale well.

Question: How can I save static routes I set up in my Fedora/RedHat/CentOS Linux after I reboot server?

Answer: In Fedora Linux (or RedHat, CentOS) you can set up static routes for certain network interface (for example eth1) by editing file /etc/sysconfig/network-scripts/route-eth1.

For example, you have to save static route added by the following command:

route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.100.1 dev eth1

To do it, just add the following line to /etc/sysconfig/network-scripts/route-eth1:

ADDRESS0=192.168.0.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.100.1

The alternate way of doing it is to put the routes in /etc/sysconfig/static-routes. So the above route would like this like in the static-routes file:

any net 192.168.0.0 netmask 255.255.255.0 gw 192.168.100.1

Where any is specified above you can also set specific interfaces (such as eth1).

Here is the part /etc/init.d/interfaces code:

# Add non interface-specific static-routes.
if [ -f /etc/sysconfig/static-routes ]; then
grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
/sbin/route add -$args
done
fi

Looks like any must be at the beginning of each line in /etc/sysconfig/static-routes.

/usr/share/doc/initscripts-${VERSION}/sysconfig.txt is a good place to look for these things as well

Friday, June 24, 2011

basename and dirname in UNIXes

I was reading The Unix For Loop today and I found that the following code will fail in the case of a filename like anoldfilename.old:

for i in *.old 
do 
j=`echo $i|sed 's/old/bak/'` 
mv $i $j 
done

I think the following will solve that problem:

j=`basename $i .old`
p=`dirname $i`

mv $i $p/$j.bak


The right tool for the right job!

AWK and Java CLASSPATH

From http://unix-simple.blogspot.com/2008/12/dynamically-building-java-classpaths.html

for line in $java_dir/*.jar
do
  CLASSPATH="$CLASSPATH:$line"
done

Lets put AWK to iterate:

CLASSPATH=$CLASSPATH:$(ls *.jar | awk 'BEGIN { ORS = ":" } { print }')

Maybe a shellish way of do it:

CLASSPATH=$CLASSPATH:`echo *.jar | sed 's/ /:/g'`

Tuesday, June 21, 2011

Prosperity Gospel: Christ Centered or Self Centered?

 The Word of Faith 'Prosperity Gospel' Promotes Material Over Spiritual Needs

Taken from: http://christianity.about.com/od/Word-Of-Faith/a/Prosperity-Gospel.htm?nl=1

Prosperity Gospel: Is Greed a Motive?

"Woe to you, teachers of the law and Pharisees, you hypocrites! You clean the outside of the cup and dish, but inside they are full of greed and self-indulgence." (Matthew 23:25, NIV)

"Watch out! Be on your guard against all kinds of greed; life does not consist in an abundance of possessions." (Luke 12:15, NIV)

"What good is it for someone to gain the whole world, and yet lose or forfeit their very self?" (Luke 9:25, NIV)


Prosperity Gospel: Was Jesus Rich or Poor?

"After this, Jesus traveled about from one town and village to another, proclaiming the good news of the kingdom of God. The Twelve were with him, and also some women who had been cured of evil spirits and diseases: Mary (called Magdalene) from whom seven demons had come out; Joanna the wife of Chuza, the manager of Herod's household; Susanna; and many others. These women were helping to support them out of their own means." Luke 8:1-3 (NIV)

Prosperity Gospel: Do Riches Make Us Right with God?

"Do not store up for yourselves treasures on earth, where moths and vermin destroy, and where thieves break in and steal. But store up for yourselves treasures in heaven, where moths and vermin do not destroy, and where thieves do not break in and steal. For where your treasure is, there your heart will be also...No one can serve two masters. Either you will hate the one and love the other, or you will be devoted to the one and despise the other. You cannot serve both God and money." (Matthew 6:19-21, 23, NIV)

Wealth may build people up in the eyes of men, but it does not impress God. In talking with a rich man, Jesus looked at him and said, 'How hard it is for the rich to enter the kingdom of God!' (Luke 18:24, NIV)

"But godliness with contentment is great gain. For we brought nothing into the world, and we can take nothing out of it. But if we have food and clothing, we will be content with that. Those who want to get rich fall into temptation and a trap and into many foolish and harmful desires that plunge people into ruin and destruction." (1 Timothy 6:6-9, NIV)


Thursday, June 16, 2011

Mounting LVM Disk using Ubuntu livecd

Mounting is an easy process to do, provided the filesystem type you are using is supported. What happen when you have an LVM formatted disk, and you need to mount it because the disk cannot be booted and a hell lot of valuable data kept inside?? Do not worry, because the solution is here.......

1. Get a live cd, for example, Ubuntu. For this article, I use Ubuntu 6.06 (I cannot find any latest version of ubuntu at my place)

2. Boot using the live cd. Search for these tools: lvm2. If the cd do not have it, install it.
# apt-get install lvm2

3. To make sure the harddisk is recognised, you can use fdisk
# fdisk -lu

4. Once installed, run pvscan to scan all disks for physical volume. this to make sure your LVM harddisk is detected by Ubuntu
# pvscan
PV /dev/sda2 VG VolGroup00 lvm2 [74.41 GB / 32.00 MB free]
Total: 1 [74.41 GB] / in use: 1 [74.41 GB] / in no VG: 0 [0 ]

5. After that run vgscan to scan disks for volume groups.
# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VolGroup00" using metadata type lvm2


6. Activate all volume groups available.
# vgchange -a y
2 logical volume(s) in volume group "VolGroup00" now active

7. Run lvscan to scan all disks for logical volume. You can see partitions inside the hard disk now active.
# lvscan
ACTIVE '/dev/VolGroup00/LogVol00' [72.44 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [1.94 GB] inherit

8. Mount the partition to any directory you want, usually to /mnt
# mount /dev/VolGroup00/LogVol00 /mnt

9. You can access the partition in the /mnt directory and can backup your data


(Taken from http://linuxwave.blogspot.com/2007/11/mounting-lvm-disk-using-ubuntu-livecd.html)

Brief Notes on Enabling Samba in OpenSolaris

I've been experimenting with OpenSolaris again. I figured out how to enable my broken samba package: I discovered that, after installing the package with

pfexec pkg install SUNWsmbs SUNWsmba

I had to execute:

svccfg import /var/svc/manifest/network/samba.xml

I then copied /etc/sfw/smb.conf-example and modified appropriate values, and created a configuration file that was saved to:

/etc/sfw/smb.conf

Finally, I could enable the SAMBA server:

svcadm enable samba
(taken from: http://baitisj.blogspot.com/2008/07/quick-notes-on-enabling-samba-in.html)

Wednesday, June 1, 2011

Ubuntu nasty bug

pam update causes cron to stop working with "Module is unknown" error

https://bugs.launchpad.net/ubuntu/+source/pam/+bug/790538