Faoileag's Nest

Faoileag's Little Howto

This is a loose collection of tips and tricks; basically it's just a collection of notes on how to do things. A quick reference if you like.


How to run a x application on a remote machine

If you want to start a x application on a remote machine (for instance via telnet), but have the output send to your screen (i.e. your local X-server), you've got to do two things:
  • Let the remote machine know which X-server to use when a X-application ist started. You do this by exporting the DISPLAY variable as in this example: export DISPLAY=<local ip>:0 where <local ip> stands for the ip of your local machine (or it's hostname).
  • Let your local X-server know that it's ok to accept requests from the remote machine. You do this with the xhost command as in: xhost +<remote ip>. Your .xinitrc file is the perfect place for this command (if you want your X-server to accept requests from more than one remote machine just use more than one xhost command).

[toc]


How to access a remote machine via rsh

In this case there must exist a .rhosts file in the user directory of the remote machine you want to access. The .rhosts file consists of lines like <local ip> <local user> with exactly one ip/username-combination per line (you may use hostnames instead of ip's).
Attention: if you get the user-rights of the .rhosts file wrong, it will be ignored!!! Set them to -rw------- (600) to be on the safe side.

[toc]


How to update drivers for your graphics card

Get them, then copy them into the directory /usr/X11R6/lib/modules/drivers/ (at least on a suse 7.0 system).

[toc]


How to unzip .zip files (or create them)

Get zip and unzip from www.info-zip.org/pub/infozi p/, either as a precompiled binary or as source.

[toc]


How to start a cron job

The cron daemon consults so-called crontabs for jobs to execute (and when to execute them). These crontabs are ordinary textfiles, however you should always use the appropriate tool (crontab) to manipulate them.
To have a look at your crontab execute crontab -l. If a crontab exists then it's contents is listed, otherwise "no crontab for <username>" will be displayed.
To add or delete an entry in your crontab, use crontab -e. Which editor is used can be customized, but usually it's vi.
You add or delete entries by adding or deleting the appropriate line in the crontab (every entry takes exactly one line).
Each line consists of six columns which are seperated by blanks. The sixth (rightmost) column tells cron which command/file to execute (always use the full path here), while the other five columns tell cron when to execute it.
The columns (1 stands for the leftmost column, counting to the right) have the following meaning and take the values in brackets:
  1. Minute (0 - 59)
  2. Hour (0 - 23)
  3. Day of month (1 - 31)
  4. Month (1 - 12)
  5. Day of the week (0 - 6, 0 representing sunday, 6 saturday)
In each of these five columns an asterisk ("*") stands for "every". Example: "15 4 * * * /home/joe/backup.sh" would mean that everyday at 4:15 in the morning the script backup.sh in joe's home directory would be executed (assuming, of course, that the script is executable).
If you want to specify a group of times, then concatenate the individual values, seperated by commas (Example: "00,15,30,45" - in the first column this would read as "every quarter of an hour on the quarter of the hour").
If you want to specify a range of times, you can use the minus (Example: "1-5" in the fifth column would read as "every workday").

[toc]


How to force package installation with rpm

Use the option --nodeps with rpm.
Example: rpm --install --nodeps mypackage.rpm

[toc]


How to check the syntax of httpd.conf

Call (as root) httpd with the option -t or -T (-t includes checking the DocumentRoot).
Example: httpd -t
If the httpd.conf is faulty, the linenumber as well as the offending directive are printed.

[toc]


How to create a bash prompt with colours

The sequence \[\033[attr;back;fore\] sets the text following it to the attributes and colours defined by attr, back and fore. Here's what values they can assume:

attr: fore: back:
ValueMeaning
00normal
01bold
02(undefined)
03(undefined)
04underlined
05darker, bold
06(undefined)
07inverse
08invisible
ValueMeaning
30black
31red
32green
33brown
34blue
35purple
36cyan
37white
ValueMeaning
40black
41red
42green
43brown
44blue
45purple
46cyan
47white
These are the default colors; if you don't like them (or if they don't look good in your terminal window) take a look at "How to customize your terminal colors".

back and fore are interchangeable, but I would always start the sequence with the value for attr, because an attribute value of zero cancels any previously declared fore- or background colour.
Example: If you define your bash-prompt like this:

PART1="\[\033[1;41;32m\]\u\[\033[1;44;36m\]" PART2="@\h:\[\033[0;47;30m\]\w\[\033[0m\] $ " PS1=$PART1+$PART2

you'll get something like this:
foobar @pluto: ~/bin  $ ls       
Where foobar is the username and pluto the current host. ~/bin would be the directory the user is currently in, this being a subdirectoy named "bin" of the users home directory. Finally ls would be a command he just typed and the terminal window would be configured as having a black background and white text.
Attention: if you work with colour in your bashprompt, don't forget a \[\033[0m\] after the coloured section; otherwise the last colour-definition will "spill-over" into your command-line.

[toc]


How to allow root to export his display to a user-started x-server

First, add a line like export DISPLAY=localhost:0 to root's .bash_profile (or whatever file is executed after starting a new shell on your machine).
Next, you will have to tell the x-server that localhost is allowed to connect to it. You do this by adding xhost +localhost in your .xinitrc file.
If the x-server is currently up and running, you'll have to restart it. And from now on, you can start x-applications when you're root but the x-server was started by you not being root but your usual user.

[toc]


How to make kppp work for normal users

If you want to make the dialer kppp available for normal users in SuSE Linux 7.2 running as their process, you'll have to do the following:
  • The user must be in the groups uucp and dialout (in addition to the standard users).
  • The directories /var, /var/spool and /var/lock must be writable (and executable) for the user.

[toc]


How to change the login message

The text in the file /etc/issue is displayed before the login-prompt. System information can be accessed via escape-sequences, e.g. \n stands for the system name.
The text in the file /etc/motd is displayed directly after the user logged in succesfully.
If you want to display generated messages that change daily (say, a message from fortune) you will have to write a small script that writes the generated message into the appropriate file and place it in your /etc/init.d directory. Then hook it up in the appropriate runlevel (for instance by creating a link in /etc/rc2.d) and you are greeted with a different message after restart.
Here is an example script to display fortune's sagacities:
#!/bin/bash
case "$1" in
  start)
    echo "Setting motd (fortune)"
    fortune >/etc/motd 2>&1
  ;;
  *)
    echo "Usage: $0 {start}"
    exit 1
  ;;
esac
exit $?

[toc]


How to tell the X server to reload .Xdefaults

xrdb -load ~/.Xdefaults

[toc]


How to tell ls to use a local color table

Insert eval `dircolors .dir_colors -b` somewhere in your .bash_profile (.dir_colors being your customized xopy of /etc/DIR_COLORS).
You specify colors in the .dir_colors file not by specifying the color itself but by specifying which color out of the current color table should be used. Take a look at "How to customize my terminal colors".

[toc]


How to customize my terminal colors

If you don't like the standard colors used, for instance, by the ls command, you can change them by redefining the color palette to which all entries in /etc/DIR_COLORS refer to (see "How to tell ls to use a local color table" on how to tell ls to use user-specific colors).
To do this, you will have to add the following lines to your .Xdefaults file (assuming you use xterm for your terminal windows):

XTerm*color0: <some color>
...
XTerm*color7: <some other color>

for normal text and the lines:

XTerm*color8: <some color>
...
XTerm*color15: <some other color>

for bold text.
For a list of the default colors see the man pages for xterm; for names of supported colors see the file /usr/X11R6/lib/X11/rgb.txt.
Or take a look at http://yath.mine.nu/x11byco lor.html, where you can see how the colors come out on your system as well.
By the way, if you don't want to use names for the colors, you can also specify the color as hex-code, like: XTerm*color8: #000080, which would be the color navy (blue).

[toc]


How to query a pop3 server by telnet

Open a telnet connection to the pop3 server you want to query. Don't forget the port number (most pop3 servers use port 110). Example: telnet pop3.faoileag.de 110
The result should be something like +OK POP3 server ready. You now have to send the user data, i.e. the name part of your email-address and your email password. The user name is passed with the USER command and the password with PASS. Example (let's assume the email address is mike25@faoileag.de and the password is "iammike"):
USER mike25
+OK
PASS iammike
+OK
Now you can query the pop3 server using the following commands (the commands are not case-sensitive, i.e. you can write USER as well as user:
  • STAT: gives you the number of messages in the mailbox and the total number of bytes of all messages in the form +OK #msgs #bytes. Example:
    STAT
    +OK 5 1200715
  • LIST: gives you a list with the size of each message in bytes. The end of the list is marked with a line showing just a single dot. Example:
    LIST
    +OK 2 messages
    1 50153
    2 9560
    .
  • RETR msg: retrieves the email whose number you specify, i.e. the email is displayed in your telnet window. The end of the email is marked again by a line with a single dot. Example:
    RETR 1
    Return-path: <john23@faoileag.de>
    Envelope-to: mike25@faoileag.de
    Delivery-date: Sun, 17 Nov 2002 17:33:43 +0100
    and so on...
    .
  • TOP msg numoflines: retrieves the header of the email specified by msg and the first numoflines lines (not all pop3 servers support this). The end of the result is marked by a single dot in a line of its own as usaual.
  • DELE msg: marks the email specified by msg for deletion. Deletion takes place only after you have send QUIT.
  • RSET: resets all the deletion markers set so far, i.e. the emails will not be deleted after QUIT.
  • QUIT: closes the telnet connection. All emails still marked for deletion are now deleted.
If you specify an email-id that does not exist you will be told that the message does not exist: -ERR no such message. Same goes for unknown commands, then you will see -ERR unknown command.
RFC 1939 explains all this in more depth, if you are interested (it also lists some additional commands, but these here are the standard ones you need every day).

[toc]


How to query a web server by telnet

Open a telnet connection to the web server you want to query. Don't forget the port number (most web servers use port 80). Example: telnet www.faoileag.de 80
The result should look like:
Trying 212.227.109.218...
Connected to www.faoileag.de.
Escape character is '^]'.
Now you can send off your query, i.e. fetch a web page. You do this with GET. Example:
GET http://www.faoileag.de/index.html HTTP/1.0 [return]
[return]
There are several things to note here:
1) You have to hit [return] two times. The first [return] just enters the GET command. It's the second [return] that sends the request off to the web server.
2) You have to type the full url (including the protocol bit "http://" and the server name) even though you already are connected to the server and it should know what to do. With long urls, this is not exactly fun.
3) After the url and seperated by a blank, you have to type the protocol again.
As a result of the GET, the contents of the web page you requested is printed to the telnet console. After that, the connection is usually closed.
What do you need this for? Well, there are two reasons why you might want to fetch a web page via telnet:
1) You get the code of the page you requested. This can be quite helpful if there are instant redirects on the page.
2) It's quite useful when you are testing scripts. This is because between the GET and the second [return], you can insert and set the environment variables the script on the other end "sees".
Example:
GET http://www.faoileag.de/index.cgi HTTP/1.0 [return]
REFERER: http://www.faoileag.de [return]
[return]
If my script, index.cgi (don't try, there isn't one), would check the variable REFERER it would get "http://www.faoileag.de" even though the request originated on a completely different machine.
This example is called "referer spoofing"; it's sometimes used to bypass security measures in scripts.

[toc]


How to query the status of an apache server

There exist three query commands you can type in the location bar of your browser (I've used localhost here, but a domain name should work as well):
http://localhost/server-status
http://localhost/server-info
http://localhost/perl-status
However, apache must be configured to support this.

[toc]


How to deny directory listing with apache

You must set the options for that directory accordingly. You do this by using Options within a <directoy ...> block like this:

<directoy "/home/foobar/html/sampledirectory">
Options -FollowSymLinks -Includes MultiViews
<directoy>

If the options for Options include Indexes, a directory that does not contain an index.html file (or whatever you have specified as an equivalent) will be indexed, if Indexes is not included in the list you will get an error 403, "Forbidden".

[toc]


How to set up a virtual server with the same ip but on a different port

Apart from setting up the virtual server with a <VirtualHost...> block, you also have to set the Listen directive to the new port you've chosen as well as to port 80.
Attention: You will have to restart apache after this; reload won't do!

[toc]


How to suppress the header information on a telnet connection

Start the telnet server with the option -h. If you use inetd, this is done in /etc/inetd.conf

[toc]


How to set the default rights for uploaded files

Start the ftp server with the option -u xxx, where xxx stands for the desired umask.
Example: ftpd -u 002 sets the umask for uploads to -rw-rw-r--.

[toc]


How to avoid logging shell commands in the history

At the beginning of the session type unset HISTFILE[return]. That will clear the environment variable that specifies the file in which shell commands are logged. And without that variable set the shell won't save the sessions command history when it exits.

[toc]


How to really erase a file and clean the disk

With the normal rm command, you only delete the i-node of the file in question; the file's data is still on your harddisk and could potentially be read by analyzing the disk.
There are two ways to ensure complete deletion:
  • The safest way to really erase the data is to use srm instead of rm. If srm did not come with your distribution you can get the "secure delete" suite from http://freshmeat.net/projects/securedelete/?topic_id=43 (there are some other usefool tools included in the suite as well).
  • If you can't get srm use wipe <filename>.
But what about the data of all those files you deleted insecurely? Again, there are two ways to wipe the entire free space on your harddisk:
  • The safest way again is using sfill from the "secure delete" suite (see above). This really sanitizes your disk although it is very slow and may take several hours depending on your system.
    Nevertheless, it's still what I would do before I ever sold an obsolete harddisk or computer.
  • Alternatively you can use dd if=/dev/urandom of=/dev/hda or dd if=/dev/random of=/dev/hda (use the mouse to generate randomness if you use /dev/random instead of /dev/urandom).

[toc]


How to customize syntax highlighting in emacs

Type: M-x customize-face[Return] (M-x translates into [Alt][x] on my system).
Answer the question wether you want to customize all faces with yes.
The syntax highlighting rules for c++ code are those named "Font Lock <element> Face:".
If you can't set boldness here, just set it to off, then change the entry in your .emacs file manually from nil to on (the lines looks like (font-lock-type-face (... :bold nil))).

[toc]


How to supress loading Netcenter in Netscape Mail

Add the line user_pref("mailnews.start_page.enabled", false); to the file prefs.js.

[toc]


How to install the RealPlayer plugin for Netscape 4.7x

After installing the RealPlayer, look for the file rpnp.so and copy it into Netscape's plugins directory.

[toc]