Erik's page about Linux/Programming/A few other things.. <author>Erik Forsberg <date>v1.13.5 Mar 28, 1999 <abstract> Hi and welcome to my page about Linux - most of it from the beginners point of view, but with some more or less advanced tips too. I try to update this page often,, but since I'm quite a busy person, sometimes it may take a month or two. Please <url url="http://www.lysator.liu.se/~forsberg/cgi/guestbook.cgi/" name="sign"> my <htmlurl url="http://www.lysator.liu.se/~forsberg/guestbook.html" name="Guestbook"> and tell me what you think about this page if you're visiting the HTML version. Or, send me a mail, <url url="mailto:forsberg@lysator.liu.se" name="by clicking here"> Please check out the <htmlurl url="http://sunsite.unc.edu/LDP" name="The Linux documentation project"> too find even more valuable information. Also check out <htmlurl url="http://www.allexperts.com/software/unix.shtml" name="Allexperts.com - The Unix section">. A website with volunteer experts answering your questions. </abstract> <toc> <sect>About Erik Forsberg, and this document <p> Well.. This page isn't supposed to be one of these "Hello, I'm Jim, and this is my very fat cat Sara" pages.. but if you're interested, look at <url url="erik.html" name="this page about him"> <p> You think this page is boring ? Almost no pictures, flashing text, background images, colours etc ?? Well.. this is what the web was in the old good days, when the internet was an information network, not a garbage can.. It's still possible to find small oases of valuable information, but it's getting harder.. <p> The information you find here, is in no order, with no structure, and directly out of my very weird brain :-) Watch out, or you'll be like me.. Right now, it's quite incomplete, but I'll try to write a section now and then. If you want to contribute with a text about something, feel free to mail me at the address you'll find if you read a few more lines.. If you're a new Linux user, I recommend the "Linux Installation and Getting Started Guide 2.3", a part of the Linux Documentation Project, check <htmlurl url="http://sunsite.unc.edu/LDP/" name="this url"> for more information. A lot of the information on my pages are there too, most of it probably better written and formatted ;) <sect1>Authors address <p> Please give me feedback, any kind of it is welcome. Mislinks, errors, things you think should be here, misspells, whatever, just mail them ! If you want to, you can write your own section, if I think it should be here, I'll add it, with your name on it. Text or SGML format please. The e-mail address of the author is <htmlurl url="mailto:forsberg@lysator.liu.se" name="forsberg@lysator.liu.se"> <sect1>Disclaimer <p> Standard Disclaimer follows: I don't take any responsibility for anything happening to you, your computer, your house, your neighbours, anybody/anything else, after reading this document or any other page written by me or anybody else. I don't put anything I know don't work here, but I don't guarantee it does. <p> All trademarks mentioned in this document are owned by their respective owners. Linux is a registered trademark of Linus Torvalds. <sect1>Getting this document <p> There are various versions of this document: <itemize> <item><url url="ftp://ftp.lysator.liu.se:/pub/texts/forsberg/indexsrc.gz" name="The sgml source (gzip compressed)"> <item><url url="ftp://ftp.lysator.liu.se:/pub/texts/forsberg/indexps.gz" name="compressed postscript"> <item><url url="ftp://ftp.lysator.liu.se:/pub/texts/forsberg/indexrtf.zip" name="zip compressed RTF (yes, you can read it with your lousy word !!)"> <item><url url="ftp://ftp.lysator.liu.se:/pub/texts/forsberg/indextxt.zip" name="zip compressed text file for viewing in DOS."> <item><url url="ftp://ftp.lysator.liu.se:/pub/texts/forsberg/lesstxt.gz" name="gzip compressed text file for viewing with less or more"> </itemize> <sect1>My system <p> It might perhaps be interesting to know on what kind of computer I'm doing my weird Linux experiments, facts follow The old one.. <table> <tabular ca="ll"> CPU | NexGen 586 75 MHz (an Intel compatible CPU) @ Memory | 32 Mbytes @ Hard disk | 4.8 Gbytes, Maxtor 540 Mb + Quantum 4.3 Gb @ Modem | US Robotics Sportster 28k8 @ Graphics Card | Very slow CL5429 @ Screen | 15" AOC Spectrum @ Network card | One 3c509 for my link to the rest of the world, and one for my internal net.@ EIDE card | EIDE 2300+, recommended ! @ CD-ROM player | Vertoz 4X, very weird player @ Backup | Seagate TapeStor 8000, ATAPI drive, 4 Gb uncompressed @ Printer | Fujutsi DL 1100 (24 pin matrix, with color option) @ </tabular> <caption> Glurp, the old computer </caption> </table> <table> <tabular ca="ll"> CPU | Intel Pentium II 350 Mhz @ Motherboard | ASUS P2B-DS Dual PII (But I only use one CPU to start with) @ Memory | 128 Mb @ Hard disk | 4.5 Gb IBM U2 SCSI @ DVD | Pioneer 6 X DVD, 32 X CD @ Graphics Card | Creative Graphics Blaster RIVA TNT @ Screen | Nokia MultiGraph 446Xpro 19" - I love it ! @ Network card | 3COM 3C900 Combo, 3c509 @ Sound card | Creative SoundBlaster PCI128 @ </tabular> <caption> Hostname, the new computer.. </caption> </table> <p> I run Debian GNU/Linux 2.1 on both machines. <p> I also have an old IBM PS/2 Model 30 (intel 80286 POWERED ! :) ), a HP X terminal I don't use, and some other junk.. <sect1>Changes in this document <p> The version number of this document is in the form A.B.C, where a change in A stands for a major rewrite or adding a new sect. Increasing of B indicates a new sect1 and increasing of C a new sect2 or small change, bug fix. Perhaps I'll even follow that system !! :) <table> <tabular ca="l|l|l"> <bf>Version</bf> | <bf>Date</bf> | <bf>What happened ?</bf> @ 1.0 | Dec 1997 | First upload of this page @ 1.3 | 1998-02-14 | I start tracking changes :) @ 1.4.0 | 1998-02-15 | Started writing the script tutorial @ 1.5.0 | 1998-02-20 | Added alias tip. Added guest book. Continued the script tutorial.@ 1.5.1 | 1998-02-21 | Did some error correction. @ 1.6.0 | 1998-02-21 | Added section on gpm. Added section on VT's. @ 1.7.0 | 1998-03-17 | Added section on file rights. @ 1.8.0 | 1998-04-06 | Added daemon section. @ 1.9.0 | 1998-04-10 | Added small tip about Emacs. @ 1.9.1 | 1998-04-11 | Added some URL's in link section. @ 1.10.0 | 1998-05-20 | Added section about root directories. @ 1.11.0 | 1998-05-29 | Where to get Linux. Some other small additions. @ 1.12.0 | 1998-05-31 | Section about PPP. A few new links, minor corrections. @ 1.12.1 | 1998-06-07 | Various minor modifications. @ 1.13.0 | 1998-09-05 | Added some commands, and some fixes. @ 1.13.1 | 1998-09-13 | Possible to download on and off files. @ 1.13.2 | 1998-11-13 | New ftp server. New guestbook. Some links, and some corrections@ 1.13.3 | 1999-02-03 | New main URL, some links. Not enough time. @ 1.13.4 | 1999-02-12 | More info about ssh. Live date update in shell script section :-) @ 1.13.5 | 1999-03-28 | Updated the todo list :-) @ </tabular> <caption> List of changes in this document. </caption> </table> <sect1>TODO <p> Some plans for this document, if you have ideas, please mail me.. <p> Description of some useful tools. Descriptions of some of my hacks. Some words about the major distributions. More about printers. More links ? Some words about compiling kernels. Package systems (rpm, deb). How modules work. <sect>Some general talk about Linux, mostly for new users. <p> The operating system I run is Linux, a free 32 bit truly multitasking multiuser OS. It's fast, it's powerful, it has a TUI, it has a GUI, I can say positive things about it all day :-) <p> Here I'll try to assemble some information that should be good to know for the new user. It's all availiable in other documentation, but if you don't know where to look, it's hard to find something useful. There will also be some tips and tricks for a more experienced user. <sect1>Some talk about Linux.. <p> What to say more about Linux ?? Linux isn't easy for the beginner, you have to dig deep into the documentation to understand it, and use it. After you've learnt, you get a lot more out of your computer, than you get with a commercial and not truly 32 bit "multitasking" OS (no names, I won't say those words on this page) <p> Linux isn't easy to install and setup, but it isn't impossible, if you have some talent for computers, and can read English texts. It's getting easier, with a growing community of Linux users ready to help you with your problems. That's one of Linux's real advantages over other OS's.. if you ask a question in one of the numerous discussion groups on computer networks as Internet and fidonet, you get answers. Good answers, from people who know what they talk about. <p> Isn't there <bf>anything</bf> negative to say ? Of course there is.. I've already said it's a hard beginners operating system, but, perhaps that's an advantage. Personally, I don't think it's possible to combine user friendliness, and powerfulness in a computer. If you want the raw power, you still have to understand a few advanced commands. There is a very good GUI, The X window system, but it's a bit hard to setup.. <sect1>Is there any software for Linux ? <p> This is another general misunderstanding; people think since Linux is free, there can't be any good software running on the OS. <bf>Completely wrong !</bf> Quite the opposite, there is a large number of software packages, available for free, with the capabilities of commercial software packages for other operating systems. Most software is distributed as source code, so a small knowledge about programming, especially 'C', is good when you're running Linux. Nowadays, with modern distributions such as Debian and Redhat, there are packages, containing pre compiled software, with installation scripts placing the files at the right place, often asking you questions about how the software should be setup. Lately, a lot of commercial packages has been ported to Linux. Including software like Oracle's databases, SAP R/3, Staroffice and Informix databases just to mention a few. <sect2>Sure it's nice with free software, but where do I get any support ? <p> Ask someone in a newsgroup, a fido discussion, an e-mail list or just e-mail the author.. somewhere there is someone who have or had the same problem you have. He or she will most probably help you, for free ! <sect2>Aren't there any commercial software ? <p> Sure there is, and it's coming more and more... Check out <htmlurl url="http://www.linux.org/apps/applications.html" name="http://www.linux.org/apps/applications.html"> for some good examples.. <sect1>Some words about partitions, Linux way of accessing (E)IDE disks, Linux way of using partitions and some other talk.. <p> When newbies ask me about installing Linux, there's a lot of confusion about partitioning your HD, and how Linux access your HD and so on.. I'll try to explain some of it.. <sect2>What's all this about partitions, boot sectors etc ? <p> If you're going to understand the text below, you should know what a primary and extended/logical partition is. You should also know how Linux names partitions located on different drives. <p> This applies to (E)IDE drives, the controller type sitting in most PC's. I'll check out how SCSI works, could someone help me with the information. <sect3>Linux way of accessing hardware. <p> In Linux, and most UNIX operating systems, you access almost all the hardware by reading/writing virtual files, mostly located in the /dev directory. This might seem a strange method, but when you get used to it, it is really natural. <sect3>(E)IDE controllers, and partitions on hard disks <p> Every IDE controller can have 2 disks, one master and one slave. In new home computers of today, there's often a (E)IDE controller, which provides the possibility of attaching 4 drives. Every drive can have four primary partitions, and a larger number of logical partitions. A partition is a piece of the hard disk, with a size you decide. <sect4>The difference between Primary and Logical partitions <p> With DOS/windows and a few other operating systems, you can only see one primary partition at one specific moment. Running DOS or windows, they are named C:. There can be four primary partitions, a PC limit as stupid as the 640 kb DOS memory limit, there should be no foreseeable limits in the soft/hardware you use.. that's my opinion. Anyway, due to information I have, Linux can see all primary partitions at one time, and use them. <p> There can be a larger number of logical partitions. An operating system can see several logical partitions at once, making it possible to access them all at the same moment. This is why one should use logical partitions where possible. Some operating systems must have a primary partition to start from, including DOS, and windows 3.xx and 95. I don't think that's clever. <sect3>The device names of different hard disks/partitions in the Linux file system. <p> So, now when we know the difference between a master and a slave, and a primary and a logical partition, we can understand the system which Linux uses to name the different drives/partitions in it's file system. the base name for a (E)IDE controlled disk is /dev/hd<it>?</it>. The <it>?</it> is a single letter. The system goes like this: <itemize> <item>/dev/hda - master disk on first controller <item>/dev/hdb - slave disk on first controller <item>/dev/hdc - master disk on second controller <item>/dev/hdd - slave disk on second controller </itemize> You get it ?? GOOD ! Now, naming the partitions is quite easy, you just attach a number to the device. Look below for some partitions on /dev/hda <itemize> <item>/dev/hda1 - master disk on first controller, first primary partition. <item>/dev/hda2 - master disk on first controller, second primary partition. <item>/dev/hda5 - master disk on first controller, first logical partition. <item>/dev/hda6 - master disk on first controller, second logical partition. </itemize> You get that too ?? VERY GOOD ! Not ?? Read it once more :-) <sect2>OK, now I understand what a partition is.. how do I use it ? How do I access C: ? (Or, the mount thing) <p> Linux doesn't present the user with stupid drive letters, it has a much more intelligent way of doing that. <sect3>A mounted file system.. <p> The advantages of a mounted file system is many.. You decide where you want the space, you can mount different file systems without problems.. <sect3>How does it work ? <p> Well.. first you need a root file system, the base of all directories, named '/'. The directory separator in Linux/UNIX is '/', not '\' as in DOS.. during system startup you tell the kernel you want as an example /dev/hda5 as root file system. After that, you can tell the kernel, you want /dev/hda1 as /dosc and you access that drive exactly like any other directory. This way, you can mount just a few directories from a local hard disk, and keep shared volumes with large amounts of data at a central server. There's a protocol for sharing files over a network, the Network File System, and you won't notice the difference accessing that directory, from accessing a directory at your hard disk. <p> I hope you understand.. perhaps not a good explanation. <sect3>Two examples <p> To mount your floppy disk, located at /dev/fd0 and formatted with the MS DOS filesystem at /floppy you'll have to execute <tt>mount -t msdos /dev/fd0 /floppy</tt>. The <tt>-t msdos</tt> tells mount what filesystem to expect, sometimes you don't have to give this, it'll find out itself. Don't forget to <tt>umount /floppy</tt> before removing the floppy. <p> To mount your CDROM, let's say it's a ATAPI CDROM located at the second EIDE controller as master, you'll execute the following command. <tt>mount -t iso9660 /dev/hdc /cdrom</tt>. Make sure /cdrom exists, otherwise it won't work. <sect1>Some other commands for the beginner <p> On request from people visiting this page, I'll list some commands the new user might want to know. Most of this is also availiable in the DOS to Linux HOWTO, check out the <url url="http://sunsite.unc.edu/LDP/" name="Linux Documentation Project"> for HOWTO's and other very interesting material. <table> <tabular ca="l|l|l"> <bf>DOS Command</bf> | <bf>Linux Command</bf> | <bf>Comment</bf> @ dir | ls | List files in the current directory @ dir | ls -l | List files, now with user right details and dates and other perhaps interesting stuff. @ Not present in DOS | ps | Lists processes you've started. Give it the argument <bf>aux</bf> for all the processes on the system. @ type | cat | List a file @ more | more or less or most or.. | List files longer than the screen length. more is standard, less is very common, most is not as common. @ help | man or whatis or apropos | Commands to learn more about the system. run man man sometime. @ fdisk | fdisk | A very funny game, don't play it too often =) @ chkdisk | fsck | Fsck is often run automatically when it's needed, at bootup. @ nc | mc | mc is a very good Norton Commander clone. @ </tabular> <caption> Some useful (?) Linux commands. </caption> </table> I can't remember any more dos commands =) <sect1>Dealing with user rights in the filesystem.<label id="about-chmod"> <p> Linux, like any advanced operating system, has a access control system for the file system. That means, not all users can do what they want with a specific file. Every file has a owner, a group owner, each with their respective right to do certain things on that file, and rights for the rest of the world. If you do a normal ls -l in some directory, you'll get something like this. <code> -rw-r--r-- 1 erik erik 444 Feb 14 22:24 Makefile -rw-r--r-- 1 erik erik 3507 Feb 14 17:44 erik.html </code> This might look cryptic the first time you see it, but after a while it's as natural as it can be. I'll try to explain the fields. <sect2>The rights for this file. <p> <tt>-rw-r--r--</tt> describes the rights the <bf>owner, group and everyone else</bf> has on this file. As you can see, there is 10 characters, the first one tells the type of the file, if it's a directory there is a 'd' instead of a '-', there is a few other types, but this is what you need to know right now. After the classifying character, there is three groups of characters, each of them with three characters in them. They describe the rights for the owner, the group and everyone, one character group for each of them. The basic rights are <bf>Read Write Execute</bf>. So, the string <tt>rwx</tt> says right to read, write and execute the file. If you have execution right on a directory, you may cd into it. Anyway, a string like the one in the example <tt>-rw-r--r--</tt> means that the owner of this file has read and write rights, the group has only read and the so has the rest of the systems users. Of course, root can do whatever with the file too, since root is God in the UNIX world (Root really can do everything, like deleting your /bin directory, ask me, I know... ). The other fields in the listing says how many links to this file there are, who is the owner, what group it is in, the file size and date and the filename. <sect3>What is a group ? <p> Perhaps I should explain that too.. As you probably know, you have a username, and most of your rights depend on that username. Sometimes it's practical to have common rights for some users, per example 5 people developing the same program should have read/write permissions to the source code, but everybody else shouldn't. The sysadmin of the system may setup a special group for those programmers, and then they can happily share their files. <sect2>Changing the rights for a file... <p> So, now when you know what the cryptic fields mean, you'd probably like to change them, wouldn't you ? The magic command is <tt>chmod</tt> with the correct parameters given. There is two ways to tell chmod what rights you want for a particular file (or a bunch of files specified with a wildcard); <sect3>...The character way or... <p> If you prefer this way, you tell chmod what you want by combining characters, basically <bf>u, g, o and a</bf> is used, they tell chmod for whom you want to change rights, u for user, g for group, o for others and a for all. You combine that character with another character specifying what right to change, <bf>r, w and x</bf> most commonly used. r for read, w for write and x for execute. As an example, if you want to add execute rights for the user owning the file named file1 you execute <tt>chmod u+x file1</tt>. Removing the groups write rights on the same file would be <tt>chmod g-w file1</tt>. Really logical, isn't it? Make a dummy file and experiment, and read the man page <tt>man chmod</tt>. <sect3>...The numerical way <p> This is the way I use, since I've grown up with it ;). You tell chmod what you want by giving it numbers, one for each of <bf>user</bf>, <bf>group</bf> and <bf>others</bf>. You calculate the numbers by looking at the read, write and execute flags as binary bits. <bf>rwx</bf> would be a <bf>7</bf> if you look at an enabled r as a 4, an enabled w as a 2 and an enabled x as a 1. <bf>rw-</bf> is 6, since 4 (enabled r) + 2 (enabled w) + 0 (disabled x) = 6. You get it ? Not ? Use the character way :) Anyway, if you combine one number for the user, one for the group and one for others, you'll get three numbers. So, for <bf>rwxr-xr-x</bf> you'd do <tt>chmod 755</tt>. There's probably about a million better ways to describe this, but.. <sect1>Booting Linux with LILO <p> When you start using Linux, you probably want your old operating system left there, to use if you get struck in some problem. You won't need another operating system because Linux can't do something. Linux can do everything, it's just a matter of configuration and time :-) Anyway, if you want your old system as a backup, a smart way of doing this, is to install Linux to another partition, and use LILO to choose the operating system you want to run at the moment, at system boot. For more detailed information than this text gives you, check the lilo man page. 'man lilo' and 'man lilo.conf' <sect2>How LILO works <p> LILO (<bf>LI</bf>nux <bf>LO</bf>ader), places itself in a boot sector of your hard disk. It could be the MASTER boot record of your hard disk, ie the first sector of the disk, making it execute as the first thing the BIOS does after checking things are OK. It could also be a partition boot record, ie the start of a partition, making it execute when another boot loader, perhaps the OS/2 Bootmanager, passes the control to it. This way, you could have a more fancy boot loader there for your mother to choose from, and then LILO will do the Linux boot. <p> LILO has a configuration file, called /etc/lilo.conf, where you tell it how to behave. I'll give you an example of such a file in the next section. After you've written your lilo.conf, run the command 'lilo' and it will write the boot sector, or give you an error message if you've done something wrong. It's really important that you have a boot, because if you do something wrong you have to edit the lilo.conf file, and try doing that when you can't start Linux ! Installing some operating systems (Win95 for example) will erase the information lilo writes to the Master Boot Record, and you'll have to boot Linux with a boot disk to be able to reexecute lilo to rewrite the information. <sect2>An example lilo.conf file, for a computer with win95 and Linux installed. <p> I'll give an example here, basically copied from the lilo man page, how to setup lilo for a computer with windows 95 on the first primary partition, and Linux on the first logical partition. All text after a '#' is comments. <code> # example /etc/lilo.conf boot = /dev/hda # place lilo in MBR of first disk delay = 40 # Wait 4 seconds for user to press Ctrl or Shift # This way your mother won't have to do anything to # boot her windows 95 other = /dev/hda1 # The windows 95 partition label = windows table = /dev/hda image = /boot/zImage-2.0.33 # A Linux kernel, located in the /boot directory root = /dev/hda2 # The partition that will be mounted as root label = linux # The name you should type in to boot this kernel. </code> After entering that into your /etc/lilo.conf, run the command <tt>lilo</tt>. If everything is what it should be, it should respond with<newline> <tt> Added windows *<newline> Added linux<newline> </tt> The star indicates that windows is the default alternative, that will boot if you do nothing. <p> When you reboot (remember having a rescue disk if something goes wrong), lilo will print 'LILO' at your screen, wait for seconds for you to do something, and then boot windows 95. If you push down shift or Control, LILO will give you a prompt, where you can enter 'linux' and push enter, then it will boot the linux kernel you've specified. I hope it'll work for you ! <sect1>Virtual Terminals - VT's <p> OK, so now you sit there with your Linux prompt, doing nice things.. try pressing Alt+F2.. Wow, a brand new login prompt ! Try pressing ALT+F3.. Another one. Press Alt+F1, back at the old one.. this way you can do several things at once, logging in as yourself at tty1 and perhaps as root on tty2, this way making your system administration effective. Usually there are 6 <bf>Virtual Terminals</bf>. This might seem obvious, but I'm writing this document with the new user in mind. <sect1>Environment variables <p> Perhaps good to know is how bash handles environment variables. This is bash specific I know, but as I've said before, bash is the most common shell. I'd like to have information how other shells does. <sect2>What is an environment variable good for ? <p> It's a fast way of accessing some short configuration options from every program. It's easy to change during a session and is easy to view.. or something, well, they exist and it works quite well.. <sect2>How do I set/unset an environment variable, and how do I view them ? <p> In bash, you use export <tt><variable>="<value>"</tt> (example: <tt>export PATH="/bin:/usr/bin"</tt>) to set a variable. To remove it completely you use <tt>unset <variable></tt> . With <tt>printenv</tt> you can see all the variables. <sect2>What more or less important variables are there ? <p> There are a lot of them, some of the most common being <table> <tabular ca="ll"> <bf>Variable</bf> | <bf>Meaning</bf> @ PS1 | Let's you decide how your prompt should behave @ PATH | Defines the PATH (surprise ! :) ) @ LOGNAME | Shows which user is logged in on the current terminal @ HOSTNAME | Contains your hostname @ PAGER | Contains the local pager, to view textfiles @ $$ | Gives the Process ID of 'this' process. @ $? | Gives the errorlevel of the last command. Useful in shell scripts @ $0 | The name of the command executing right now, also useful in shell scripts @ $1 | The first cmdline parameter to 'this' process. @ $2 | The second... @ </tabular> <caption> Some environment variables </caption> </table> <sect1>Shell scripts <p> Another thing good to know is how to write shell scripts. They are commonly used in the setup and in the automation of system tasks. In DOS and similar OS's there are a simple shell script in the batch files, with .BAT filename extension. The writing of Linux shell script is similar, with some enhancements. <sect2>Type in a test script <p> To begin, type in the following with your favourite editor, and save it with filename "first" in your home directory. <code> #!/bin/sh # This is a comment # The first script I've ever created. echo -n "My first script runs at " date </code> <sect2>Make the script run. <p> To make Linux understand it's a shell script, do a chmod on the file. Do a <tt>chmod 755 first</tt> at your prompt (if you don't understand what that means, go read the <ref id="about-chmod" name="section about chmod">). If you have colour support in your ls, the file will have another colour. <p> Now type <tt>first</tt> and watch the output. It should say something like this: <#unless output=html> <code> My first script runs at Sun Feb 15 02:33:35 CET 1998 </code> </#unless> <#if output=html> <code> My first script runs at insertdate-foo </code> </#if> Well, actually it's lying, since this isn't my first script, not at all :-) <sect2>What did we do ? <p> Now let's check out what the cute little script did... <sect3>Beginning of file <p> A shell script always starts with something like this: <code> #!/bin/sh </code> Telling your shell what program to execute to parse the script. /bin/sh should be availiable on most Linux/UNIX systems, on my system a symbolic link to /bin/bash. <sect3>Comments <p> Lines beginning with '#' are considered comments. Always comment your scripts, otherwise you won't remember after a month why you did things that way. Try to keep version information and date of last modification there too. <sect3>Commands <p> In the shell script you can use commands just like you would type them in at your prompt. Two examples of that are in the example script, <bf>echo</bf> and <bf>date</bf> they are both examples of small unix programs doing their specific tasks very well. <sect4>echo <p> echo does what it's named.. echoing something to the screen. If you give it the -n variable (as in the example script) it won't put any newline after it's output. There are few other parameters, check out the man page. <sect4>date <p> Prints the current system time and date. <sect2>if, for, case <p> Bash of course has support for these.. <sect3>if <p> This is one of the most useful commands, when you want to check if a file is where it should be, if a command executed successfully, and whatever else you usually use a if command for. Type in the following example in second and <tt>chmod 755</tt> it. <code> #!/bin/sh ping -c 2 localhost if [ $? != 0 ] ; then echo "Couldn't ping localhost, weird" fi ping -c 2 veryweirdhostname.noend if [ $? != 0 ] ; then echo "Surprise, Couldn't ping a very weird hostname.." fi echo "The pid of this process is $$" </code> (Yes, I do believe a lot in examples :) ) OK, let's check out what we're doing. <tt>ping</tt> is a net command that checks if a host is up and running, and how long time it takes for a packet to travel the way to the host. If it finds the host and succeeds pinging it, it will leave an errorlevel of 0, else it will leave another, higher errorlevel. That's common practice, if something goes well, it usually leaves errorlevel 0, else it gives something else. <sect2>for <p> For is useful when you want to do something on every file in a directory, the following will do a <tt>file</tt> on every file with a .sgml extension in the current directory. <tt>file</tt> is a very useful command trying to determine what type a file is. <code> #!/bin/bash for sgmlfile in *.sgml ; do file $sgmlfile done </code> I'm sure you can find a better example, please mail it :) <sect2>case <p> Case is very useful when you want to give your shell scripts commandline parameters. Almost all scripts in the SysV init dirs has start, stop and perhaps restart as possible parameters. That's done this way; <code> #!/bin/sh case "$1" in start) echo "Parameter was start" ;; stop) echo "Parameter was stop" ;; reload) echo "Parameter was reload" ;; *) echo "Usage: `basename $0` {start|stop|reload} ;; esac </code> This example also shows how to include a command in a string, very useful feature of UNIX. Put a command inside two "`" and it's output will be inserted. In this case, <tt>basename $0</tt> removes any directories from the name of the script. So if the script is named /scripts/third, it won't say "/scripts/third {start|stop|reload}" but "third {start|stop|reload}". <p> Linux scripting is wonderful, if you compare with DOS or Windows NT or something similar. There are other more powerful scripting languages than bash's, for example perl and python, I don't know too much about either of them, but as fast as I do, I'll write a small chapter. <sect1>Linux configuration <p> <sect2>How ? Global and User settings <p> Almost all configuration in Linux is made by editing text files located at various places. Often there are one global text file, defining global defaults for all users on your system, and one user specific file, defining settings for a specific user. This way, every user can tweak his settings in every detail, or just use the default configuration made by the system administrator. In my opinion a perfect system ! <sect2>Where ? <p> Most global configuration files are located in the /etc directory, and it's subdirectories. Users configuration files are usually located in their home directories, very often as files or directories with names that begin with a '.' You won't see them with a normal <tt>ls</tt>, but with a <tt>ls -a</tt>. Not all programs have user specific files, but userprograms often have. <sect1>The system init files (or, "Where is the autoexec.bat file ?") <p> (this section is true only for systems with SysV init, as Debian GNU/Linux and RedHat Linux, not Slackware). <p> When the system boots, it reads some files to setup itself. After the kernel has booted, it starts a process called <bf>init</bf>, with PID 1. Init reads it's main configuration file called /etc/inittab to get the default runlevel, and a few other settings. <sect2>runlevels <p> A linux system has a few different runlevels, each configured for a specific task. A Debian system normally goes into runlevel 2 when it boots, starting up daemons and more to make the system accessible in different ways and by several users at once. If you start the system in runlevel 1, you'll get a singleuser system for maintainance. Setting the runlevel to 0 will do a system halt, and runlevel 6 will reboot the machine after taking down daemons, umounting file systems and other important things before a shutdown. The runlevels I give here as example are specific for a Debian system, a RedHat or Slackware of whatever distribution have different runlevels for the different modes of operation. <sect2>Runlevel specific files <p> For each of the runlevels, there are files that specify what to do when entering that runlevel. Or, to be more exact, the files are links to files in another directory, this way you won't have 6 copies of each file when the file is used in 6 runlevels. <p> The files have names that start with either <bf>S</bf> or <bf>K</bf>, then a number, and after that a descriptive word. The S or K stands for <bf>Start</bf> or <bf>Kill</bf>, the number stands for when the file is executed, and the rest of the filename is there for uniqeness and completeness. Take the following file list for example, it's from my /etc/rc2.d, ie files to execute for runlevel 2. <code> S10sysklogd S20gpm S20ssh S30netstd_misc S99xdm S12kerneld S20iplogger S20timecount S89atd S13dhcpc S20lpd S20xfs S89cron S15netstd_init S20ppp S25netstd_nfs S91apache S18netbase S20sendmail S26firewall S99rmnologin </code> The file S10syslogd will be executed first, and the file S99xdm will be executed as the last of the files for runlevel 2. This way you may decide when in the boot process something is done. <p> On a Debian system, the files are located in /etc/rc?.d, where the '?' stands for the runlevel. The symbolic links mostly points to files in the directory /etc/init.d. Those files are scripts that take <bf>start</bf> or <bf>stop</bf> as arguments, some of them have <bf>reload</bf> too. When init reads in the /etc/rc2.d and finds the S10syslogd, it will see that's a symbolic link to /etc/init.d/sysklogd and execute /etc/init.d/sysklogd with the argument <bf>start</bf>. After that it will do the same thing with S12kerneld and so on.. If the filename is K10sysklogd, it will execute /etc/init.d/sysklogd with argument <bf>stop</bf> instead. You get it ? Me to :) RedHat has it's files in /etc/rc.d/rc?.d and /etc/rc.d/init.d, AFAIK ! <sect1>BASH's init files <p> Now when we know where configuration files are located, it might be interesting to take a look at the configuration for bash, the most common shell on Linux machines. There are, as there should be, a global and a user file; the global file named /etc/profile and the user file named .bash_profile (well, this is not completely true.. there is other files, .bashrc and .inputrc, but right now I won't deal with them..). <sect2>What is setup in the files ? <p> Environment variables such as PATH, PS1 and such.. aliases, umask and other mysterious things, perhaps some programs is run to do things you want to be executed at your login.. <sect1>Customizing your prompt. <p> This is a little bells and whistles, but very nice to know.. <p> When you've installed your Linux distribution (I recommend Debian), your prompt probably won't look as you want it. The key to changing this is the PS1 environment variable. This is specific for the common shell bash (I think). You make your own prompt by combining some codes in the variable, just like in the (old good ?) DOS days... here is what you can use: <table> <tabular ca="ll"> \a | Bell (makes Linux beep every time it shows a prompt, not recommended !) @ \d | Todays date @ \e | ESC character, useful if you want to send ansi sequences @ \h | Your hostname, to the first '.' @ \H | Your fully qualified hostname @ \n | newline @ \s | The name of the shell @ \t | The current time in 24 hour format @ \T | The current time in 12 hour format @ \&commat | The current time in 12 hour am/pm format @ \u | The username of the current user @ \v | The version of bash @ \w | The current working directory. @ \W | The basename of the current working directory (ie /usr/local will be local) @ \! | The history number of this command @ \# | The command number of this command @ \\ | A backslash @ </tabular> <caption> Codes to use to format your prompt </caption> </table> My own PS1 says "\h:\u \w $", giving me hostname:user working dir $ (I really need all that information, since often I have ssh sessions to a few machines open, and it's REALLY good knowing what machine you currently work at). The best way to set this is in the shell init files. <sect1>Using your mouse - gpm <p> So far, we've just been using our keyboard, typing in mysterious commands, looking at the screen with a total amazement waiting for response. Somewhere to the right (or perhaps left, if you're left-handed) there's a weird shaped thing with a cable attached to it, doing nothing at the moment. They usually call it a mouse, or pointing device. Can you use that thing in Linux text mode ? The answer is yes. <sect2>The mouse server, gpm. <p> When you installed your Linux, most probably a <bf>mouse server</bf> called gpm was installed and perhaps even configured. Gpm is a daemon watching the mouse, and when detecting movement, showing up a mouse pointer on the screen. Gpm is usually started in the init scripts (remember reading about that earlier in this document ? :) ) Command to start gpm could be <tt>gpm -t ms -m /dev/ttyS1</tt> if your mouse is of Microsoft type attached to COM2. If you have a PS/2 mouse, try something like <tt>gpm -t ms -m /dev/psaux</tt>. Anyway, if your mouse server isn't working, read the manual. <tt>man gpm</tt> will probably give some useful information. <sect2>OK, it's running, what can I do ? <p> You move your mouse and a pointer moves on the screen ? Great ! But what is it good for ? <p> The basic function of gmp is as a cut and paste utility. You have one Virtual terminal open with a file listing, and want to open one of the files in an editor in another Virtual terminal. Mark the file in the first terminal (hold left button down and mark, then release it) switch to the other one, and paste the text with the right button. Very useful, when you know about it, you'll miss it if it isn't there. <p> gmp can do other stuff to, if you invoke it with the -S parameter, and then hold your right button and triple-click you left, a message will appear.. if you press one of the buttons again within three seconds, your machine will reboot. Very handy for programmers if the keyboard locks, and he can't telnet in to do a clean reboot. It's possible to specify what should be done instead of rebooting. <sect1>Daemons ? <p> A Linux system, as any UNIX system, has quite a few daemons hanging around, doing nice little things for you. This section will try to explain what a daemon is. <sect2>What's a daemon ? <p> A daemon is a program executing in the background, doing a specific task, usually something important for the system. They are most often started at system boot, and stopped at system halt, running all the time the system is up. Normally, they don't interact directly with the user, instead you tell them how to behave with a configuration file. They are most often well written, so they won't consume much CPU power when they are just waiting for something to happend. <sect2>What daemons are there ? <p> I'll describe some of the most common daemons, in no particular order. <sect3>inetd <p> The "internet super server" is one of the most common daemons. At startup, it reads it configuration file /etc/inetd.conf and then starts listening for incoming internet connections. When someone tries to access your system with, as an example, the telnet protocol, inetd checks it's configuration to see what to do if a telnet request comes, and executes the correct program. <sect3>crond <p> Crond is a very useful daemon, making it possible to execute things at a specified time, or at an interval. You submit a configuration file to it, and every minute it wakes up from it's CPU friendly sleep, and checks if something should be done right this minute. Really useful, if you ask me. <sect3>syslogd <p> This daemon takes care of logging information from various programs, and stores them to the correct place. It's configuration file, /etc/syslog.conf, makes it possible to have logs from pppd in one file, and logs from sendmail in another. It's also possible to have the log on a VT, or even on another machine via TCP/IP. <sect3>klogd <p> Takes care of messages from the kernel. <sect3>atd <p> A daemon waking up every minute to see if something should be done at that time. Kind of similar to crond, but a job submitted to atd (with the command <bf>at</bf>) is only executed once, while a job maintained by cron is executed periodically. <sect3>rpc.portmap <p> This daemon acts a little like inetd for SUN RPC calls such as NFS. Sounded like greek ? Read the nfs man page :-) <sect3>sshd, httpd, nntpd.. <p> These are various internet services, such as secure shell, http (web), nntp (news) running as separate daemons instead of being started by inetd. This makes them a bit faster, but they consume more memory/CPU. <sect3>gmp <p> See the previous section, but basically handling your mouse in consolemode. <sect3>xdm <p> Handling X server, remote or local. If you have a fancy login prompt in X, this is the daemon handling that. <sect1>There are so many directories, I don't understand the file structure ! <p> The directory structure in Linux most often has the same structure as any UNIX. There's a specification specifying how it should be built, the FHS. I'll try to explain what the directories under '/' does. <table> <tabular ca="ll"> /bin | This is where the system stores important executables, needed for the startup of the system. @ /boot | The kernel is often placed here, together with some other boot files, this directory should be on the first 1024 cylinders of the disk, or the disk should be LBA translated, otherwise LILO can't boot the kernel. @ /cdrom | This is a directory I have, as a mount point for my CDROM reader. @ /dev | This is a really interesting directory :). In there, every device on your computer (serial ports, hard disks etc..) has a file, a device file. When you write to the file /dev/ttyS0, the kernel takes care of what you write, and write it to the first serial port of the system. This is a very nice system, since everything in the system can be treated as files. @ /dosc | This is a common name for your DOS <bf>C:</bf>. On every system I've seen, the DOS primary partition has been mounted as /dosc. Don't ask me why ! @ /etc | Global configuration files, often has some subdirs, like /etc/ppp for your dialup PPP internet configuration. @ /floppy | My mount point for floppydisks. @ /home | Users's home directories, every user has a directory in this directory. @ /lib | Shared libraries, important for the system startup. Share libraries are used by many executables at the same time, saving memory and diskspace. @ /lost+found | If you run a fsck, and it finds some weirdness, the result goes here. @ /mnt | This is another non-standard, but common directory. It exist there for temporary mounts, ie if you want to mount some partition you normally not mount, you can mount it here.. Well, that's at least how I use it. @ /proc | This is a really important directory. It exists only as a mount point on the harddisk, the rest is virtual information filled in by the kernel. Here you find information about all your processes, and other information such as which interupts and memory adresses are in use. An easy way to fetch that information, it's just files, as the rest of the UNIX system. @ /root | This is the home directory of the root user. @ /sbin | Executables the root needs to use, that should be availiable at boot. @ /tmp | Temporary files. Everybody can write here, but only the owner of the file may remove the file. Root may do it too, of course. @ /usr | This directory has a lot of subdirs. There is a /usr/bin, a /usr/sbin and so on. /usr doesn't need to be there directly at system boot, but can be mounted a bit later. That way, you can have a small root partition and a bigger /usr and perhaps /home that you mount later. /usr/bin has the same type of programs in it as /bin, but they aren't that essential for the system to work. One subdir of /usr is /usr/local, also having a bin and sbin and lib directory. In local you can place local extensions of the system, and if you upgrade your system the upgrade shouldn't do anything about local, so your changes will still be there. @ /var | var stands for Variable. This directory holds files that could be a lot bigger in a short time, and get smaller really fast too. Typical examples are mail and news spools. @ </tabular> </table> Well, that's about it. Of course this is my version, if you have any feedback, make sure to send a mail to <htmlurl url="mailto:forsberg@lysator.liu.se" name="forsberg@lysator.liu.se"> <sect1>Setting up a PPP connection to your ISP <p> A lot of the useful information about Linux is on the net, I think I've said that before :) Most of the people I know (including myself) don't have a high speed internet connection at home, but rather a dialup connection to some Internet Service Provider. The most common way to connect to the net via a ISP is by PPP (Point to Point Procotol). PPP support is included in most common distributions. <p> Here I'll try to describe a ppp setup that should work for almost all distributions. If you're from Sweden, you might want to check out <htmlurl url="http://www.lysator.liu.se/~forsberg/" name="http://www.lysator.liu.se/~forsberg/"> instead, since there you can find this information in Swedish, together with examples for most of the ISP's in Sweden. The original scripts were created by Simon Josefsson <htmlurl url="mailto:jas@pdc.kth.se" name="jas@pdc.kth.se">. <sect2>Basic setup. <p> As a start, your kernel must have ppp support, and you must have a pppd that isn't too old. Try to execute the command 'pppd' at a root prompt, you should get a lot of funny characters, not the message "This kernel lacks kernel support". I you get the message, something is wrong ! =) <p> By the way, the funny characters stops after a short while, just be patient. <sect2>Files. <p> Start by creating an empty file named /etc/ppp/options. This can be done by executing <tt>:> /etc/ppp/options </tt> at a root prompt. Make a symlink named /dev/modem to the com port your modem is placed at, that is /dev/ttyS0 if your modem sits on COM1, /dev/ttyS1 if it's connected to COM2.. Do this by executing <tt> # ln -s /dev/ttyS0 /dev/modem </tt>. First, make sure the link doesn't exist, your distribution may have done that work at installation. <sect3>/etc/ppp/on <p> Save this as /etc/ppp/on (If read this online, you may retrieve the script by <url url="ftp://ftp.lysator.liu.se:/pub/texts/forsberg/on" name="clicking here"> <code> #!/bin/sh # PPP-script made by Simon Josefsson <jas@pdc.kth.se>. tmpfile=/tmp/ppp.script.$$ source /etc/ppp/provider export TELEPHONE LOGIN LOGINSTR PASSWORD PASSWORDSTR PPPCOMMANDSTR PPPCOMMAND if test -n "$USEPAP"; then PAP="name $PAPLOGIN remotename $USEPAP" fi umask 0177 cat<<EOF>$tmpfile TIMEOUT 5 ABORT BUSY ABORT "NO DIAL TONE" ABORT \nRINGING\r\n\r\nRINGING\r ABORT "NO CARRIER" "" \r\rATZ OK-+++\c-OK ATH0 TIMEOUT 60 OK ATDT$TELEPHONE CONNECT \n TIMEOUT 40 $LOGINSTR $LOGIN $PASSWORDSTR $PASSWORD $PPPCOMMANDSTR $PPPCOMMAND EOF exec /usr/sbin/pppd -detach debug lock modem crtscts /dev/modem 57600 \ noipdefault netmask 255.255.255.0 defaultroute $PAP \ connect "/usr/sbin/chat -v -f $tmpfile" disconnect "rm -f $tmpfile" & </code> Make it executable by executing <tt> # chmod 755 /etc/ppp/on </tt>. <sect2>/etc/ppp/off <p> Save this as /etc/ppp/off (Or, get it by <url url="ftp://ftp.lysator.liu.se:/pub/texts/forsberg/off" name="clicking here">) <code> #!/bin/sh if [ "$1" = "" ]; then DEVICE=ppp0 else DEVICE=$1 fi if [ -r /var/run/$DEVICE.pid ]; then kill -INT `cat /var/run/$DEVICE.pid` if [ ! "$?" = "0" ]; then rm -f /var/run/$DEVICE.pid echo "ERROR: Removed stale pid file" exit 1 fi echo "PPP link to $DEVICE terminated." exit 0 fi echo "ERROR: PPP link is not active on $DEVICE" exit 1 </code> Do the same chmod command to this file, as you did to the file named 'on'. <sect2>Nameservers, /etc/resolv.conf <p> If you want to be able to use the internet by typing names (like <htmlurl url="http://www.lysator.liu.se/~forsberg/" name="http://www.lysator.liu.se/~forsberg/">) instead of numbers (like 10.38.0.18) you have to tell the linux resolver library how to get the information what number correspond to which names. This is done by writing nameserver statements to the file /etc/resolv.conf. Get ip adress of your nameserver from the information your ISP sent you, and write something like this in /etc/resolv.conf <code> nameserver 10.38.0.18 </code> It's possible to have up to three nameservers, they will be tried in the order they are written. <sect2>ISP Specific settings <p> Here comes the hard part :-) Now you must give pppd ISP specific settings, writing some words in /etc/ppp/provider and, if the ISP uses PAP or CHAP, a few words in /etc/ppp/pap-secrets or /etc/ppp/chap-secrets respective. <p> Here is a list of the statements you may use, with descriptions. <table> <tabular ca="l|l"> TELEPHONE=<phonenumber> | The telephone number to your ISP's modem pool.@ LOGINSTR=<login string> | The string that should trigger sending your user name, for example "ogin:--ogin:" works quite well in quite a few cases. PPPD will wait for the string ogin: and then send your account name. @ LOGIN=<account> | Your account name. @ PASSWORDSTR=<password string> | Similar to the LOGINSTR, this tells pppd what to wait for before sending your password. "assword:" will probably work for many systems. @ PASSWORD=<password> | Your password. @ PAPLOGIN=<account> | If your provider uses PAP or CHAP, put your login name here, instead of in the LOGIN keyword. @ USEPAP=<providername> | If your provider uses PAP or CHAP, put the name of your provider here, and put the same name as providername in the secrets file, described later. @ </tabular> </table> <sect2>The secrets file. <p> If your provider uses PAP or CHAP, a line in the /etc/ppp/pap-secrets, or chap-secrets should be added. It should look like <tt><account> <providername> <password></tt> where account and providername is the same as you put in the /etc/ppp/provider with the PAPLOGIN and USEPAP statements. <sect2>Some examples of /etc/ppp/provider and /etc/ppp/pap-secrets <sect3>Provider not using PAP (or CHAP) <p> /etc/ppp/provider <code> TELEPHONE=555112233 LOGINSTR=ogin:--ogin: LOGIN=mystupidaccountname PASSWORDSTR=assword: PASSWORD=MyTooEasyPassword </code> <sect3>Provider using PAP (or CHAP) <p> /etc/ppp/provider <code> TELEPHONE=555221133 PAPLOGIN=mystupidaccountname USEPAP=providername </code> /etc/ppp/pap-secrets <code> mystupidaccountname providername MyTooEasyPassword </code> Well.. I hope this helps.. =) <sect1>Doing things periodically - Using CRON <p> On a UNIX system there is always some things that should be done periodically, for example backups, locatedb updates and such things. This makes life easier, as you don't have to keep all the things you should do in your head, or on silly little notes on your desk. Not to mention the fact that you don't want to sit up all night doing backups. <sect2>The CRON daemon <p> The nice program that makes this possible is the cron daemon. It runs all the time the system is up and every minute it wakes up to see if there is something that should be done. If there is, it spawns a shell that executes some command. I'll describe the most used cron package on Linux systems, Vixie Cron. Check out <htmlurl url="http://www.vix.com" name="http://www.vix.com"> for some more interesting software. <sect2>Crontab's <p> To instruct the crond when to do what, you use crontabs. Like many other programs, cron has a system and a per user crontab. They both have a similar format, with some small differences. What you do in the crontab is to give the minute, hour, day of month and/or day of week a specific command should be run. <sect3>The system crontab <p> The system wide crontab is most often called /etc/crontab. This file should have only important jobs, the file is only writable by root. Mine looks something like this: <code> # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file. # This file also has a username field, that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/etc/ppp # m h dom mon dow user command 44 5 * * * root run-parts /etc/cron.daily 07 5 * * 7 root run-parts /etc/cron.weekly 00 5 1 * * root run-parts /etc/cron.monthly </code> As you can see, there is seven fields with information. They are, in correct order: minute, hour, day-of-month, month, day-of-week, user and command. Some of the fields contain stars (*) which means any value will fit. <p> The first line of my file tells cron that every day (the fields day-of-month, month and day-of-week have stars, so cron doesn't care about them) at 05:44 in the morning I want the command "run-parts /etc/cron.daily" to be run. The command run-parts checks a directory for files that are executable by the user specified in the user field. It runs all of them, in some kind of order :) This is a good way of getting a lot of small things done without writing a big script. Makes it a lot easier maintaining the jobs. My /etc/cron.daily have the following files: <code> calendar* standard* sysklogd* find* man* netbase* smail* tetex-bin* </code> So every morning at 05:44 my computer starts doing things like rotating my logs, updating the manual index files, updating the updatedb database and other things that is quite good if you do once a day. At 05:44 I usually don't use my computer anyway (I do actually sleep sometimes ! ;) ) so these jobs don't use any CPU - time I could need. <p> The other lines work just as the first, executing things every week and every month. There is a user field, if you put another user than root there, it will run the command with other rights than root. That is often recommendable by security reasons. <sect3>The per - user crontab <p> Every user on the system may write his own crontab. The job will be executed even though the user is not logged on. The format is similar to the system crontab, though there is not user field, since a user's cron commands will always be executed as that user. My personal crontab looks like this: <code> 10 5 * * 0 futility tool "+delete" "keep+1300" ; futility pack 5 3 * * * /home/erik/bin/mirroring 15 0-23/1 * * * /usr/bin/fscan </code> As you can see, it has three jobs. The first one goes every Sunday (Day of week field has the value 0, which is Sunday. I could write 'Sun' there too) and does some packing of my fidonet message base. <p> The second goes every day at 5 minutes past 3 in the morning and mirrors some ftp archives. <p> The third executes 5 minutes past every hour 24 hours a day. The syntax 0-23/1 tells cron it should do it once an hour from hour 0 to hour 23. 0-14/2 would mean twice an hour from 00:00 to 14:00 in the afternoon. <sect2>The crontab command <p> When a user wants his own crontab, he has to install it. This is done with the command <bf>crontab</bf>. The syntax is quite simple, <bf>crontab name-of-crontab</bf> will install the file you specified as your new crontab. The command crontab has some other switches, to list, edit or remove crontabs, but the basic syntax is actually all you need to know - If you want to edit you crontab, do so and reinstall it with a new crontab command. <sect2>Environment variables and file rights. <p> There are a few things one should think of when trying to master cron. First cron doesn't read your login files to set the path you're used to, so a command that executes just fine when you test it may not run at all because cron can't find some file. There are two solutions to this problem, the first is to use only absolute filenames (ie give the whole path to the files), the second to include something like <code> PATH = /usr/local/bin:/home/foo/bar </code> in your crontab. That way you set the environment variable PATH, so your scripts will find the files. <p> Another environment variable of interest is MAILTO. If you set that variable (the same way as you set PATH) cron will mail the output of your commands to the address specified. Cron will by default mail the output to the user the crontab belongs to, but if you want the mail to go somewhere else you may specify it in the variable. You may also give an empty MAILTO variable (by writing "MAILTO=" in your crontab). Cron won't mail any mails to an empty address.. <p> File rights can sometimes be a problem. If cron doesn't want to execute your scripts or programs, try giving the group or world execution rights to the file. That may solve the problem. The irritating thing is cron won't tell you it can't execute, it just sits there doing nothing. <p> I hope that will help you in further cron adventures =) <sect1>Accessing a computer in a secure way - SSH <p> One of the really good things with UNIX computers is you can access them the same way wherever they are located. I can do the same things on my local computer, as I can do on a server in the US, by an interactive command line session. I can even run X window system programs on another computer, and get the window on my local screen. <sect2>telnet, rsh, rlogin <p> The old way of doing this is to use telnet, rlogin or rsh, all of them unencrypted standard protocols availiable at most UNIX computers. Sure they work, but you send your password in plaintext, not to mention all the data you enter during your session. That's not good, since network security is getting more important all the time. <sect2>ssh <p> There is an alternative. Secure Shell, developed in finland, encrypts everything you send, including your password. It has even more features, it can forward ports, and forward X window system connections. It also has quite a few ways of authentification. <sect3>Where do I get it ? <p> Most major distributions have a ssh package, though you may have to look in some special directory, since the US government by some reason doesn't permit export of programs with encryption, therefore those files has to be kept outside the US. Don't aks me why they do this, I can't find a reason. If you can't find a package, get the source from <htmlurl url="http://www.ssh.com" name="The ssh communications security">, the company who developed it. <sect3>Version 1 or 2 ? <p> There are two major versions of the ssh protocol. Version 1, and version 2. Most systems in use runs version 1, it works well. The second version hasn't been out for a long time, and it has a license that gives some problems. Be sure to read the license for the ssh before you use it. Anyway, using version 1 works good. <sect3>Server and Client <p> The ssh protocol needs its own server, sshd, running. Well, it may be run from inetd, but it works best if it runs as a daemon. <p> To connect to a computer with sshd running, you use ssh, the client. You type something like <bf>ssh hostname</bf>, type your password, and gets connected. <p> Run ssh without arguments to see what command line parameters there are. One of the most used is -l which lets you specify your username on the remote machine. <sect3>Authentification <p> Ssh has a lot of ways to authenticate you to the server. The most basic one is by password, just the way you would do if you used telnet. The difference is your password is never sent in cleartext, it's encrypted, so a person listening to the network where you send your data can't fetch your password. <p> The second way is by RSAhost authentification. If the host you are connecting to has the host you are connecting from listed in either it's /etc/hosts.equiv or /etc/shosts.equiv or in .shosts or .rhosts in your home directory on the server host, it will permit your login if it recognizes the client hosts host key. A host key is uniqe for every single machine, and every time you connect to a new machine that machines host key is stored in the file $HOME/.ssh/known_hosts. This way of authentification closes security holes due to IP spoofing, DNS spoofing and routing spoofing. <p> A third way of authentification is a RSA based public-key technology. You generate a pair of keys (one private and one public) with the command <bf>ssh-keygen</bf> and place the public part of it in the file $HOME/.ssh/authorized_keys on every host where you want to login using this type of authentification. When you try to connect to one of these hosts the server and client finds out you have a .ssh/identity on your host, and a .ssh/authorized_hosts on the server. If they match, you are allowed access. If you encrypted your private key with a password, you'll have to type in that to get access. <p> A very good way of using RSA based public-key authentification is with the program ssh-agent. That program keeps your personal keys on it's mind, and if you have a passphrase for them you only need to enter them once, with the program ssh-add. <p> As you've probably foundout, this information is not at all complete, it isn't meant to be. When it comes to security related things, always read the manpages. I've only written enough to get you interested ;-) <sect>Some other Linux information, perhaps not for the new user <p> I'll try to assemble some of my experiences here, dealing with some problems, software I've coped with, and other things.. <sect1>A script to turn off the 'beep' <p> When you push the wrong key in Linux, it beeps.. it even beeps sometimes when you press the right key.. If you get irritated, just run this script with a parameter 'off' or 'on' (I think it'll only work under the bash shell) <code> #!/bin/sh if [ "$1" = "off" ]; then echo -e "\33[11;0]" echo "Bell turned off." fi if [ "$1" = "on" ]; then echo -e "\33[10;750]\33[11;250]" echo "Bell turned on." fi if [ "$1" = "" ]; then echo "Usage: $0 <on|off>" fi </code> (If you're reading this from the web, it might be more convenient to download the file by shift clicking <htmlurl url="bell" name="here">) <sect1>Using your printer in an intelligent way <p> One good piece of software I've found is apsfilter, making it possible to print almost any kind of file with a simple command. It works with a large number of printers, including all postscript printers, epson printers, Deskjet printers and all printers supported by the ghostscript software. <p> You must have lpd/lpr installed, and ghostscript, and a few other things.. <sect2>How it works. <p> Install it, and print files with the command lpr, you can print a large number of formats, including postscript and LaTeX and compressed files and usual textfiles and... and apsfilter converts to the right format and prints it.. wonderful :-) It works with more than one printer too, I have a Citizen ProJet II (emulating a HP Deskjet), and a Fujutsi DL 1100 (emulating an Epson), and they both work very well. <sect2>Where do I get it ? <p> The official ftp site is <htmlurl url="ftp://ftp.informatik.rwth-aachen.de/pub/Linux/local/packs/APSfilter" name="ftp://ftp.informatik.rwth-aachen.de/pub/Linux/local/packs/APSfilter">. I think you could get it on the nearest sunsite mirror. <sect1>Slow loading X or X clients (netscape or similar) ? <p> On systems without math coprocessor, or perhaps just a system without the absolutely newest hardware, there are sometimes problems with X clients loading slowly. <p> One tips that perhaps might give some better performance is to look at the Fontpath section of your XF86Config, mine looks like this: <code> FontPath "/usr/X11R6/lib/X11/fonts/misc/" FontPath "/usr/X11R6/lib/X11/fonts/75dpi/" FontPath "/usr/X11R6/lib/X11/fonts/100dpi/" FontPath "/usr/X11R6/lib/X11/fonts/freefont/" FontPath "/usr/X11R6/lib/X11/fonts/Type1/" FontPath "/usr/X11R6/lib/X11/fonts/Speedo/" </code> It's all in the Files section. Well, the trick is, the "Type1" and "Speedo" Paths' should be moved to the bottom of the list (like they are in my example), or perhaps commented out. If you have them in the beginning of the list it might slow down things. Try it ! <sect1>BackSpace not working in X ? <p> Sometimes you find that you can't use backspace in a X program. I had problems especially with TCL/TK programs, where I had to type Ctrl-H instead. A solution that works for me is adding the line <code> keycode 22 = BackSpace </code> to a Xmodmap file, and run xmodmap on that.. <sect1>No colours in your file listings ? <p> Something I do on every new Linux installation I do, is an alias for ls. First, let's explain how to use the alias command, available at least with bash and tcsh. Alias will put a table in memory, and when you type a command that matches, it will execute what you've specified instead. There's a command for this in DOS too, but I can't remember right now. <tt>alias ls="ls --color"</tt> will do the right thing in bash, I think <tt>alias ls "ls --color"</tt> is the correct syntax for tcsh, but not sure there. You can do a lot of things with alias.. <p> Of course, you don't want to type <tt>alias ls="ls --color"</tt> every time you log on, so a good idea is to put the command in the file .bash_profile in your home directory. That way it'll be done every time you log on. <sect1>How to find a program for a specific purpose ? <p> People knowing nothing about Linux says there are no software for the operating system. As we all know, that's as wrong as it could be, there are tons of programs, most of them free for you to use. <p> <sect2>The LSM <p> Even though there is tons of software, it is sometimes hard to find just the piece of software you need for a specific task, that's where the LSM, the Linux Software Map comes in. The LSM is a database of thousands of programs, with descriptions and information where to find the program. The primary site for the LSM is <htmlurl url="http://www.execpc.com/lsm/" name="http://www.execpc.com/lsm/"> <sect2>Browsing the LSM <p> Of course it's possible to read the LSM with your favourite pager (ie 'less' or similar), but using a special tool is better. I recommend the lsmsearch utility, with a nice dialog interface, letting you search keywords and freetext. It's availiable at your nearest sunsite mirror, in the search directory. <sect1>Date and time in Emacs status bar <p> Emacs is a very good editor (Well, almost religion for some people :-) ), with so much configuration possibilities one could configure it for years, and that's good ! <p> I want emacs to display the current date and time in it's status bar, place this in your $HOME/.emacs and start emacs.. <code> (setq display-time-day-and-date t display-time-24hr-format t) (display-time) </code> And watch the magic ! It'll now display Date, Time, system load and mail status in the status bar. Really useful, if you ask me. <sect>Some links to other information sources <p> <sect1>Where to get Linux <p> There are several ways to get Linux, now when you know how supreme it is =) Mainly there are two ways; From the net, if you have a fast internet connection (or a friend with fast access..). From a CD, they're really quite inexpensive. <sect2>CDROM Vendors <p> Examples of companys selling CD's with Linux on, is <url url="http://www.cdrom.com" name="Walnut Creek CDROM"> and <url url="http://www.infomagic.com/" name="Infomagic">. <sect2>FTP sites containing Linux. <p> There are a lot of them ! First, check out the main webpage of the distribution you want and check out their instructions for getting the dist. They often have a list of mirrors containing the same files, that way you won't load the main server too much, and you'll get a faster transfer. An important Linux ftp site is <url url="ftp://sunsite.unc.edu/pub/Linux" name="sunsite.unc.edu">. There are a lot of Linux programs and distributions there. Other important sites is <url url="ftp://tsx-11.mit.edu" name="tsx-11.mit.edu"> and <url url="ftp://prep.ai.mit.edu" name="prep.ai.mit.edu">. Learn how to find programs, especially on sunsite, since there is almost always what you want, it's just a matter of finding it. <sect1>Linux/UNIX links, in no particular order. <p> <itemize> <item><htmlurl url="http://www.allexperts.com/software/unix.shtml" name="Allexperts.com - The Unix section">. A website with volunteer experts answering your questions. <item><url url="http://svlinux.home.ml.org" name="Information about running Linux in Sweden, with correct characters :)"> <item><url url="http://www.sun.com/sunworldonline/sun.index.html" name="SunWorldOnline, very nice online magazine with UNIX information."> <item><url url="http://sunsite.unc.edu/mdw/LDP/" name="The Linux documentation project, home of the manpages, the HOWTO's and some good books"> <item><url url="http://www.linux.org" name="Linux.ORG, a very nice page"> <item><url url="http://www.linuxhq.com" name="Linux v2 Information HQ, patches to the kernel."> <item><url url="http://www.kernel.org" name="The Linux Kernel Archives"> <item><url url="http://www.debian.org" name="The Debian GNU/Linux Distribution headquarters"> <item><url url="http://www.redhat.com" name="RedHat, another Major linux distribution, though more commercial than Debian"> <item><url url="http://lwn.net" name="Linux Weekly journal, really good site with the Linux news of the week"> <item><url url="http://slashdot.org" name="Another very updated site. &dquot;News for nerds, stuff that matters&dquot;"> <item><url url="http://www.lysator.liu.se/~forsberg" name="My other page, with a link to this one, and a FAQ for the swedish fido meeting R20_LINUX (all in swedish)"> <item><url url="http://webwatcher.org" name="Linux Web Watcher. Keeps track of the change date of a lot of Linux related pages."> <item><url url="http://www.linuxmall.com" name="The Linux MallOnline shop with those really useful things you need as a true Linux user =) "> <item><url url="http://www.adelaide.net.au/~rustcorp/ipfwchains" name="The Linux Generic IP Firewall Chains. Info about the firewall design in the 2.1.102 and later kernels"> <item><url url="http://www.geocities.com/SiliconValley/Circuit/7737/" name="Mango Girl's Links for Linux newbies. Ackording to the author of this page, it sucks, but I think it's quite a nice compilation of links :)"> </itemize> <sect1>Programming links (almost only about 'C') <p> <itemize> <item><url url="http://www.python.org" name="Home of python, another script language"> <item><url url="http://kipper.york.ac.uk/~vic/sock-faq/" name="Unix Socket Programming. With the Socket FAQ, and a few good links."> <item><url url="http://www.hal9k.com/cug" name="C/C++ Users Group"> <item><url url="http://www.utu-fi:80/~sisasa/oasis/main.html" name="Programmers oasis"> <item><url url="http://intranet.ca/~sshah/booklist.html" name="The programmers booklist, by Sunir Shah"> <item><url url="http://www.strangecreations.com/" name="The programmers virtual library"> <item><url url="http://info.desy.de/user/projects/C++.html" name="The Virtual C++ Library"> <item><url url="http://www.brokersys.com/snippets" name="The snippets collection, a lot of examples, FAQ's and such things in a package"> <item><url url="http://cires.colorado.edu/people/peckham.scott/tutors.html" name="Scott's tutorial hotlist"> <item><url url="http://www.lysator.liu.se/c" name="Programming in C, at Lysator, Linkoping university"> </itemize> <sect1>Other links, useful places, useful programs etc.. <p> <itemize> <item><url url="http://lynx.browser.org" name="Home of LYNX, THE Webbrowser"> </itemize> <sect>Thanks to.. <p> .. all the people in the Swedish R20_LINUX fido conference for their knowledge about the best operating system in the world. Also thanks to the people in the international fido meeting LINUX, also recommended for it's nice people and good answers. For information about the nice computer conference network fidonet, check out <htmlurl url="http://www.fidonet.org" name="www.fidonet.org">. The people in the Electronic Conference system <url url="http://www.lysator.liu.se/lyskom" name="LYSKom"> have a great knowledge too. <p> Thanks to Ed Suda,Peter Åstrand, Jon Berg, John Paulsen, Wei Chen and Ron Price for feedback and corrections. </article>