The gates in my computer are AND, OR and NOT, not Bill.
(tony)
Back in the last century, around 1990, I made my first programming experiences in C. At about the same time I got in contact with the Unix operating system. It was Digital's Ultrix 4 on a DECstation 2100. At that time, a 330-MB hard disk space was huge, and 32 MB of memory were incredibly vast. The operating system included all those tiny tools that you whished you had under MS-DOS, the C compiler came along with it, it was real multiuser and multitasking, and the c-shell csh could do things that command.com could not even dream of.
From this time on I was waiting for an affordable Unix-like system on an affordable platform. You guessed it: then came Linus and his Linux, and today I'm running a number of PCs under Linux, both at home an at my workplace.
This site is not an introduction to GNU/Linux - this has been done on many other places on the web. What you will find here is a collection of scripts and tricks from my daily use.
As a side note: I'm using 'Linux' as a synonym for the 'GNU/Linux' system. Strictly speaking, Linux is the operating system's kernel, while the GNU utilities plus a lot of other software form most of the programs on this system. Thus, while 'GNU/Linux' would be a "more correct" name, I prefer 'Linux' for its brevity and - IMHO - elegance.
saveconfig is a handy script to get a copy of the most important configuration files in one run - for backup, documentation and for the preparation of a system update or a fresh install on another machine. It saves the most important configuration files as tar-archive to floppy disk (or to USB stick, or whatever you want ;-), and it provides a textual listing of some of those files. - Note that a few of the commands are only accessible as root.
If you use a dial-up connection, timehosts is a simple script to synchronise both the system time and the hardware clock with a public time standard via Internet. - You will need to adjust the ntp server according to your timezone.
Click here to download the timehosts
script. Now supports also server on the local network
(option '-l').
"Nobody cares if you do backups. All that counts is your ability to restore the data."
Among others, I maintain a Linux system that runs some MySQL databases. To save the database files in regular intervals, the script below is called every night via crontab. It archives the files to a backup drive, in our case a NFS-mounted drive on a physically different computer. - Please adjust the mount points to your installation before launching. Indications for setting up the cron job are in the file.
Similar to the above, this is a simple script to archive the /home directory tree to a remote computer. It is called as a cron job. - Please adjust the mount points to your installation before launching. Indications for setting up the cron job are in the file.
KMail is a full-featured email client for the K Desktop Environment. To do a daily, quick backup of my personal mail data and settings to diskette, I wrote this script. It saves all the email, plus the address book and configuration files for KMail and the kppp dialer. The script is adapted for KDE3. - Of course you can adapt this to any other storage location, such as an USB drive.
Firefox is a great web browser, but it has one downside: Mozilla products use a random folder name for user profiles. This causes a problem if you want to use the same bookmarks name on multiple computers, e.g. by synchronisation with unison.
The workaround is easy: Simply rename your profile folder in ~/.mozilla/firefox to whatever fits your needs - e.g. default.JHa. Then, edit ~/.mozilla/firefox/profiles.ini to reflect this change, and you're done.
Source: Micah Carrick's blog.
Everybody knows that MS Windows sometimes "crashes", and in rare cases you need to re-install the whole operating system. Now, reinstalling Windows requires many reboots to upgrade to the latest drivers for motherboard, graphics, sound, modem and the like. If you cannot do without Windows, I recommend to make a backup of the complete, fresh installation - not only of the files, but really of the whole partition. This is easily achieved using Linux (you may use any floppy-based Linux to do this):
dd if=/dev/hda1 | gzip -c > /mnt/nfs/part_win95.gz
... assuming hda1 is your windows partition, and /mnt/nfs is a free partition (local or remote) that you can write your data to. Alternatively, do the same thing over ssh:
dd if=/dev/hda1 | ssh login@remote 'gzip -c > /path/to/part_win95.gz'
The process may take a while, and the resulting file may be quite large (more than half of the partition size) even if the actually installed data are only 300 MB - this is due to the archival of the "raw" partiton data. Axel Buergers pointed out that this problem can be largely reduced by defragmenting and then "filling up" the Windows partition with a huge NULL file, something like dd if=/dev/zero of=/mnt/dos/eraseme bs=reallybignumber, which will abort once the partition is full. The file /mnt/dos/eraseme can then be deleted, and the "clean" partition archived as above. This "cleaning" process can reduce the size of the final partition image by 50%.
To unpack such a file to the original location:
gunzip -c /mnt/nfs/part_win95.gz | dd of=/dev/hdx
Source: Patagonia
CloneSys at the ETH Zürich.
See also: Partimage.org,
a utility to save partitions.
If you do need to copy data over the network in a very simple way - without scp or ssh, without ftp, even without telnet ... there is still netcat, the swiss knife of networking (on some systems the binary is called nc). I sometimes use a floppy-based Linux, such as tomsrtbt, to copy data between two computers, e.g. to backup the whole harddisk of a laptop.
An example how to use tar over netcat:
On the "sender" side, launch tar and pipe its output through netcat, specifying the destination IP address, "listen"-mode (-l) and an arbitrary port number, e.g. 5555:
tar cvf - . | netcat -l -p 5555
On the "receiving" computer, just give the sender's IP address (or hostname) and the same port number, and pipe the output through tar to unpack:
netcat 192.168.xxx.yyy 5555 | tar xvf -
... and the data will be transferred. The same works with almost any other command, e.g. dd instead of tar.
A while ago the amount of data that should be included in a daily backup outgrew the volume of a CD-RW. At a time when I did not yet have a DVD writer but access to a tape drive, I wrote the script backup2tape.sh. Some features:
The script relies on Jörg Schilling's star. I am using this script with success for several years now to perform regular backups on several Linux machines, either manually or via cron, with DDS2 and DLT tapes.
Click here to download the backup2tape.sh script
(updated 2008-08-25).
One of the wonderful things with Linux is the built-in "allround" networking. This makes it very easy to use almost any device that is attached to a remote computer, such as the display, scanner, or other devices. If you want to use a remote tape drive (say, located on machine "tapehost") to backup your local computer, use something along the following line:
tar cvf - /path/to/file | ssh tapehost 'buffer -s 32k -p 75 -m 10m > /dev/nst0'
Tape access usually requires root rights, so you may need to enable superuser access by adding the option -h to the entry for rshd in /etc/inetd.conf:
shell stream tcp nowait root /usr/sbin/tcpd in.rshd -Lh
You can use a similar procedure to clone an existing system to another one (where the remote system, here called targetPC, should be booted from floppy or CD, so that no access to the harddisk is required for system operation during the cloning process):
(cd / && tar cpf - .) | ssh targetPC '(cd / && tar xpf -)'
... or the other way round, i.e. you fetch the system from targetPC:
ssh sourcePC '(cd / && tar cpf - .)' | (cd / && tar xpf -)'
If you use your computer for serious work, the price of lost data is certainly more expensive than any backup medium. That's why I perform regular backups onto CD-RW media (see below), and from time to time I archive my complete /home directory tree onto CD-R. The media are nowadays really cheap (you can find quality CD-R for 0.50 CHF). If I have less than 650 MB to save, I use multi-session CDs and add several sessions onto the same disk, but in different directories. First, create an ISO image:
mkisofs -L -J -R -V Backup_Home -m '*cache*' -o /tmp/img.iso -graft-points home.20010704/=/home
The trick for differentiating backups from different dates lies in the option -graft-points. I use this to relocate the directory /home to the new directory home.20010704 on the CD - the extension after the dot is the date when the backup was performed, here it is the 4th of July 2001.
The other options stem from practical considerations: -R preserves file ownership and permissions, -J enables the Joliet filesystem, so that all filenames are readable on Linux and MS-DOS systems. -L allows filenames with a leading dot (think hidden files ;-), and -V is followed by the volume name. -o gives the name of the output file (here, /tmp/img.iso), and -m excludes cache files - I do not need a backup of that.
Make sure you use mkisofs 1.13 or later. The earlier versions had problems with multi-session disks. -- For 650-MB CD media, don't let the image file to grow bigger than 332500 blocks (each 2048 bytes, makes 680960000 bytes in total). Some CD-writing programs and/or CD-R disks don't allow bigger images. Then, burn the disk using the option -multi for a multi-session disk:
cdrecord -v -multi -pad speed=6 dev=0,6,0 /tmp/img.iso
When the next backup is due, we need to recover the information of the previous session. This is done by inserting the CD and launching mkisofs with the options -C and -M (see the manpage for details):
mkisofs -L -J -R -V Backup_Home -C `cdrecord dev=0,6,0 -msinfo` -M /dev/scd0 -m '*cache*' -o /tmp/img.iso -graft-points home.20010710/=/home
mkisoifs will report the size of the final data, including the first session. Verify that it fits on the CD, then burn the disk with the same command as above. If this is the last session on the disk, close the disk by simply omitting the -multi option from cdrecord:
cdrecord -v -pad speed=6 dev=0,6,0 /tmp/img.iso
If you mount this disk in /cdrom, you will see two directories, /cdrom/home.20010704 and /cdrom/home.20010710, holding the data from the different backups.
Note that there is a certain risk if you use multisession CD-R as your only backup medium: If, for any reason, writing the CD fails, all data on that CD are gone. So, use at least two independent techniques for backup, and verify that you are able to restore your data.
Note also that mkisofs does not follow symbolic links. If you have a symlink called /home/audio that points to /mnt/audio, these data will not be included!
Besides the "permanent" backup to tape and/or CD-R media, I use CD-RW to perform quick, systematic backups of the most important system directories, such as /home, /root, /etc and /var.
The script saveset.sh meets several of my requirements: It allows inclusion and exclusion based on patterns, verifies that the data fit on a single CD and that enough disk space for the temporary file exists, it uses relocation to avoid merging of directories, and it preserves access rights. The script also allows to read an external configuration file, e.g. to use with multiple data sets or multiple CD-RW devices. - This script has also been the subject of an article on the Pro-Linux site, written by Hendric Stattmann (in German), and has been extended for use with a DVD writer by the same author.
Download the saveset.sh script.
Instructions for configuration are in the file.
Download the saveset-dvd.sh script.
Instructions for configuration are in the file.
If you are sure that you regularly exceed the capacity of one disk, you might be interested in the cdtape script below.
The script cdtape lets you use a CD-RW drive similar to a tape drive. It actually is a filter, redirecting the output from your favourite archive/compression/whatever utility to cdrecord. A few usage examples:
To save a directory to CD: tar cf - /DirectoryToBeSaved | cdtape save
To obtain a listing of the archive: cdtape restore | tar tvf -
To extract a certain file from the archive: cdtape restore | tar xvf - FileToRestore
To copy an audio CD which does not have the traditional two seconds of pause between tracks (which is often the case with Live CDs), cdrdao is the software of choice. To copy an audio CD "1:1", first run
cdrdao read-cd --device 0,5,0 --paranoia-mode 3 audio-cd.toc
which writes a binary image file data.bin into the current directory, correcting any scratches or errors as far as possible. To write this image back onto a fresh CD, use
cdrdao write --device 0,6,0 --eject audio-cd.toc
If you want to do a test run before burning, add --simulate. Note that the filesize reported here is not strictly correct as the CD is written in audio format - what counts is the number of blocks written, and this should not exceed 332500.
Recent versions of cdrdao have this functionality built in:
cdrdao copy --source-device ATA:1,1,0 --device ATA:1,0,0 --buffers 64
So what is the "best" way to copy a data CD?
The problem lies in the extraction of the "raw" data as an ISO image from the CD. Inspired by an article from Steve Litt, I took the first disk from my SuSE Linux 7.3 and ran a number of different commands on this disk.
First of all, some statistics from isoinfo -d -i /dev/scd0:
CD-ROM is in ISO 9660 format System id: LINUX Volume id: SU7300.001 [snip] Volume set size is: 1 Volume set seqence number is: 1 Logical block size is: 2048 Volume size is: 330704 Joliet with UCS level 3 found Rock Ridge signatures version 1 found
The output of isosize -x /dev/scd0 is coherent with this:
sector count: 330704, sector size: 2048
Then I ran a few different commands that are frequently used to copy disks:
temp/iso> cat /dev/scd0 > ./img_cat.iso temp/iso> dd if=/dev/scd0 of=./img_dd_bare.iso 1323416+0 records in 1323416+0 records out temp/iso> dd if=/dev/scd0 of=./img_dd_bare_corr.iso conv=notrunc,noerror 1323416+0 records in 1323416+0 records out temp/iso> dd if=/dev/scd0 of=./img_dd_bs.iso bs=2048 330854+0 records in 330854+0 records out temp/iso> dd if=/dev/scd0 of=./img_dd_count_corr.iso bs=2048 count=330704 conv=notrunc,noerror 330704+0 records in 330704+0 records out temp/iso> dd if=/dev/scd0 of=./img_dd_count_nocorr.iso bs=2048 count=330704 330704+0 records in 330704+0 records out
Up to this point, all six techniques seem to work fine. But then, a look at the file size (here: in blocks of 2k) reveals a surprise:
temp/iso> ls -s -1 --block-size=2048 total 1655600 331180 img_cat.iso 331180 img_dd_bare.iso 331180 img_dd_bare_corr.iso 331180 img_dd_bs.iso 331030 img_dd_count_corr.iso 331030 img_dd_count_nocorr.iso
None of these files is 330704 2k-blocks in size, and there is a difference of 150 blocks (of 2048 bytes each) between the "raw" files and the two files generated using the bs= and count= options!
A comparison all files to the CD-ROM (diff -r $file /dev/scd0 as well as the checksums generated with md5sum show that the latter two files differ from the original CD-ROM (first line):
993b97cd78ce73ac37f5ac8db50824f5 /dev/scd0 993b97cd78ce73ac37f5ac8db50824f5 img_cat.iso 993b97cd78ce73ac37f5ac8db50824f5 img_dd_bare.iso 993b97cd78ce73ac37f5ac8db50824f5 img_dd_bare_corr.iso 993b97cd78ce73ac37f5ac8db50824f5 img_dd_bs.iso 8acfbbfac2b4bdb8113d774ca29b7d5e img_dd_count_corr.iso 8acfbbfac2b4bdb8113d774ca29b7d5e img_dd_count_nocorr.iso
It gets even more surprising: The data reported by isoinfo -d -i $file or isosize -x $file do not refer to the complete file but are only the header information! If you don't believe this, then just run one of the two programs on the ISO file while the CD is being extracted, i.e. when the image file is guaranteed not to be complete. The size reported will always be that of the "theoretical" file ... !
Thus, my recommendation to copy a data CD "1:1" is as follows:
(Note: For the following discussion I assume that "Mixed Mode" is identical with "CD+" (CDplus), i.e. Music tracks with added data. Please correct me when I'm wrong!)
You cannot just write audio and data tracks "mixed" on a CD-R, as (1) an audio CD-Player will identify one more audio track than there are (it's the data track), and (2) the data track is no longer accessible. It is there, but the CD cannot be mounted, neither under Linux nor under Windows! So, here's how to do it:
First, write your audio files onto a multi-session disk:
cdrecord -multi -pad speed=6 dev=0,6,0 -audio *.wav
Then, retrieve the multi session info:
cdrecord dev=0,6,0 -msinfo
This will print the session start positions of the last and the next session, generally something like "0,121550". Now, create an ISO filesystem with the data files that includes the above "offset" for the multi-session audio part:
mkisofs -R -J -o /tmp/fs.iso -C 0,121550 temp/
In this example, the ISO image will be created in /tmp and we read the data files from a directory "temp" which is located below the actual working directory. We specify -J and -R to obtain a CD that is readable both under Linux and MS-Windows. - mkisofs will issue a warning that option -M was not specified, however, we don't need this feature here - just ignore the message.
The final size reported in the mkisofs output is that of the complete CD, including the audio tracks we recorded before. Note that you cannot "dry-run" mkisofs with the option -print-size in this mode; it will report a wrong size.
Next, burn the image onto the CD. We do not specify "multi" here as we will close the CD:
cdrecord -pad speed=6 dev=0,6,0 -v -data /tmp/fs.iso
... and you're done. This CD can be played in an audio CD player and be read as a normal data CD in your computer. I could not find any difference between a CD made this way and a commercial CD+ (well, the only one I have ;-).
(Based on Jörg Schilling's pages around cdrecord).
To create a bootable ISO9660 cdrom image file with Joliet and Rock Ridge support, change directory to the place that will be the root directory of the cd. Then:
mkisofs -v -J -r -T \ -b images/boot.img \ (boot image) -c boot.catalog \ (boot catalog, will be created by mkisofs) -p My_Name \ (Preparer, <128 characters, optional) -A My_boot_CD \ (Application ID, <128 characters, optional) -V Linuxboot \ (CD ID, optional but recommended) -o /tmp/img.iso . (ISO image to be written)
Then, test your new disk image by mounting it. If you forgot to fix file permissions or set the rock ridge extensions then the error will be obvious here since the file names and directory structure will be wrong:
mount -t iso9660 -o ro,loop=/dev/loop0 /tmp/img.iso /cdrom
When you're done, unmount it and burn the disk.
(I captured this somewhere on Internet but I admit I have lost the source!
See also
Martin L. Purschkes page about creating your own rescue CD.)
Note: This section is nowadays obsolete since all recent Linux distributions can handle such drives "out of the box". However, I'm leaving this information online for reference purposes.
CD-R and CD-RW drives with SCSI are supported natively by Linux. Using an IDE (ATAPI) CD-RW is not difficult either:
In case you are using Kernel 2.4, the latter procedure also works if you use a "real" SCSI adapter together with an ATAPI-CD-writer. In /etc/init.d/boot.local, add a second line that may look like this:
/sbin/modprobe ide-scsi /sbin/modprobe aic7xxx
In this example, the second line loads the kernel module for an Adaptec 2940 card after the ide_scsi module. - In such a system, the IDE-SCSI device will show up as host scsi0, and the "real" SCSI adapter will appear as scsi1. Here is the output of cat /proc/scsi/scsi on a system that uses IDE harddisks, an IDE CD-RW plus a SCSI tape:
Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: PLEXTOR Model: CD-R PX-W1610A Rev: 1.03 Type: CD-ROM ANSI SCSI revision: 02 Host: scsi1 Channel: 00 Id: 03 Lun: 00 Vendor: Quantum Model: DLT4000 Rev: CC37 Type: Sequential-Access ANSI SCSI revision: 02
Need a quick copy of LILO written to a boot disk? Insert a floppy (don't mount it) and run lilo -b /dev/fd0h1440. With this, LILO is written to the floppy without modifying your actual /etc/lilo.conf file. For details, look up the lilo manpage.
To change from the graphical screen to a text console (aka "terminal"), use Alt-Ctrl-F1 (and the other F-keys for more). With Alt-Ctrl-F10 you get the system messages - if you leave your computer unattended for a long time, it is a good idea to switch to this console before.
To access (grab) the image of a text console, use the device files vcsn. You can access them as user root.
Usually, system logs are written to /var/log/messages. If you want a "live copy" of these messages simultaneously on console 9, simply edit the file /etc/syslog.conf and duplicate the line pointing to /var/log/messages as follows:
*.*;mail.none;news.none -/var/log/messages *.*;mail.none;news.none /dev/tty9
After running rcsyslog restart, system messages will appear also on console 9 (reachable with Alt-Ctrl-F9).
(Thanks to Romeo Benzoni in ch.comp.os.linux!)
To make use of the kernel SYSRQ key, set ENABLE_SYSRQ=yes in /etc/sysctl (on older systems: /etc/rc.config). If you press the key combination ALT + SysRq (aka PrtScr) plus one of the following keys, this will do ...
Sometimes I have to abort a CD burning process, or I forgot to switch on one of the devices on the SCSI bus. Now, every reboot is a reboot too much, so here is a way to add a SCSI device when the system is already running.
Removal (necessary for "screwed-up" devices):
echo "scsi remove-single-device a b c d" > /proc/scsi/scsi
Adding a new device:
echo "scsi add-single-device a b c d" > /proc/scsi/scsi
where a is the hostadapter id (first one being 0), b is the SCSI channel on hostadapter (first one being 0), c is the device ID, and d the LUN number (first one being 0). With a single SCSI card, usually all you have to care about is the device ID c, the rest is 0.
In the case of my CDRW, which is the 6th device on the first SCSI bus, this is as simple as
echo "scsi remove-single-device 0 0 6 0" > /proc/scsi/scsi echo "scsi add-single-device 0 0 6 0" > /proc/scsi/scsi
Many thanks to Patrick Fuerlinger in ch.comp.os.linux!
Note: SuSE Linux comes with a script rescan-scsi-bus.sh
for that purpose.
The same command that was mentioned in the previous section allows to switch on a SCSI device after the computer has started - as an example, when I want to do a backup but forgot to switch the tape drive on at boot time:
echo "scsi add-single-device 0 0 4 0" > /proc/scsi/scsi
It does not hurt if you get the wrong device ID. If you chose the right one, the command cat /proc/scsi/scsi should list the new device.
Please keep in mind that the SCSI bus is not hotpluggable - the device must already be present in the SCSI chain, it just does not matter if it was switched on.
If you use Linux in a network, you will probably use NFS to mount remote directories. Timing problems may occur if the NFS server is not available at the NFS client's boot time, or if the server goes offline while the client is still connected. To allow "soft" mounts in /etc/fstab, simply add the options bg,hard,intr. See the manpage to mount for details.
If ever you happen to come across a corrupt filesystem (e.g. you installed a new harddisk, but forgot to update /etc/fstab and now one of your partitions became a swap partition ;-), the program e2fsck if of use.
However, upon running e2fsck /dev/hdX you may run into trouble if the superblock is defective. In this case, you may specify an alternative (backup) superblock, e.g. e2fsck -b 8192 /dev/hdX.
To find out where these backup copies are stored, just run mke2fs -n /dev/hdX ... this command causes mke2fs to display what it would do if it were to create a filesystem, but without actually doing it. In other words, it shows the location of the backup copies of the superblock! All you need to do then is to re-run e2fsck with the -b option and an appropriate superblock location.
The key to using a Linux PC in a Microsoft Windows Network is the samba protocol. To gain access to the ressources of the NT network, you only need the samba-client package: The "full" samba-package contains also the server, but is only required if the Linux machine is to provide services towards the MS-Windows domain.
The configuration file /etc/samba/smb.conf must provide at least the following entries in the [global] section:
workgroup = NAME_OF_THE_WINDOWS_DOMAIN
encrypt passwords = Yes
update encrypted = Yes
Now, to mount the NT/w2k "network drive" //server/directory, issue the following command as root:
mount -t smbfs -o username=XXX //server/directory /mnt/smb
... where XXX is your Windows username (btw, this option is not required if you are logged with the same name under Linux). You will be asked the corresponding password for your Windows logon; enter it and access should be granted. - Note that you can also give the password on the command line, however, this is unsecure: it could reveal your password to others that access the "history" function.
On recent Linux distributions, mount.smbfs is being replaced by mount.cifs; CIFS stands for Common Internet File System and is the successor to the SMB protocol. The syntax of the command stays the same, but you may need to use of the server's IP adresses instead of its name:
mount -t cifs //ip.of.server/directory /mnt/smb/
If you want to use samba to access a directory on a Windows machine without using your "personal" WinNT domain account (e.g. to have a backup daemon watch a directory, without the need to enter the password every time you reboot that Windows box), proceed as follows (Note: this procedure is essentially identical for a computer running MS Windows 2000, but the entries are in slightly different locations.):
On the WinNT computer, create a new local user:
Still on the WinNT machine, adjust the share:
On the Linux machine, we do not want the username/password to appear in clear text. Thus, create a file (e.g. /root/access.win) that holds the credentials and that is only readable to root. The file is very simple:
username = xxxxx password = yyyyy
Now you can use the following mount command:
mount -t smbfs -o workgroup=PC12345,credentials=/root/access.win //PC12345/toarchive /mnt/smb
If you want this to be done automatically in /etc/fstab, use:
//PC12345/toarchive /mnt/smb smbfs workgroup=PC12345,credentials=/root/access.win 0 0
Samba comes with lots of well written documentation; use it!
If you work within a Windows NT domain, you will want to avoid that Linux "takes over" if the NT domain controller is rebooted. Thus, if you run a Samba server in the network, set the following parameters in the [global] section of the configuration file /etc/samba/smb.conf :
workgroup = NAME_OF_THE_WINDOWS_DOMAIN
encrypt passwords = Yes
update encrypted = Yes
domain master = no
local master = no
preferred master = no
os level = 0
domain logon = no
Restart SAMBA with /etc/rc.d/smb restart.
If you have a printer that is connected locally to your Linux box and you want to share it within a Windows NT/2000 network, the entries in your /etc/samba/smb.conf might look as above, plus a few more entries related to the printer:
[global]
...
guest account = Nobody
map to guest = Bad User
printing = bsd
printcap name = /etc/printcap
# "load printers = yes" is only required if you want to browse
# ALL printers on this system. In my case, I make only ONE printer
# available (definition at the end of this file).
; load printers = yes
[hp2200d]
comment = HP2200d Duplex PS
path = /tmp
guest ok = yes
writable = no
printable = Yes
printer = lp3
browseable = yes
I had a lot of trouble getting my printers to work with MS Windows 2000. I finally found that the problem was (very probably) due to the fact that the spool directory var/spool/samba had not the correct access rights; since I changed it to /tmp everything works fine.
Using the configuration above in a Windows 2000 network, the Control Panel still shows the printer with "Access denied, unable to connect" ... but everything works fine, apparently even bidirectional printing and spooling.
Blank sheet after print job from MS-Windows. The printer queue "lp3" above is configured to print in RAW mode, so that all output from the MS-Windows printer driver is fed directly to the printer. However, I encountered the problem that I always got an extra blank page when a printjob was sent from MS-Windows, while printing directly from Linux always worked without that extra page. The solution was simply to remove the entry for the printer filter (e.g., apsfilter) from the corresponding entry in /etc/printcap ... a "raw" queue does not need a filter anyway ;-)
Kppp is a ppp dialer for for the K Desktop Environment. A nice feature of kppp is that it enables accounting of phone costs, using rule sets. A few hints:
Download the kppp ruleset for sunrise
"pay as you surf" (probably outdated).
Download the kppp ruleset for Swisscom
(probably outdated).
There are many tricks and recipes circulating about speeding up a given system. Here are a few that I experienced myself:
/dev/sda5 swap swap pri=42 0 0 /dev/hda2 swap swap pri=42 0 0
If you use HylaFAX, just type:
sendfax -n -D -s a4 -d 021xxxxxx /path/to/file.ps
... where -n means "no coversheet", -D mail notification to user upon delivery, -s specifies the paper size (here, a4), and -d is followed by the destination number.
HylaFAX sometimes hangs, and in /var/spool/fax/status you can find a status message telling "waiting for modem to come ready". In such a case, with an outgoing fax in the queue, try the command faxmodem /dev/modem (indeed, this command should be in the script that launches the HylaFax server).
If you use a small system such as a portable computer and send faxes only occasionally, have a look at efax. This is a small but powerful package e.g. for use with a laptop, which requires only a few kilobytes of disk space and can be configured easily. Usage is very simple: to send a fax, just type
fax send 021xxxxxx /path/to/file.ps
If you need to receive a fax, use fax receive. You can even set this software up as a "fax printer" queue ... see the manpage for details.
If you want to remove the cover page from a document you received (e.g. a fax):
convert -verbose -page A4 -compress Zip multipagefax.tif[1-4] fax.pdf
If you have a multi-page pdf file that you would like to OCR, you can split it into individual TIFF files:
pdftopbm -r 220 mytxt.pdf mytxt for i in mytxt-0* ; do convert -verbose $i `echo $i|sed 's/pbm/tif/g;s/000//g'` ; done
You certainly know this problem: Somewhere in your directory tree is a file, but all you remember is that is contains the words "what text". To find this file, just issue the following command:
find . -type f -print | xargs grep -li "what text"
The find command finds all "normal" files and feeds a list of them to the pipe. xargs takes the piped list and makes it into an argument list for grep. The -i option makes grep ignore case, and -l is used to output a list of unique filenames which match.
(Inspired by a tip found at www.linuxplanet.com).
If you need to replace a certain text in a file, you could use an editor to do this. If you need to do this more than a few times per file, or in a large number of files, you will probably prefer an automatic processing. The script replace.sh performs this task - I wrote it as a kind of "exercise in shell scripting" ;-)
Click here to download the replace.sh script.
Note: Of course there are many other ways to perform such a task. As an example, the following one-liner should do the same: perl -e 's/old text/new text/gi' -p -i.bak *.html
I often have to deal with files that contain spaces in the filename, such as "My File". Although Linux can deal with such names, I prefer to rename them so that the names do not contain any whitespace nor other special characters. The following one-liner (in bash) replaces the space character by underscore, so My File becomes My_File:
for i in *\ *; do mv "$i" "`echo $i | sed 's/ /_/g'`"; done
While we are at it, let's transcribe all uppercase characters to lowercase (My File becomes my_file):
for x in *; do mv "$x" `echo $x | tr "A-Z " "a-z_"`; done;
Applying this through a whole directory structure, with all files and directories, starting at the current working directory, with find:
find . -exec bash -c 'mv "$1" "`echo $1 | tr "A-Z " "a-z_"`"' {} {} \;
This pattern-matching is not fully "bullet-proof", but it works for me, both under tcsh and bash.
Here is another one, but this time I want to convert the first letter of each 'word' to uppercase (so that 01-my_song.ogg becomes 01-My_Song.ogg. I use this e.g. to convert the filenames of encoded audio files:
for i in *.mp3; do mv "$i" "`echo $i | sed 's/\([-_]\)\(.\)/\1\u\2/g'`"; done
The usual archive format in the Linux world is the compressed tar archive, .tar.gz or .tgz. Most Archive utilities in the "Windows world" can handle these archives. However, you can easily create "zip" files that are fully compatible with WinZip, PowerArchiver etc. To archive a directory full of directories with data files (say, *.raw), run in tcsh:
foreach i (*.raw)
zip -rmT9v $i.zip $i
end
Option -r travels recursively, -m removes the original files after verification with -T, -9 is the highest compression level, and -v is verbose mode.
In contrast to WinZip, this runs nicely from the command line and can work on a sequence of files without efforts. Just make sure not to invert the position of the zip file and of the data-to-be-archived ;-)
For various projects that I have been working on, I needed to generate sets of random numbers where every number appears exactly once ... quite similar to drawing cards from a deck of cards.
The Perl script below is called as ./randomseq.pl min max. It will print all integers from min to max in random order.
If you need to copy a file (or a directory) to a remote computer, scp is a secure replacement for rsh. The syntax is somewhat unusual but nevertheless straightforward:
To find out what software is driving a certain webserver, do a telnet to port 80. Enter HEAD / HTTP/1.0 and hit <enter> twice.
If you are using xdm as display manager, you may define a background image in /etc/X11/xdm/Xsetup ... e.g. with a line like background=/root/graphics/tux.xpm.gz.
The xdm configuration is defined in /etc/X11/xdm/xdm-config. Note that ~/.xsession contains the X server launch instructions if the login is done in X mode, while ~/.xinitrd contains the setup if the login is done in text mode, and X is then launched manually with startx.
Usually you start one X Server that is running on virtual console 7. What if you want to have two X Servers? No problem:
startx -- :0 & startx -- :1 &
The -- is used by startx and xinit to separate an optional set of client parameters from the set of display/server options and parameters.
startx windowmaker -- :1 &
starts XWindows on virtual console 8 and runs windowmanager. Note that you should be logged in before doing so, and that starting the same window manager twice from the same user account may confuse the configuration files ...
For more information, see the manpages to startx and xinit.