Kalle Hoffman


Fun Stuff
Indian Chief Projects
Saunas (FAQ)

Contact Me

Kalle Hoffman's Engineering Notes

$Revision: 1.61 $

Ok, I'm sick and tired of looking up these questions in my engineering notebook over and over so I have put them on the web. Now I don't need to search for them anymore and maybe they'll be useful to you too. If these notes are outdated or if you have notes you'll like to contribute feel free to contact me.

Table Of Contents

What are the most useful rpm command
Wed Feb 24 15:00:34 PST 2016

    git clone user@repo check out a repo
    git add .
    git commit .
    git push
    push your change back to the repo
    git checkout FILENAME
    revert the content of a file
    git checkout -b BRANCHNAME
    git push origin BRANCHNAME
    Create a new branch
    git checkout -b BRANCHNAME
    git pull origin BRANCHNAME
    Switch to another branch

How do I share a Linux screen session?
Tue Dec 17 17:43:56 PST 2013

    session1# chmod 777 `tty`
    session1# sudo su - user
    session1# screen
    session2# sudo su - user
    session2# screen -ls
              There is a screen on:
                      19787.ttyp6.deeptht     (Attached)
              1 Socket in /tmp/screens/S-kalle/.
    session2# screen -x

What are the most useful rpm command
Fri Feb 18 13:44:06 PST 2011

    rpm -qa    list installed rpms
    rpm -qlp file    list the files in an rpm
    rpm -qRp file    list an rpm dependencies
    rpm -qlp file    list the files in an rpm
    rpm -qip file    report the rpm info
    rpm -qf  file    report the rpm that owns a file
    rpm -i   file    install an rpm

Where can I download putty?
Wed Mar 11 17:57:20 PDT 2009

How do connect to a server via ssh without typing a password. (useful for rsync and cvs)
Fri Jul 28 12:04:02 2000

    If you are going to run cvs on a machine other than the server, you'll need to configure ssh. The following will allow you to run remote commands on a client without being prompted for a password. When prompted for a key from ssh-keygen just hit enter. Execute the following commands on the server and client in your home directory:
    server# mkdir $HOME/.ssh
    server# chmod 755 $HOME $HOME/.ssh
    server# ssh-keygen -t dsa
    server# mv $HOME/.ssh/id_dsa.pub $HOME/.ssh/authorized_keys
    server# chmod 644 $HOME/.ssh/authorized_keys
    server# scp -r $HOME/.ssh client:.
    server# ssh client chmod 755 . .ssh

How do I set up more then one machine to an adsl connection. How do I set up a gateway at home with an old 486 pc and Red Hat Linux 5.2.
Fri Aug 6 13:10:39 1999

    With DSL being so cheap ($50/month), my housemates and myself decided to drop our dial up isps and get a dsl line. Since we only get one IP address at this rate we set up an old 486/66, 16 mb memory and a 400 mb hard drive to act as a firewall at our place. There are tons of referances on the web, Here's a few you can read:

    Here's what I did:
    • I sent email to a list of friends and asked them to give me an old computer.
        Subject: computer, paper weight, door stopper
        To: <list of friends>
        Date: Fri, 9 Jul 1999 11:50:34 -0700 (PDT)
        From: Kalle Hoffman 
        Do you have an old pc I can have? I need to set up a gateway at my
        place. I'm willing to fill in the blanks or buy stuff to bring it up to
        what I need.
                i386+ Intel architecture
                16+ mb memory
                400+ mb hard drive
                2 ethernet cards 10 based t
    • After getting a free 486 from my friend I opened up the box and figured out what hardware the box had and made the following table.
        unit            irq     addr    dma
        ====            ===     ====    ===
        vga             2
        tty01 (com2)    3       2f8
        ethr0           3       300
        tty00 (com1)    4       3f8
        lpt1            5       378
        floppy          6       3f2-3f7 2
        _______         7
        smc/wdn         9       240-25f
        _______         8
        ethr1           10      2c0
        audio           11      344
        ps2_mouse       12   
        fpu             13
        ide             14      1f0-1f7
        _______         15
        lpt2                    278
    • I checked the Redhat Linux 5.2 hardware compatibility list and took out everything that wasn't on the list.
    • I bought two ne2000 compatible 10 based t ethernet cards ($7 each) and installed them using addr=0x300 irq=3 on the first and addr=0x2c0 irq=10 on the second. Pac bell will give a ethernet card but it may not be compatible with linux. I found it was easier to just buy two I knew were compatible. The ethernet cards I bought are plug and play but my pc wasn't so I had to use the dos utilities that came with the cards to change the settings on the second card. Since I was using two of the same cards I only had one installed when I ran the utility.
    • Then I installed Redhat Linux 5.2 on the box. When I was asked what packages to install i selected "everything".
    • After installing Linux I logged on as root and configured the ethernet cards by creating the following files.

          alias eth0 ne 
          alias eth1 ne
          options ne io=0x300,0x2C0
    • Then I set up the name server by adding the following to /etc/named.conf and creating /var/named/fiftynine.com.

          zone "fiftynine.com" {
          	type master;
          	file "named.fiftynine.com";
          @       IN      SOA     oak.fiftynine.com. (
                                  1D )            
                          TXT     "fiftynine.com"
                          NS      oak.fiftynine.com.
                          MX      10 mail         
          localhost       A
          oak             A
                          MX      10
          mail            CNAME   oak
          www             CNAME   oak
          mail            CNAME   oak
          ftp             CNAME   oak
          ; local network
          oak-local       A    
          fell            A    
          page            A    
    • Finally RedHat 5.2 comes with ip forwarding turn off. I added the following to my /etc/rc.d/rc.local to turn on masquerading and ip forwarding.

          # enable ip forwarding
          echo 1 > /proc/sys/net/ipv4/ip_forward
          # enable 
          /sbin/depmod -a
          /sbin/modprobe ip_masq_ftp
          /sbin/modprobe ip_masq_raudio
          /sbin/modprobe ip_masq_irc
          /sbin/modprobe ip_masq_quake
          # Permit IP masquerading for the 192.168.90.- network
          /sbin/ipfwadm -F -p deny 
          /sbin/ipfwadm -F -a m -S -D -W eth0
    • As for the network inside our house I bought a 10 base t 8 port hub ($55), 250 feet of cat5 cable, rj-45 crimper, and a bunch of rj-45 ends.

      • Here's the topology of my network.
                   /        \
                  | PAC BELL |
                       |                              +---------------+
                       |                  +-----------| ( |
              +------------------+        |           +---------------+
              | adsl cable modem |        |
              +------------------+        |           +---------------+
                       |                  |+----------| ( |
                       |                  ||          +---------------+
          +----------------------------+  ||
          |   oak     (  |  ||          +---------------+
          +----------------------------+  ||+---------| ( |
          |                            |  |||         +---------------+
          |            CPU             |  |||     
          |                            |  |||         +---------------+
          +----------------------------+  |||+--------| ( |
          |   oak-local(  |  ||||        +---------------+
          +----------------------------+  ||||     
                       |                  ||||        +---------------+
             +-----+   |                  ||||+-------| ( |
             |     |---+                  |||||       +---------------+
             |     |----------------------+||||   
             |     |-----------------------+|||       +---------------+
             |     |------------------------+||+------| ( |
             | hub |-------------------------+||      +---------------+
             |     |--------------------------+|            
             |     |---------------------------+      +---------------+
             |     |----------------------------------| ( |
             +-----+                                  +---------------+
      • Here's the order of the wires when they go into the rj-45 plug. Only four wires are actually used.
    • Next I configured all of the machines on my local network.
        Domain Name:	fiftynine.com
        DNS server:
        Net mask:
        Ip Addresses:

    • Lastly I rebooted my box and started surfing. Thats it!

How do I clone an OS disk on Solaris?
Mon Sep 22 20:26:30 1997

    Hey Kalle,

    Here's disk cloning in a nuthsell. I normally use it when I want to clone an OS disk, to save me the labor of patching it. If you're not going to boot off it, you can skip the installboot command. Of course, you'll want both drives on the same machine with different SCSI IDs. Copying the disk the system is booted off of is no problem. The relative drive sizes aren't that important, as long as the destination drive can hold all the data on the source. For example, if you have 200M of data on a 4.3G drive, it'll safely clone to a 480M drive.

    First, format the drive as necessary. So, put /, swap, backup and /usr partitions on t1. Write the lables to thie disk, and newfs the data partitions (/ and /usr here). If the partitions are over 1G, you might want to change the minfree of the newfs. I think keeping over 100M free on a drive is silly. it's the -m option of newfs, which defaults to 10.

    For this example, I'm going to clone a boot disk on c0t3d0s0 with a /usr partition on c0t3d0s6 onto the disk on c0t1d0s*.
      # newfs /dev/rdsk/c0t1d0s0 -m 5
      # newfs /dev/rdsk/c0t1d0s6
    Now, mount the destination partition
      # mount /dev/dsk/c0t1d0s0 /mnt
    Get creative with ufsdump/restore
      # ufsdump 0f - /dev/rdsk/c0t3d0s0 | (cd /mnt;ufsrestore rf -)
    Make the new root disk bootable
      # installboot /usr/platform/`uname -m`/lib/fs/ufs/bootblk /dev/rdsk/c0t1d0s0
    Repeat for different partitions
      # mount/dev/dsk/c0t1d0s6 /mnt/usr
      # ufsdump 0f /dev/rdsk/c0t3d0s6 | (cd /mnt/usr;ufsrestore rf -)
    You can see this would lend itself to scripting. It's also fairly easy to clone one disk onto several targets. It's not fast, it's not normally pretty, but when you don't want to send disgusting amounts of data over a network, it's useful. If you want to go from a drive with few partitions (say, / and swap) to a same-size or smaller disk with many partitions, this process will sometimes overfill the / partition. Extensive taring can get around that. Most people move to bigger disks anyway.


    Sam Rafter

How do I configure sendmail to add my domain to my return add ress Solaris 2.5.1?
Fri Sep 19 13:48:47 1997

    Lots of questions are answered in the Sendmail FAQ. One way to solve this problem is to copy /etc/mail/subsidiary.cf to /etc/mail/sendmail.cf and then make the following changes to /etc/mail/sendmail.cf.
    NOTE: the whitespace in the rule set MUST be tabs.
      R$*<@$+>$*	$@$1<@$2>$3		already ok
      R$=D		$@$1<@$w>		tack on my hostname
      R$+		$@$1<@kalle.com>	tack on my domain

How do I set up majordomo on Solaris 2.5.1?
Thu Sep 4 15:21:48 1997

    The majordomo FAQ is a good place to start. You'll need a C compiler and perl on the system your installing majordomo on. Then get sources for majordomo and put them in /tmp.

    Majordomo comes with rather extensive INSTALL and NEWLIST files. You should read these files completely. Then run the following commands as root:
      # useradd -c "majordomo" -d /usr/local/majordomo -g 12 \
      	-m -u 100 -s /usr/bin/csh majordomo
      # passwd majordomo
    Run the following commands to extract the majordomo source a the majordomo user.
      % cd /tmp
      % gunzip -c majordomo-1.94.4.tar.gz | tar -xvf -
      % cd majordomo-1.94.4
    Modify the following macros in /tmp/majordomo-1.94.4/Makefile:
      PERL = /opt/LWperl/bin/perl
      CC = /opt/SUNWspro/SC4.0/bin/cc
      W_HOME = /usr/local/majordomo
      W_USER = 100
      W_GROUP = 12
    Run the following commands as the majordomo user to install the majordomo software.
      % cd /tmp/majordomo-1.94.4
      % /usr/ccs/bin/make wrapper
      % /usr/ccs/bin/make install
      % su root -c "/usr/ccs/bin/make install-wrapper"
      % cd /usr/local/majordomo
      % cp sample.cf majordomo.cf
    Modify the following variables in /usr/local/majordomo/majordomo.cf:
      $whereami = "kalle.com";
      $homedir = "/usr/local/majordomo";
    Add the following lines to /etc/aliases:
      # majordomo mail aliases
      majordomo:          "|/usr/local/majordomo/wrapper majordomo"
      owner-majordomo:    kalle@kalle.com
      majordomo-owner:    kalle@kalle.com
      test-list:          :include:/usr/local/majordomo/lists/test
      owner-test:         kalle@kalle.com
      test-owner:         kalle@kalle.com
      test-request:       "|/usr/local/majordomo/wrapper majordomo -l test"
      test-approval:      kalle@kalle.com
    Run the following configuration test script as a regular, unprivileged user (not the majordomo user or root).
      % cd /usr/local/majordomo
      % ./wrapper config-test
    Run the following commands as majordomo to create a test list. The info file should have some useful information for the first time user of the list.
      % touch /usr/local/majordomo/lists/test
      % touch /usr/local/majordomo/lists/test.info
      % chmod 664 /usr/local/majordomo/lists/*
    Test the configuration:
      % echo 'lists' | mail majordomo

How do I set up the automounter on Solaris 2.5?
Mon Aug 11 14:22:12 1997

    You'll need to add the file /etc/auto_direct and update /etc/auto_master and /etc/auto_home. Sam Rafter comments that you'd prob'ly want to mount the directorys soft, or mount it with a low number of retries. If you mount it hard, and the system can't be reached, the machine won't finish loading the OS.
    Here's an example of the configuration files I've used in the past:

        /home1 rw,soft abbott:/export/home1
        kalle   abbott:/export/home/&
        /net            -hosts          -nosuid
        /home           auto_home
        /xfn            -xfn
        /-              auto_direct
    Once the system files are set up restart the automounter with the following commands:
      # /etc/rc2.d/S74autofs stop
      # /etc/rc2.d/S74autofs start

What does big-endian and little-endian mean?
Thu Aug 7 16:23:32 1997

    The terms big-endian and little -endian come from Swift's `Gulliver's Travels' where big-endian refered to opening an egg at the big end and little-endian refered to opening an egg at the little end. The "endianness" of a computer's CPU is determined by how multi-byte data structures are stored. The paper by Danny Cohen that popularized these terms in connection with the LSB-first/MSB-first controversy was entitled "On Holy Wars and a Plea for Peace".

    Here's a table to help you determine the endianness of your system.

    CPU Endianness

    Here's a simple runtime check for endianness of your machine.
              int i=0;
              ((char *)(&i))[0] = 1;
              return i == 1;
    Here's the source to a generic endian swapper.
      #define ENDIAN_SWAP(a)  endian_swap(&(a), sizeof(a))
      endian_swap(void *v, int size)
              int i;
              unsigned char *p = (unsigned char *) v, q;
              for(i=0; i<size/2; i++) {
                      q = p[i];
                      p[i] = p[(size-1)-i];
                      p[(size-1)-i] = q;

What is a simple program to controls screen movements?
Aug 1 11:15:14 1997

    The curses library routines give the user a terminal-independent method of updating character screens with reasonable optimization. Here's a trivial example of a C program that uses the curses library.
      % cc -o test test.c -lcurses -ltermcap
      % cat test.c
      *** test: Uses the curses library to move a curser on the screen.
      ***       Kalle Hoffman
      ***       (831) 458-0685
      ***       Aug  1 11:15:14 1997
      ***       www.kalle.com
      ***       kalle@kalle.com
      #include <curses.h>
      main() {
              int col=0, line=0, c=0;
              initscr(); cbreak(); noecho();  /* init curses and screen */
              do {
                      mvprintw(line, col, "     "); /* clear old curser */
                      switch (c) {
                              case 'k': line--; break;            /* up */
                              case 'j': line++; break;          /* down */
                              case 'h': col--; break;           /* left */
                              case 'l': col++; break;          /* right */
                      mvprintw(line, col, "%02d,%02d", line, col);
              } while ((c=getch()) != 'q');
              move(LINES-1, 0);    /* leave curser in lower left corner */
              return 0;

How do I copy a directory while preserving links, owner id, group id and timestamps?
Mon Jul 7 12:04:42 1997

    The GNU copy command (cp) supports the -a (archive) option which preserves as much as possible of the structure and attributes of the original files in the copy. This includes: copying symbolic links as symbolic links rather than copying the files that they point to, preserving hard link relationships between source files in the copies, preserving the original files' owner, group, permissions, and timestamps, and copying directories recursively (copying all nondirectories as if they were regular files).
      % cp -a SRC_DIR DEST_DIR
    The Solaris 2.5 copy command (cp) supports the -p option which preserves the owner id and group id, permissions modes, modification, access time, and ACLs if applicable. WARNING: This command won't copy links as links it copies the information the link points to.
      % cp -rp SRC_DIR DEST_DIR
    Another way to preserve file information and soft links when copying is by using tar.
      % mkdir DEST_DIR
      % cd SRC_DIR
      % tar -cf - . | ( cd DEST_DIR; tar -xvf - )
    I have written a shell script (tarcp.sh) that acts like cp but uses tar to copy directories. You can get a copy at: ftp://ftp.kalle.com/pub/tarcp.sh

How do I pass a variable number of arguments in c?
Wed Jul 2 18:43:23 1997

    #include <stdio.h>
    #include <stdarg.h>
    my_printf(char *format, ...)
            va_list ap;
            va_start(ap, format);
            vprintf(format, ap);

How do I add swap space (increase /tmp) on Solaris 2.5.1?
Wed Jul 2 18:13:04 1997

    First you'll need to allocate disk space (200 megabytes) on a local disk (/export/home) and create a swap file (/export/home/SWAP).
      # mkfile 200m /export/home/SWAP
    Then tell the memory manager about the new swap space.
      # swap -a /export/home/SWAP
    Last so the new swap space will be used the next time the system is rebooted update /etc/vfstab. Make sure the new swap entry comes after the disk it's allocated on.
        #device           device             mount         FS    fsck  mount    mount
        #to mount         to fsck            point         type  pass  at boot  options
        #========         =======           ======         ====  ====  =======  =======
        fd                -                  /dev/fd       fd     -    no       -
        /proc             -                  /proc         proc   -    no       -
        /dev/dsk/c1d0s1   -                  -             swap   -    no       -
        /dev/dsk/c1d0s0   /dev/rdsk/c1d0s0   /             ufs    1    no       -
        /dev/dsk/c1d0s6   /dev/rdsk/c1d0s6   /usr          ufs    1    no       -
        /dev/dsk/c1d0s7   /dev/rdsk/c1d0s7   /export/home  ufs    2    yes      -
        swap              -                  /tmp          tmpfs  -    yes      -
        /export/home/SWAP -                  -             swap   -    no       -

Where are the most useful search engines on the net?
Thu Jun 5 10:35:25 1997

Where can I get precompiled utilities like gcc, tcsh, and elm for Solaris 2.5 sparc and x86?
Thu Apr 22 15:22:38 1999

How do I get a Solaris 2.5.1 box to revert to a "blank" system?
Thu Jun 5 10:16:17 1997

    The way you can make a machine not have a name or know about other systems or networks is with sys-unconfig. Sam Rafter adds that a problem with sys-unconfig is that it removes the root password and if the machine was built from a server (as opposed to CDROM), it doesn't unconfig properly.
      # sys-unconfig

How do I configure a Solaris 2.5.1 box to talk to a network?
Thu Jun 5 10:36:41 1997

    First see blanking your system. Then you'll need to put the IP address of your systems default router or Gateway in /etc/defaultrouter. Put the domain name and DSN name servers IP address in /etc/resolv.conf. And you'll need to add dns to the hosts line of /etc/nsswitch.conf. Here's an example of files on a solaris 2.5.1 x86 box on a network of NT machines.
        domain kalle.com
        passwd:         files
        group:          files
        hosts:          dns files
        networks:       files
        protocols:      files
        rpc:            files
        ethers:         files
        netmasks:       files	
        bootparams:     files
        publickey:      files
        netgroup:       files
        automount:      files
        aliases:        files
        services:       files
        sendmailvars:   files

How do I set up a trash directory so I can unremove files on UNIX using csh?
Thu Jun 5 10:56:58 1997

    Set up these aliases in your .cshrc and do the mkdir once.
      % mkdir ~/.trash
      % alias urm   "mv ~/.trash/\!* ."
      % alias rm    "mv -f \!* ~/.trash"
      % alias check "ls ~/.trash; du -s ~/.trash"
      % alias empty "/bin/rm -fr ~/.trash/{,.}*"

What can't I ftp to a Solaris 2.5.1 box when my login shell is tcsh?
Thu Jun 5 11:11:56 1997

    The solaris ftp daemon (in.ftpd) authenticates users according to the following rules:
    • The user name must be in the password data base, /etc/passwd.
    • The user name must have a password that is not null.
    • If the user name appears in the file /etc/ftpusers, ftp access is denied.
    • Ftp access is denied if the user's shell (from /etc/passwd) is not listed in the file /etc/shells. If the file /etc/shells does not exist, then the user's shell must be one of the following:
        /usr/bin/sh  /usr/bin/csh /usr/bin/ksh /usr/bin/jsh
        /bin/sh      /bin/csh     /bin/ksh     /bin/jsh
        /sbin/sh     /sbin/jsh
    • If the user name is "anonymous" or "ftp", an entry for the user name ftp must be present in the password and shadow files. The user is then allowed to log in by specifying any password

How do I get a new disk formatted, mounted, and exported on a Solaris 2.5.1 box?
Thu Jun 5 11:19:04 1997

    Turn your machine off and install the disk. In order to get Solaris to reconfigure your new hardware configuration you'll need to boot Solaris with the reconfigure option at the boot prompt. Some people like to do this operation in single user mode, you can do this by using the -s option.
      # b -r
    When the machine boots login as root and run the format command to partition the new device.
      # /etc/format
      format> fdisk
      format> label
      format> partition
      format> quit
    Now run newfs on the raw device. Here's an example of a disk on scsi controller 0, target 1, slice 0.
      # /usr/sbin/newfs /dev/dsk/c0t1d0s0
    Now edit the /etc/vfstab file so that the device will mount at boot time.
        #device           device             mount         FS    fsck  mount    mount
        #to mount         to fsck            point         type  pass  at boot  options
        #========         =======           ======         ====  ====  =======  =======
        fd                -                  /dev/fd       fd     -    no       -
        /proc             -                  /proc         proc   -    no       -
        /dev/dsk/c1d0s1   -                  -             swap   -    no       -
        /dev/dsk/c1d0s0   /dev/rdsk/c1d0s0   /             ufs    1    no       -
        /dev/dsk/c1d0s6   /dev/rdsk/c1d0s6   /usr          ufs    1    no       -
        /dev/dsk/c1d0s7   /dev/rdsk/c1d0s7   /export/home  ufs    2    yes      -
        swap              -                  /tmp          tmpfs  -    yes      -
        /dev/dsk/c0t1d0s0 /dev/rdsk/c0t1d0s0 /export/home1 ufs    2    yes      -
    If you want the device exported put the following in the dfstab file.
        share -F nfs /export/home1
    Now reboot the machine and the device will be mounted when you login.
      # sync; sync; sync;
      # reboot

How do I share file systems without rebooting on Solaris 2.5?
Tue Feb 27 16:44:26 1996

    It turns out that if /etc/dfs/dfstab is empty, nfsd and mountd are not started at boot time, so any share commands will not take effect. If you want to access files from a system that is not currently exporting any filesystems, you will have to explicitly start the nfs and mount daemons. Then the share command will make /export/home available for mounting by other machines.
      # /usr/lib/nfs/nfsd -a 16
      # /usr/lib/nfs/mountd
      # share -F nfs /export/home

Copyright © 1995-2009 Kalle Hoffman - All Rights Reserved.