Archive for February 2008

TAR & zipping

Most of the program files you need to install on your machine will be downloaded in a compressed format that takes less time to transfer. Once on your machine, you will need to uncompress the file before you can install it. First, determine the type of file you have from the file suffix. If it ends in .tar it is probably an unzipped tar file. If it ends in .Z, .gz, .bz2 or.tgz it is probably a zipped tar file (zipping is a form of further compression). In order untar a tar file type:
tar -xvf file.tar
if it is a zipped tar file add a z to the options:
tar -zxvf file.tar.Z (except for bz2 which uses -j instead of -z)
If you want to look at the contents of a tar file before you untar it use:
tar -t filename.tar
If you then decide there is only a small part of the total tar file you actually need to extract, type:
tar -zxvf tarfile filepathIf you have a large number of files you wish to transfer you can make it simpler by tarring them first:
tar -cvf file.tar directory_to_tar
(Make sure you don’t reverse the order of “file.tar” and “directory_to_tar”). Then to zip it type:
gzip -cv file.tar
Or better yet, do it all at once with:
tar -zcvf
On our SGIs, this must be done with the command:
tar -tvf file.tar directoryname instead.

Here’s a neat trick for transferring a tar file to another machine that will tar “on the fly” rather then requiring you to create a tar file on your own machine first. (Which can be useful if you don’t have much space left.) To do this simultaneous tar, zip, and transfer type:
tar --rsh-command=`which shh` -zcvf -- --host_computer:filename.tar -- --directory_to_tar
Note that “which ssh” needs back-ticks rather than apostrophies.

After you uncompress a program tar file you will usually still have to install the program yourself. The usual directory to install programs in is /usr/local/. (You will need root permissions.) Look for a README file in the file’s source code to get further instructions.
An easier method of installing programs though is to get a rpm package rather then a tar file for a program whenever possible. Rpm packages do all the work of untarring and installing for you. A good source for these files can be found at: http://linux.s390.org/download/rpm2html/index.html or ftp://ftp.software.umn.edu/pub/linux/redhat/redhat-9-en/os/i386/RedHat/RPMS
(Note that this particular link is for people using Redhat 9 but if you go up a few directories you can get to the directory specific to the LINUX version your using).

tar zcf localfolder.tgz localfolder/
tar zcf - localfolder/ \ | ssh 192.1.1.1 "cd folder/to/copy/to; tar zpxvf -"

gzip -dc file.tar.gz | tar xf - pathname/filename
The pathname and filename should be exactly as given in the .tar.gz file. If you want more than one file append their names, again include pathname, at the end of the command.

File editing with SED

In addition to editors like emacs, you can also edit files directly from the terminal using sed, the built-in stream editor. You can use it to make substitutions or deletions in a file with commands such as:
sed 's/oldword/newword/g' filename
which substitutes “newword” for “oldword”. The “g” makes the substitution global (all instances on that line). Without the g, it will only change the first match on that line.
Other sed commands:
sed 's/word/d' filename
This deletes the whole line, not just the word. To delete just the word:
sed 's/word//' filename
The examples given will print out the changes to the terminal. If you want to print the changes to a file instead type:
sed 's/oldword/newword/' filename > newfilename where > directs the output into a file called newfilename
To link more than one command together use &&. For example:
sed 's/oldword/newword/' filename > newfilename && emacs newfilename

sed ‘s/string1/string2/g’ Replace string1 with string2
sed ‘s/\(.*\)1/\12/g’ Modify anystring1 to anystring2
sed ‘/ *#/d; /^ *$/d’ Remove comments and blank lines
sed ‘:a; /\\$/N; s/\\\n//; ta’ Concatenate lines with trailing \
sed ‘s/[ \t]*$//’ Remove trailing spaces from lines
sed ‘s/\([\\`\\"$\\\\]\)/\\\1/g’ Escape shell metacharacters active within double quotes
seq 10 | sed “s/^/      /; s/ *\(.\{7,\}\)/\1/” Right align numbers
sed -n ’1000p;1000q Print 1000th line
sed -n ’10,20p;20q Print lines 10 to 20
sed -n ‘s/.*<title>\(.*\)<\/title>.*/\1/ip;T;q Extract title from HTML web page
sort -t. -k1,1n -k2,2n -k3,3n -k4,4n Sort IPV4 ip addresses
echo ‘Test’ | tr ‘[:lower:]‘ ‘[:upper:]‘ Case conversion
tr -dc ‘[:print:]‘ < /dev/urandom Filter non printable characters
history | wc -l Count lines

Managing the Blue Net MySQL database

The document describes how you can manage your Blue Net MySQL database.

Note:
Database structure and design are outside the scope of this document and are not covered.

To manage your database you require the following information:

Database server:
mysql01.blue.net.au

Database user name and password are allocated upon signup with Blue Net hosting

You can then either use the built-in manager at:

http://support.blue.net.au/phpmyadmin

For instructions on how to use PHPmyAdmin please refer to: http://www.phpmyadmin.net/home_page/docs.php
Alternatively we recommend the excellent, free OpenSource HeidiSQL:

http://www.heidisql.com

Please refer to their extensive user forum for support and instructions for this product.

centos 5 tweaks

There are a couple of things missing from the otherwise very stable CentOS5:

denyhosts
A python script checking on failed attempts to log into SSH and blocking IP addresses in /etc/hosts.deny when detected.

psad – www.cipherdyne.com/psad/
port scan admin, which detects port scanning activity and blocks IPs with iptables when detected

Additional updating and facilties (like the ones above) are easier installed with YUM when the following repo (Centos, Linux Enterprise & RedHat 7.3 & 9) is added:

http://dag.wieers.com/rpm/FAQ.php#B