Linux Blog

Comment spam vent and an idea to combat it

Filed under: General Linux,The Linux Blog News — TheLinuxBlog.com at 10:48 am on Thursday, September 27, 2007

Ok I just have to vent a little. Spam Spam Spam. Spam bots and blog spammers in general are stupid. Why would you spam a site that doesn’t even have comments on blog posts? I don’t get it. I would love to get my hands on the code of these spam bots to see how they are working. It would be so simple for them to actually load the page and grep for the comment link. That way they could stop wasting mine and their time by spamming this site. All comments are marked as spam at the moment since that’s all I’m getting. If some one wants to send me a comment they could go trough the trouble of creating a <FORM> to send one but I think they would just send me mail at owen -at- <thelinuxblog.com>. This generally means that I can delete all of the comments I get as I doubt any one is really going to create a form just to send me a comment.

IP addresses are being recorded and I’ll continue to monitor the situation. Eventually I might do a security scan on repeat offenders and let the ISP of the host know what’s what. It would be nice to catch the spammer but I will settle for the knowing that the owners of the Zombie PC have been warned about the consequences and might send their computer in for repair.

After writing this post I have an idea for a Linux Blog project. The Linux Blog can be the first to submit data. Basically I propose a plugin for WordPress that would monitor comments and send the IP’s of those that were spam (either flagged manually or automatically) to a host. This host would log all of the IP’s submitted and when appropriate take action against them.
This reminds me of a project that I saw a presentation on at CarolinaCon 05. Except this project was targeted at bot nets and aimed to be malicious back or ban the host / subnet completely. This would not be necessary for this project; just a simple mail merge application written in Linux would work.
I suppose the real first step is to see if this application already exists. I’m sure I’m not the first person to think of this.
I guess I need to come up with a quirky name for the project and a plan. It goes without saying that the platform will be Linux and will use open source applications to achieve the final goal. Once research has been done I can either try to add it to my never ending list of projects to complete or find a team of developers willing to work on it.

Two Screens, Two Linux Boxes – One Keyboard and Mouse

Filed under: General Linux,Quick Linux Tutorials — TheLinuxBlog.com at 8:50 am on Wednesday, September 26, 2007

Ever wished you could use your keyboard and mouse on another computer? In this article I will show you how.
To read it it should take about 60 seconds. In this time I’ll show you how to use one keyboard and mouse on two Linux machines. I’ll cover how to use the same keyboard and mouse on a Linux and Windows machine in another article.

Ready? Lets go!

First Decide which keyboard and mouse you want to use across multiple monitors on different machines and sit at that computer. The program needed to get this to work is called x2x.
As of this writing the stable version is 1.27

Download the stable version from http://x2x.dottedmag.net/

wget http://x2x.dottedmag.net/releases/x2x-1.27.tar.gz

Extract The Source code

tar xvzf x2x-1.27.tar.gz

Compile x2x

./configure && make && make install

If x2x compiled without any errors you should be good to run the program.
On the computer you want to use your primary keyboard and mouse on do the following:
Find out your IP

/sbin/ifconfig ethX

Run xhost to allow clients to connect to your display:

xhost +

Going back to your original computer decide which side of the monitor you want your mouse to jump to the other computer on. It will either be North, South, East or West. If your second linux box is on your left like mine, it will be west.
Now lets get the two computers connected with the same keyboard and mouse:

x2x 192.168.X.X:0.0 -west

Thats all there is to it. You should be able to mouse over the right of your screen and see your mouse cursor on the other computer.

Introduction to CHMOD – Octal Format

Filed under: General Linux,Quick Linux Tutorials — TheLinuxBlog.com at 1:25 pm on Tuesday, September 25, 2007

CHMOD is used to change permissions on a file. There are three types of permissions read, write, execute and there are three types that permissions can be set for owner, group and other.
It can be used with a symbolic representation or with an octal number that represents the bits. This blog post features on just the octal format. CHMOD works on most Linux file systems. It is also used on other operating systems such as BSD. Web designers and developers may be familiar with CHMOD as they have to set permissions when uploading files via FTP.

The octal notation can seem quite confusing but is actually very simple.
To figure out the octal format take the following table:

  Owner Group Other
Read 4 4 4
Write 2 2 2
Execute 1 1 1

To figure out the octal method just add up the sum of what you want to set the permissions to.
If you would like to set the permissions for the owner to read, write execute and the group/other to read and execute you would do the following:

  Owner Group Other
Read 4 4 4
Write 2 2 2
Execute 1 1 1
Add: 7 5 5

Its that simple. The way I remember the numbers to the corresponding permission is to remember that the number starts with 4 and is divided by two and then I repeat the following:
“For Read, Two Write, Execute”
meaning that 4 is read, 2 is write and the last (1) is execute.

There are graphical utilities that set permissions such as Thunar in XFCE and Konqeuror for KDE, but they normally do not allow you to change the permissions on multiple files at once.

If you have a whole directory full of files that you would like to change permissions on, you can simply do:

chmod 755 *

* is a wild card or regex and tells chmod to change permissions on all files.

If you would like chmod to go into directories and change permissions on files, the -R option is used.

chmod 755 -R *

will change permissions on all files and dive into the folders also.

chmod is an absolute must for system administrators and is good to know for home Linux users. If your experimenting with chmod be careful and do not use the -R option unless your absolutly sure you need to. I have accidentally used chmod to recursivly change permissions on a whole drive before. Lets leave it at this was not what I call a fun time since I had changed them to a very open 777.

Take that as your warning.

Quickly checking the weather with telnet

Filed under: General Linux — TheLinuxBlog.com at 7:15 pm on Monday, September 24, 2007

Its always good to know what the weather is or is forecasted to be over the next week, however loading a webpage such as weather.com is time consuming and unnecsary when alternatives are available.

When I quickly want to check the weather, I do so by using telnet. Its quick, has no advertisements and is exactly the same information that is shown on major weather websites. Most have heard of wunderground it is a great website, but if you just want a text based listing of what the weather is going to be just use their telnet service.

telnet rainmaker.wunderground.com

Once a connection has been made hit enter to get past the prompt and enter a city code. Since I happen to live in Charlotte at the moment my city code is CLT. So I just type in CLT and my forecast is displayed.
If you don’t know your city code you can look it up.
Hit return at the prompt, and then press 1 for US weather. Press 3 to look up city codes by state and then enter your state. Pick the closest city and remember the code. Press M to start your search and enter your city code. Then your weather forecast will be displayed.

Thats all there is to it. Next time you want to quickly check the weather consider using telnet. Its a great alternative to loading a whole website with advertisements.

Using BASH to sort a book collection. ISBN Data Mining – Part 2

Filed under: Shell Script Sundays — TheLinuxBlog.com at 8:49 pm on Sunday, September 23, 2007

Last weeks article used a bit of data mining to grab information on ISBN’s from Barnes and Noble and dumped the information into a text file. This week we’ll take those text files and format the data for input into a MySQL database. This tutorial assumes that you are familiar with MySQL.

The data that was written to the text files was in the following format:

Title: DNS and BIND, Third Edition
Title:
Author(s): Paul Albitz, Mike Loukides (Editor)
Publisher: O'Reilly Media, Incorporated
Pub. Date: September 1998
ISBN: 1565925122
Format: Paperback, 480pp
Edition Number: 3
Edition Description: Older Edition
Customer Rating:

This can easily be parsed and formatted for insertion into a MySQL table.

Firstly a database has to be created and then a table structure has to be decided upon. Since this example already has the titles, I’ll just use simular ones for the field names.
Create a database called book_info:

mysqladmin -u root create book_info;

and now create a table within the book_info database that is to contain all of the data:

CREATE TABLE `books` (
`ISBN` INT( 10 ) NOT NULL ,
`title` VARCHAR( 50 ) NOT NULL ,
`author` VARCHAR( 80 ) NOT NULL ,
`publisher` VARCHAR( 50 ) NOT NULL ,
`pub_date` VARCHAR( 50 ) NOT NULL ,
`format` VARCHAR( 30 ) NOT NULL ,
`edition` INT( 2 ) NOT NULL ,
INDEX ( `ISBN` )
) ENGINE = MYISAM ;

This isn’t the best MySQL table structure ever, but it will do for the purposes of this artice and besides it can always be tuned later.

With a directory full of .txt’s files from the last issue of shell script sundays the following can be ran to create a text file called bookQuery.sql.

for i in $(ls); do
echo "INSERT INTO \`book_info\`.\`books\` (\`ISBN\`, \`title\`, \`author\`, \`publisher\`, \`pub_date\`, \`format\`, \`edition\`) VALUES ('$(cat $i | grep ISBN:)', '$(cat $i | grep Title | sed 'q' | sed "s/'/\\\\'/")', '$(cat $i | grep Author\(s\): | sed "s/'/\\\\'/")', '$(cat $i | grep Publisher: |sed "s/'/\\\\'/")', '$(cat $i | grep Date:| sed "s/'/\\\\'/")', '$(cat $i | grep Format: | sed "s/'/\\\\'/")', '$(cat $i | grep Edition\ Number: | sed "s/'/\\\\'/")');" >> bookQuery.sql; done;

In turn this file can be imported into the table that was created by running the following:

mysql -u root < bookQuery.sql

Whats happening is pretty simple, cat reads the file and grep is used to find the line of text we want to import. After that sed is used. It is used twice in the title field. The first time is to use the first title from the text file. It is also used on every other appropriate field to escape the string so that it does not break the query. This example does not take the titles out of the line, but this could be easily done with cut.

Its easy to import text files into MySQL with shell scripting but the language I feel is best suited for this task is PHP. Some time I’ll go over how to do this with PHP.

Using BASH to sort a book collection. ISBN Data Mining – Part 1

Filed under: General Linux,Shell Script Sundays — TheLinuxBlog.com at 2:47 am on Sunday, September 16, 2007

Many problems can be solved with a little bit of shell scripting.
This week I plan to show you a script that does a little data mining from Barnes and Noble.
I have a lot of books and wanted cataloged information on them. Each book has a unique identifier called an ISBN. So I collected all of my ISBN numbers and a simple loop that wrapped around a script a friend of mine made to find basic information.
Here is his script:

#!/bin/bash
ISBN="$1"
 
function fetchInfo () {
### Using barnesandnoble.com to fetch info...
lynx -source "http://search.barnesandnoble.com/booksearch/isbninquiry.asp?ISBN=${ISBN}" |\
tr -d '[:cntrl:]' | sed 's/>\n
 
### Parsing book title.
if [ "${lineArray[0]}" == "
echo "4|Title: ${lineArray[*]}" | sed 's/<[^>]*>//g;s/ ([^)]*)//g'### Parsing book author.
elif [ "$(echo ${lineArray[*]} | grep "id=\"contributor\"")" ]; then
echo "3|Author(s): ${lineArray[*]}" | sed 's/by //;s/>[^>]*>//g'
 
### Parsing additional data.
elif [ "${lineArray[0]}" == "
[ "$(echo ${lineArray[*]} | grep -ve "bullet" -ve "title")" ]; then
echo "1|${lineArray[*]}" | sed 's/<[^>]*>//g;s/:/: /;s/  / /'
fidone | sort -ur | awk -F\| '{print $2}' | grep ":"
 
}
 
if [ "${#ISBN}" -ge "10" ]; then
fetchInfo
fi

The script should be called as followed (assuming the script name is eBook.sh):

sh eBook.sh ISBNNUMBER

The first step is to see if the ISBN is greater than 10 characters, if it is it goes to the fetchInfo() function.
It then takes the given ISBN number and searches the barnsandnoble.com site for any matches. To do this lynx is used, the -source option tells lynx to output the source instead of using browsing mode. The output of lynx is piped to tr and sed. tr is used to delete all line breaks from the source, the sed expression adds a line break at the end of each HTML tag. The while loop loops over each line from from the piped lynx, tr and sed.
Within the loop is where anything from the output of the search page can be pulled out. This script pulls out the book title, the author and additional data.

I formatted my ISBN’s in a text list and used the following loop to fetch information on my books and save them with the ISBN as the file name.

for i in $(cat list.txt); do sh eBook.sh $i > $i.txt; done;

In the next issue I plan to expand on this to format data in an even more presentable manor.
Used applications
tr, lynx, sed, awk, sort, grep

Linux Journal Issue 162 October 2007

Filed under: General Linux — TheLinuxBlog.com at 11:50 pm on Tuesday, September 11, 2007

I just got my Linux Journal October 2007 edition yesterday. I have glanced over it but haven’t had a chance to read any of the articles yet.Two things off of the bat caught my eye. If you’ve seen the cover you are probably thinking that the first thing that I am interested in is the Trolltech Greenphone. While it was the first thing I saw, it is not the first thing that I want to read. The first article that I want to read is the FS-Cache and FUSE for Media Playback QoS. This seems like something that I could use. I use SSHFS all the time but would love to be able to cache files so that I do not have to use mplayer to cache media files.

I’ll give it a read over and see if I can successfully deploy it and let you know how it turns out.

Bringing The Internet Up After Failure

Filed under: Shell Script Sundays — TheLinuxBlog.com at 9:58 pm on Sunday, September 9, 2007

This Shell Script Sunday is a short one but don’t let that fool you to the power of the shell. This script I wrote earlier in the week due to power spikes at the office. All of our equipment would stay powered on due to UPS’s but unfortunately something with the ISP was not staying on. Once the brownout occurred our router box would still have an IP and seem to be working but it wouldn’t. We had our suspicions about what piece of equipment it was but had no power to fix it. I would renew the IP from the ISP bring the public interface down by using eth0 down and then eth0 up but this was not successful. To fix it from the router I had to actually reset the network. This worked, but we have some services running at the office that I like to access from home. So to fix the problem I wrote a one liner to reset the network if the connection goes down.

ping -c 1 OurISP.com 2> /dev/null > /dev/null && echo > /dev/null || sudo /etc/rc.d/network restart

The techniques in this script are covered in Shell Scripting 101. All this does is ping OurISP.com one time and output the error & standard output to /dev/null. If the ping was successful it does nothing and if the ping failed then it restarts the network. To get it to repeat at an interval I just set it up as a cron job. This did the trick and I now do not have to worry about brownouts.

Slackware 12 MPlayer Installer

Filed under: The Linux Blog News — TheLinuxBlog.com at 12:05 am on Friday, September 7, 2007

My Slackware 12 MPlayer Installer post had the wrong link in it for the installer. The correct link for the installer is http://www.thelinuxblog.com/uploads/mplayer_setup.sh I have modified the post to the correct link. I give my apologies and will try to make sure that I don’t post a bad link again.

Thanks for reading,

Owen.

Slackware 12 – MPlayer Setup in 3 Easy Steps

Filed under: General Linux — TheLinuxBlog.com at 9:46 am on Thursday, September 6, 2007

I made a quick installer script that will install MPlayer 1.0rc1 with the essential codecs pack and the Firefox plugin on a new installation of Slackware 12. With this script you should be able to get MPlayer set up on Slackware 12 in 3 easy steps.

1. Download The MPlayer Installer that I made (Right click Save Link As).
2. Change to root user and run the MPlayer Installer OR run the MPlayer Installer with sudo as followed:

bash-3.1$ su root
Password:
bash-3.1# sh mplayer_setup.sh

OR

sudo sh mplayer_setup.sh

3. If everything installed smoothly you can remove the mplayer directory and all files inside it. If it failed then all you need to do is (as root) removepkg on all of the .tgz files and do a rm /usr/lib/codecs/*.

Firefox should be restarted after the script has run. Test Firefox by going to various media sites, one I like to use is Apple Trailers (Because of the quality and speed). If you could contact me and let me know if the installer worked or failed I would appreciate it.

Line by line breakdown of the installer:

mkdir mplayer; cd mplayer;

Creates the mplayer directory and moves into it.

wget http://www2.linuxpackages.net/packages/Slackware-12.0/X11/MPlayer/mplayer-1.0rc1-i486-1goa.tgz; installpkg mplayer-1.0rc1-i486-1goa.tgz

Gets the mplayer-1.0rc1-i486 package from linuxpackages.net then installs the package

wget http://www2.linuxpackages.net/packages/Slackware-12.0/Library/mplayerplug-in/mplayerplug-in-3.45-i686-1amg.tgz; installpkg mplayerplug-in-3.45-i686-1amg.tgz

Gets the mplayer plug-in for Firefox and installs it

wget http://www4.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2

Downloads the essential codecs pack from mplayerhq.hu

tar xvjf essential-20061022.tar.bz2; mv essential-20061022/* /usr/lib/codecs; rm -rf essential-20061022

extracts the essential codecs package to one of the directories MPlayer looks for codecs in and removes the directory.

Slackware 12 HAL fix

Filed under: General Linux — TheLinuxBlog.com at 9:15 am on Wednesday, September 5, 2007

HAL is short for Hardware Abstraction Layer. Its job is to make hardware work with minimal user interaction.
Unfortunately HAL on Slackware 12 does not work right out of the box.
While playing around trying to get HAL to work I was getting weired error messages such as:

File "/usr/bin/hal-device-manager", line 7, in
import pygtk
ImportError: No module named pygtk

and

A security policy in place prevent this sender from sending this message to this recipient, see message bus configuration file (rejected message had interface "org.freedesktop.Hal.Device.Volume" member "Mount error name "(unset" destination "org.freedesktop.Hal")

After doing some research I found that all that is needed to fix this to add your user name to the plugdev group in /etc/group
plugdev:x:83:youruser
If you have multiple users that need access to HAL then add all of those user names to the /etc/group file while your at it. Seperate them with commas as followed:
plugdev:x:83:userone,usertwo
For more information on the HAL project check out the HAL project page.

Next Page »