Unix and Linux tips.

 

 

os version

 

uname -a or uname -X (see man uname)

 

ubuntu linux

dash

Ubuntu has symlinked /bin/sh to /bin/dash.

dash is a Debian derived light version of bash.

It often breaks scripts that expect the bash shell.

 

fix:-

sudo rm -f /bin/sh

sudo ln -s /bin/bash /bin/sh

 

linux packages

list packages

dpkg --get-selections

install packages

apt-get <package>

 

Desktops

kde

default desktop is ~/Desktop

 

In a network environment when using vnc, use /usr/bin/kcontrol to change

the path to allow different desktops for different machines/os versions.

e.g. ~/.kdevnc_linux1/Desktop

 

X11

 

set screen saver timeout

xset s 3600 1800

 

xterm

 

changing the xterm title dynamically:-

printf "\033]2; <ttile> \a"

 

add this line to .cshrc to display <hostname>:<cwd>:-

alias cwdcmd printf '"\033]2;${HOST}:$cwd\a"'

see also 'man tcsh'

 

script

To send terminal/xterm output to a log file (typescript):-

unsetenv SHELL

script

 

sort functions (symbols) in map file in size order (using disassember)

 

~johns/diss/d68/d68 -s dyson.x.map -t > dyson.x.map.size

sort -n -k 3,3 dyson.x.map.size > dyson.x.map.sorted

 

grep

 

recursive search using gnu grep:-

ggrep -H -n -i --colour -r <string> --include "*.c" --include "*.cc" *

 

or using find (with grep/fgrep/egrep/ggrep) :-

 

find . -name "*.c" | xargs grep -i -n <string>

or

find . -name "*.c" -exec grep -H -n "string" {} \;

 

find

 

find files modified les than 10 minutes ago...

find . -mmin -10

 

recursion script

recur <command>

 

ssh

 

run unix ssh server daemon

 

cd ~/openssh-3.5p1

sshserv

 

NOTE sshserv is a shell script file:-

#!/bin/csh

 

while(1)

  printf "sshd\n"

  sshd -d -p 1024

end

 

gnu

building & installing gnu software locally

 

cd <gnu source directory>

configure --prefix=$HOME

make install

 

This will install files under...

$HOME/lib

$HOME/bin

$HOME/include

 

openssh

 

build & install zlib compression libraries...

cd ~/zlib-1.1.4

configure --prefix=$HOME

make install

 

build & install OpenSSL encryption libraries...

cd ~/openssl-0.9.6g

identify os/compiler...

config

Configure --prefix=$HOME solaris-sparcv9-gcc

make install

 

build & install openssh...

cd ~/openssh-3.5p1

ensure configure finds the ssl include directory...

setenv CPPFLAGS -I/home/bak/include

 

NOTE - to run on a machine NOT connected to development network,

create a directory /home/bak and use in place of $HOME

setenv HOME /home/bak before running make

($HOME/etc is used to locate ssh_prng_cmds at runtime)

configure --prefix=$HOME --with-zlib=$HOME/lib --with-ssl-dir=$HOME/ssl --with-privsep-path=$HOME/var/empty

make install

 

Your identification has been saved in /home/bak/etc/ssh_host_key.

Your public key has been saved in /home/bak/etc/ssh_host_key.pub.

The key fingerprint is:

6c:44:22:5c:2c:bc:be:c3:cd:bb:92:e8:7b:86:58:e0 bak@fallon

Generating public/private dsa key pair.

Your identification has been saved in /home/bak/etc/ssh_host_dsa_key.

Your public key has been saved in /home/bak/etc/ssh_host_dsa_key.pub.

The key fingerprint is:

f8:36:cf:a1:4c:f2:56:47:2d:13:40:23:f3:58:ef:ba bak@fallon

Generating public/private rsa key pair.

Your identification has been saved in /home/bak/etc/ssh_host_rsa_key.

Your public key has been saved in /home/bak/etc/ssh_host_rsa_key.pub.

The key fingerprint is:

b6:b1:cb:1b:79:f3:92:3c:78:f9:d4:58:80:1e:be:96 bak@fallon

/home/bak/sbin/sshd -t -f /home/bak/etc/sshd_config

Privilege separation user sshd does not exist

 

scanssh

This will scan a range of IP addresses looking for ssh servers

build & install libpcap...

cd libpcap-0.7.1

configure --prefix=$HOME

make install

 

cd scanssh

configure --prefix=$HOME --with-libpcap=libpcap-0.7.1

make install

 

telnet-tls

This needs openssl to be built & installed first.

build & install openssl as described above.

(may need to copy ssl libraries into $HOME/ssl/lib

and ssl includes into $HOME/ssl/include/openssl).

 

There is a config problem with telnetd.c :-

The function inet_ntop() exists - hence HAVE_INET_NTOP is defined.

AF_INET6 is not defined. This gives a compilation error.

hence need to add:-

#if defined HAVE_INET_NTOP && defined INET6 to telnetd.c line 1090

 

configure --prefix=$HOME --with-openssl-dir=$HOME/ssl

make install

 

source navigator

 

There are problems with the -fwritable-strings parameter when attempting to build using later versions of gcc.

This parameter was used to get gcc to put constants in data space. It has been removed from gcc 4.0.

Source navigator has not been updated to reflect this change.

 

Need to remove the parameter from the following files...

snavigator/configure

snavigator/configure.in

libgui/configure

libgui/configure.in

tix/unix/tk8.1/Makefile.in

tix/unix/tk8.3/Makefile.in

 

gnu binutils

od

object file dump in byte hex format:-

od -Ax -tx1 <filename>

 

mail

reading mail on unix

mail        - compose or mail a document.

              startup file = $HOME/Mail.rc

Mail        - compose or mail a document.

              startup file = $HOME/Mail.rc

mailx       - compose or mail a document.

              startup file = $HOME/mailx.rc

              saved mailbox file = $HOME/mbox

mailtool    - OpenWindows interface for the mail program

xmh         - send and read mail with an X interface to MH

dtmail      - the CDE Mailer (CDE toolbar)

 

mailfile:-

MAIL = /var/mail/bak

 

netscape mail:-

~/nsmail/Inbox

 

email address formats

RFC821

also see unix 'man addresses'

 

omniEvents

 

event server daemon initialisation:-

/etc/init.d/omniorb-eventservice

 

include files:-

/usr/local/include/omniEvents.hh

/usr/local/include/omniEvents/*

 

omnithreads

 

include files:-

/usr/local/include/omnithread.h

/usr/local/include/omnithread/*

 

log4cpp

 

include files:-

/usr/local/include/log4cpp/*

 

C library functions

getopt

 

see man -s 3C getopt

 

~/.bashrc

 

export SHELL=/bin/bash

export LOCALHOME=/home/bak

 

export GREP_OPTIONS='--color=auto'

export GREP_COLOR='1;32'

export EDITOR=xemacs

 

alias ls='ls -sF --color=auto'

alias lsa='ls -sFA --color=auto'

alias ll='ls -lAg --color=auto'

alias cp='cp -i'

alias mv='mv -i'

alias rm='rm -i'

alias h=history

alias passwd=yppasswd

alias password=yppasswd

 

if [ -e $LOCALHOME/bin/grep ]; then

  alias grep=$LOCALHOME/bin/grep

fi

if [ -e $LOCALHOME/bin/fgrep ]; then

  alias fgrep=$LOCALHOME/bin/fgrep

fi

if [ -e $LOCALHOME/bin/egrep ]; then

  alias egrep=$LOCALHOME/bin/egrep

fi

if [ -e $LOCALHOME/bin/xemacs ]; then

  alias xemacs=$LOCALHOME/bin/xemacs

fi

if [ -e $LOCALHOME/bin/snavigator ]; then

  alias snavigator=$LOCALHOME/bin/snavigator

fi

 

# project specific

export PROJ='AMIS'

echo "PROJECT = $PROJ"

case "$PROJ" in

  NEWS)

    if [ -d /cel/proj/violet/sw/admin ]; then

      PATH=$PATH:/cel/proj/violet/sw/admin

    fi

    if [ -d /cel/proj/violet/bin ]; then

      PATH=$PATH:/cel/proj/violet/bin

    fi

    if [ -d ~violet/bin ]; then

      PATH=$PATH:~violet/bin

    fi

    alias ssb='cd $LOCALHOME/proj/news/builds/aug29/b8_auto_web_luxel_news/ssb/recorder'

    alias mknews='make bootable NEW_DIVERTER="yes" HIGH_CAPACITY_CASSETTE="yes"'

    alias mkhs='make bootable NEW_DIVERTER="yes"'

    ;;

  AMIS)

    alias am='cd $LOCALHOME/proj/amis'

    alias amb='cd $LOCALHOME/proj/amis/bin/intel.linux/debug'

    alias amm='cd $LOCALHOME/proj/amis/modules/intel.linux'

    alias ams='cd $LOCALHOME/proj/amis/solutions/intel.linux'

    ;;

  *)

    ;;

esac

 

~/.cshrc

 

#

# .cshrc

# (runs before .login)

# set ENVIRONMENT variables in .login

# set SHELL variables (inc path) here

#

 

if ($?prompt) then

# interactive shell - force tcsh

  if (! $?tcsh) then

    setenv SHELL /bin/tcsh

    exec $SHELL

  endif

endif

 

if (! ${?OSTYPE}) then

  if (`uname -n` == ecm2a) then

    setenv OSTYPE linux

  else

    setenv OSTYPE sunos

  endif

endif

 

#if (! ${?OSTYPE}) then

#  setenv OSTYPE sunos

#endif

 

setenv OPENWINHOME /usr/openwin

setenv LOCALHOME '/home/bak'

setenv PAGER '/usr/bin/less -s -e'

setenv MAIL /var/spool/mail/$USER

setenv GREP_OPTIONS '--color=auto'

setenv GREP_COLOR '1;32'

setenv EDITOR xemacs

 

setenv LD_LIBRARY_PATH

if (-d /usr/lib:$OPENWINHOME/lib) setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/usr/lib:$OPENWINHOME/lib

if (-d /apl/X11/R5/sparc/lib) setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/apl/X11/R5/sparc/lib

 

setenv XFILESEARCHPATH

if (-d /usr/openwin/lib) setenv XFILESEARCHPATH ${XFILESEARCHPATH}:/usr/openwin/lib/%T/%N%S

if (-d /apl/X11/R5/sparc/lib/X11/app-defaults) setenv XFILESEARCHPATH ${XFILESEARCHPATH}:/apl/X11/R5/sparc/lib/X11/app-defaults

 

umask 002

#umask 022

set filec

 

#if ( $shell == "/bin/tcsh" || $?tcsh ) then

#   set prompt = "{`whoami`}%S%m%s: "

#   set prompt2 = "> "

#else

#   set prompt="{`whoami`}[7m`uname -n`[0m% "

#   set prompt2 = "> "

#endif

 

#set prompt = "%S[%m]%s %/: "

#set ellipsis set prompt='%{^[]0;%n@%m, %.03, %P, CODE=%?^G%}%B%n%b@%m%B:%b%.02> '

 

alias ls 'ls -sF --color=auto'

alias lsa 'ls -sFA --color=auto'

alias ll 'ls -lAg --color=auto'

alias cp 'cp -i'

alias mv 'mv -i'

alias rm 'rm -i'

alias h history

alias passwd yppasswd

alias password yppasswd

 

#if ($OSTYPE != linux) then

#  alias xemacs ~bak/bin/xemacs

#  alias grep ~bak/bin/grep

#  alias fgrep ~bak/bin/fgrep

#  alias egrep ~bak/bin/egrep

#endif

 

if (-e $LOCALHOME/bin/grep) alias grep $LOCALHOME/bin/grep

if (-e $LOCALHOME/bin/fgrep) alias fgrep $LOCALHOME/bin/fgrep

if (-e $LOCALHOME/bin/egrep) alias egrep $LOCALHOME/bin/egrep

if (-e $LOCALHOME/bin/xemacs) alias xemacs $LOCALHOME/bin/xemacs

if (-e $LOCALHOME/bin/snavigator) alias snavigator $LOCALHOME/bin/snavigator

 

 

set history=100

 

# path

set path = (/bin /usr/bin /usr/sbin /etc /usr/etc /usr/ucb /usr/ccs/bin)

if (-d /usr/openwin/bin) set path = ($path /usr/openwin/bin)

if (-d /apl/X11/R5/sparc/bin) set path = ($path /apl/X11/R5/sparc/bin)

if (-d /apl/local) set path = ($path /apl/local)

if (-d /apl/bin) set path = ($path /apl/bin)

if (-d /apl/bin/rcs) set path = ($path /apl/bin/rcs)

if (-d ~/bin) set path = ($path ~/bin)

if (-d /cel/proj/embedded/bin) set path = ($path /cel/proj/embedded/bin)

if (-d /cel/proj/embedded/gcc/built/bin) set path = ($path /cel/proj/embedded/gcc/built/bin)

if (-d /cel/proj/embedded/gdb/built/bin) set path = ($path /cel/proj/embedded/gdb/built/bin)

set path = ($path .)

if (-d /usr/X11R6/bin) set path = ($path /usr/X11R6/bin)

if (-d $LOCALHOME/bin) set path = ($LOCALHOME/bin $path)

 

# manpath

setenv MANPATH '/usr/man'

if (-d /cel/swd/usr/bak/man) setenv MANPATH ${MANPATH}:/cel/swd/usr/bak/man

if (-d /home/bak/man) setenv MANPATH ${MANPATH}:/home/bak/man

if (-d /usr/dt/man) setenv MANPATH ${MANPATH}:/usr/dt/man

if (-d $OPENWINHOME/man) setenv MANPATH ${MANPATH}:/$OPENWINHOME/man

if (-d /apl/man) setenv MANPATH ${MANPATH}:/apl/man

if (-d /apl/X11/R5/sparc/man) setenv MANPATH ${MANPATH}:/apl/X11/R5/sparc/man

if (-d /apl/src/tcltk/sun4/man) setenv MANPATH ${MANPATH}:/apl/src/tcltk/sun4/man

if (-d /usr/share/man) setenv MANPATH ${MANPATH}:/usr/share/man

if (-d /usr/local/man) setenv MANPATH ${MANPATH}:/usr/local/man

if (-d /usr/X11R6/man) setenv MANPATH ${MANPATH}:/usr/X11R6/man

 

# project specific

setenv PROJ 'AMIS'

echo "PROJECT = $PROJ"

switch ($PROJ)

  case NEWS:

    if (-d /cel/proj/violet/sw/admin) set path = ($path /cel/proj/violet/sw/admin)

    if (-d /cel/proj/violet/bin) set path = ($path /cel/proj/violet/bin)

    if (-d ~violet/bin) set path = ($path ~violet/bin)

    alias ssb 'cd $LOCALHOME/proj/news/builds/aug29/b8_auto_web_luxel_news/ssb/recorder'

    alias mknews 'make bootable NEW_DIVERTER="yes" HIGH_CAPACITY_CASSETTE="yes"'

    alias mkhs 'make bootable NEW_DIVERTER="yes"'

    breaksw

  case AMIS:

    alias amb 'cd $LOCALHOME/proj/amis/bin/intel.linux/debug'

    alias amm 'cd $LOCALHOME/proj/amis/modules/intel.linux'

    alias ams 'cd $LOCALHOME/proj/amis/solutions/intel.linux'

endsw

 

#if (${?DISPLAY}) then

#  if (`echo $DISPLAY | awk '{print index($0,"localhost")}'` == 0) then

#    if (-e ~/.xmodmap-`uname -n`) xmodmap ~/.xmodmap-`uname -n`

#  endif

#endif

 

if (${?VNCDESKTOP}) then

  if (-e ~/.xmodmap-`uname -n`) xmodmap ~/.xmodmap-`uname -n`

endif

 

 

~/.login

 

#

# .login

# (runs once only after .cshrc)

#

# set ENVIRONMENT variables in here

# set SHELL variables in .chsrc

#

 

##################################################

# setup dummy o/s name if not defined

#

 

if (! ${?OSTYPE}) then

  if (`uname -n` == ecm2a) then

#   ecm2 (ubuntu) doesn't set OSTYPE so force it to linux

    setenv OSTYPE linux

  else

    setenv OSTYPE sunos

  endif

endif

 

umask 002

 

 

if ($OSTYPE != linux) then

# CDE fix - no tset or stty allowed

  if ( ! ${?DT} ) then

     setenv TERM `tset -Q -q`

     if ($TERM == "vt100") stty erase ''

  endif

endif

 

#if ($?tcsh) then

#  setenv SHELL /bin/tcsh

#endif

 

setenv EDITOR lj9

#setenv EDITOR 'vi'

setenv PAGER '/usr/bin/less -s -e'

setenv OPENWINHOME /usr/openwin

setenv MAIL /var/spool/mail/$USER

setenv GREP_OPTIONS '--color=auto'

setenv GREP_COLOR '1;32'

 

setenv LD_LIBRARY_PATH

if (-d /usr/lib:$OPENWINHOME/lib) setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/usr/lib:$OPENWINHOME/lib

if (-d /apl/X11/R5/sparc/lib) setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/apl/X11/R5/sparc/lib

 

setenv XFILESEARCHPATH

if (-d /usr/openwin/lib) setenv XFILESEARCHPATH ${XFILESEARCHPATH}:/usr/openwin/lib/%T/%N%S

if (-d /apl/X11/R5/sparc/lib/X11/app-defaults) setenv XFILESEARCHPATH ${XFILESEARCHPATH}:/apl/X11/R5/sparc/lib/X11/app-defaults

 

# manpath

setenv MANPATH '/usr/man'

if (-d /cel/swd/usr/bak/man) setenv MANPATH ${MANPATH}:/cel/swd/usr/bak/man

if (-d /home/bak/man) setenv MANPATH ${MANPATH}:/home/bak/man

if (-d /usr/dt/man) setenv MANPATH ${MANPATH}:/usr/dt/man

if (-d $OPENWINHOME/man) setenv MANPATH ${MANPATH}:/$OPENWINHOME/man

if (-d /apl/man) setenv MANPATH ${MANPATH}:/apl/man

if (-d /apl/X11/R5/sparc/man) setenv MANPATH ${MANPATH}:/apl/X11/R5/sparc/man

if (-d /apl/src/tcltk/sun4/man) setenv MANPATH ${MANPATH}:/apl/src/tcltk/sun4/man

if (-d /usr/share/man) setenv MANPATH ${MANPATH}:/usr/share/man

if (-d /usr/local/man) setenv MANPATH ${MANPATH}:/usr/local/man

if (-d /usr/X11R6/man) setenv MANPATH ${MANPATH}:/usr/X11R6/man

 

switch (`uname -n`)

 

   case tc*:

      setenv TERM xterm-r5

   breaksw

 

   case ns1*:

   case isgsrv*:

   case soleng*:

      echo 'Setting up cadre v7.1.1 environment'

      source /cadre/root_set_cadre_env_csh_7.1.1

   breaksw

 

   default:

      if ( ! ${?DT} ) then

         if (`tty` == "/dev/console" && $TERM !~ vt) then

            /apl/X11/R5/sparc/bin/startx

            logout

         endif

      endif

   breaksw

endsw