Archive for the 'linux' Category

Music Radio Alarm

(I reposted this because of server migrations incase anyone noticed)
6 hours of my lesson-free day was fighting against my >8 years aged server. I lost the battle with some cuts on my fingers.
Instead of a bad configuration, it seems a faulty network card was playing me out. Lesson learned: If it ain’t broke don’t double fix it. If the server ain’t going to work anymore, there’s no point keeping this post as a draft, gotta publish it now.

Back to the topic, my father brought home a portable Philips radio combined with a Cd player and alarm clock years ago. My impression it wasn’t a very good audio player, its features and sound quality was just minimal. However, there was still few interesting and useful features. It served as clock and I also used it to set my morning alarms to interrupt my dreams by either

a) Turning on a FM station
b) Playing tracks of my CDs, or
c) Sounding alarms likes beeps and rings.

You could set to 2 alarms on it, so I usually turn on the 1st alarm to the CD tracks, then blast the noisy alarms 10 to 60 minutes later. The 1st alarms is for switching my body into a light sleep, and starts the engine of my subconscious mind. If I’m still in deep sleep, the loud sounding alarms is the last line of defense not to be late for school.

There were few CD tracks that never fail to wake me up- Carmen’s fantasy, Walton’s violin sonatas, Stravinsky’s Rite of Spring and so on… some tracks made me want to lie in bed to hear the songs- Bach’s Brandenburg Concerto 5…

That’s for waking up. For sleeping, I’ll set the timer to turn off the CD or Radio after a period of time. It seems to me I never get to sleep soon if my mind is actively listening to classical music.

— if you are not a computer geek you can stop reading right here —

Here’s did an equivalent on my server plugged to speakers. 4 linux commands I used: screen, mplayer, sleep, killall.

I start my ssh session with putty to my and run screen -r

1. Play lullaby softly
mplayer http://audio-ogg.ibiblio.org:8000/wcpe.ogg -cache 256 -af volume=-5dB
This plays WCPE, the online classical radio at a softer volume. I move to another screen window for the next step (^A,n)

2. Silence the lullaby
sleep 15m && killall mplayer
Sleep here is used sort of like a countdown timer. Here, 15 minutes later, the mplayer is terminated for silence. We need another window for the next step.

3. Countdown the alarm
sleep 3.5h && radio.sh
This shows I want the radio to be turned on again after 3 and a half hours to wake me up…

Thats not too much sleep isn’t it? La la la… ZzZzZZZzZ

In a Data Center

I’ve been to server rooms, power control stations but a data center feels different.

Data Center

Like in those movies, multiple sliding gates with biometric access control, engineers on shift monitoring screens, plenty of close circuit cameras, air-conditional room, tons of cables running under the floor, rows after rows of racks of servers and wires.

A $2k server rack is slide into place, power and ethernet cables attached. Monitor, keyboard placed on a trolley is rolled near for connection like a life support unit. The power button pushed, the small but powerful fans hums along with the symphonies of fan noise in the data center.

The network installed CentOS, the free enterprise Red Hat Linux, runs the server. Due to my personal discrimination against RH since version 6, I had to adapt to its environment.

/etc/sysconfig/network-scripts was the place where ip, dns addreses and network configurations was. system-config-securitylevel configures the firewall, yum installs, manages and updates the system. Guides exist online. Some other commands to configure and control services. I also discovered write and talk. The rest is usual linux.

http://www.lab4solutions.com is sparkling into life.

NUS Network From Home

Tunneling, VPN, proxy whatever you call it, its one the fields I forte.

NUS VPN
http://www.nus.edu.sg/vpn/usage.html

SOC VPN
https://noc.comp.nus.edu.sg/vpn

NUS WebVPN
http://webvpn.nus.edu.sg

NUS Proxy Server
proxy.nus.edu.sg:8080

NUS Domain
http://spnp.nus.edu.sg/

Whats the use? You use it when you need some resources which is only accessible from campus (intranet).

Here’s something not so obvious. You can access intranet using SOC’s unix account.

SSH. Its more than just an secured telnet. Services can be tunnelled through it. Example? Secured File Transfer.

More fun? Forward the remote port 1755 (host: live-vip-49.nus.edu.sg) locally to get the streams available only in campus. (Hint: see http://nuscast.nus.edu.sg/)

Whats next? Nus Naxos Music Library using its library web proxying service. http://lib.nus.edu.sg/

My networking module has begun to get more exciting. (New web server to code soon perhaps?)

7 Lines Of Linux Shell Scripting

A cousin asked me help him find a solution to extract html from hundreds of links into excel cells.

Telling him the limitations it, he ask me to place them in cvs format.

I start up my putty, ssh into my linux server, and coded this.

run.sh

echo URL,HTML > csv
for link in $(cat links)
do
        wget -Otmp $link
        perl -pi -e "s/\"/\"\"/g;" tmp
        echo $link,\"`cat tmp`\" >> csv
done

Lets take a look closer.
Line 1: Creates/overwrites a file called cvs with the text “URL,HTML” which is the header for the cvs file
Line 2: I placed all the URLs in file call links, 1 per line. The for in structure would loop each link
Line 3: do … done (see line 7) block would repeat the commands until all the links are processed (line 2)
Line 4: using wget to save the url (the variable $link) to a file named tmp
Line 5: This line replaces all single ” to double ” quotes (”") for differentiating in the csv file. This amazing line using perl to perform regex (regular expression) substitution (search & replace) on the tmp file. Take s/baba/haha/g, means substitute(s) baba (/baba) with haha (/haha/) on all matches (g)
Line 6: Inserts the URL, the html code enclosed in quotes (therefore requiring line 5), separated by a comma (hence comma separated values for CSV), appends to the output file csv
Line 7: See line 3

Run it by the usual commands
chmod +x run.sh
./run.sh

Then retrieve the resulting csv file via ftp.

Although not this is not the only way to code it, I pretty satisfied I could code something efficient, does some work, few a few lines of code in a short time.

This are what computers and programming for. To do work for us efficiently, although many a times in the real world it happens the opposite.

Setting up a Linux Bridge

Mentioned in MIO is here, at last, I needed a bridge to trick/configure the router into recognising my 5th cat5e/ethernet wired pc.

A network bridge (before my cisco networking license and memory end soon)
* Connects 2 or more networks together
* Usually transparent in a network (unless an interface is created, like in a firewalled bridge, like in this case)
* A layer 2 device- less lag when compared a router (a layer 3 device) and therefore faster(?)
* Same broadcast domain, same subnet address
* Different collision domains, preventing the networks to split the wire’s bandwidth.

Here is a script I used to test out if my bridge could work

#bridgeman.sh
# Create the interface br0
/usr/sbin/brctl addbr br0

# Add the Ethernet interface to use with the bridge
/usr/sbin/brctl addif br0 eth0
/usr/sbin/brctl addif br0 eth1

# Start up the Ethernet interface
/sbin/ifconfig eth0 0.0.0.0
/sbin/ifconfig eth1 0.0.0.0

# Configure the bridge Ethernet
# The bridge will be correct and invisible ( transparent firewall ).
# It’s hidden in a traceroute and you keep your real gateway on the
# other computers. Now if you want you can config a gateway on your
# bridge and choose it as your new gateway for the other computers.
/sbin/ifconfig br0 192.168.1.66 netmask 255.255.255.0

run chmod +x bridgeman.sh

Note that the last line in the script was fairly important as I configure my router remotely via ssh. I first time I tried configuring a bridge, I added no interface the bridge, so by the time enabled the bridge interface, the linux box became transparent to the network and my ssh connection was dropped (that is different of course if you are configuring at the local terminal).

This is the configuration I used in /etc/network/interfaces for automatic startup/restart situations

# The bridge network interface(s)
auto br0
iface br0 inet dhcp
       bridge_ports eth0 eth1

Links
http://linux-net.osdl.org/index.php/Bridge
http://www.debian.org/doc/manuals/securing-debian-howto/ap-bridge-fw.en.html

http://forums.invisionpower.com/index.php?showtopic=187910
http://compsoc.dur.ac.uk/~djw/qemu.html
http://affix.sourceforge.net/affix-newdoc/Affix-enduser/x199.html