Sunday, August 28, 2011

Tips and Tricks of UNIX


I've been working with variations of Unix for a long time  and thought I'd write down some of my favorite tips and tricks. They are mostly OS/distribution/shell/language independent (unless I indicate otherwise...)
1.     Get rid of blank lines in a file
grep . inputfile > outputfile
This matches (and thus prints) only lines that contain some text, not blank (empty) lines.

2.     comm
Many people never cross paths with the 
comm command, but it is very useful. I works similarly to diff, but outputs the contents of two compared files into three columns. The first column is content only in the first file, second column is content only in the second file, and third column is content that is in both files (matches between the two files.) While this may not seem useful at first, you can select which columns to output, so if you only want to know what is in both file1 and file 2 (column 2) you'd suppress columns 1 and 2, by running:
comm -12 file1 file2
Don't forget that your input files must be sorted.

3.     paste
Systems administrators frequently use the 
cut command to parse files, but many people I run into have never used the paste command. The paste command will concatenate two files line by line (as opposed to file by file, likecat.)

4.     less instead of more
This is not available on all Unix-based OSes, but the 
less command works very similar to more, but will let you move through a file forwards and backwards more easily. Want to jump to the end of the file, type Shift-G Depending on the version of less you are running, it will provide context highlighting when you search for a pattern.

5.     Jump to vi from more
While paging through a file in more, press "v" to jump to editting the file in vi at the current position in the file.

6.     Jump to a line number when editing a file with vi
vi +linenumber filename
will open up the file with the cursor automatically moved down to the specified line. This is useful when you get an error that indicates "syntax error on line 2047." You can jump straight to the problem without fumbling around.

7.     Invisible characters become visible
Sometimes you'll end up with carriage returns on each line in a file originally created on a DOS/Windows system, or filenames with spaces, tab, or other control characters in them, but you can't see them typically.
The 
cat command provides three useful options -v, -e, and -t that will let you understand these invisible characters
-v (displays non-printing characters)
-e (prints a "$" at the end of each line to indicate a NL character)
-t (prints "^I" for each Tab in the file)
cat -vet filename |more

8.     Remove DOS ^M from ends of lines
The "^M" characters are visible when editing in vi but here are two approaches to remove the characters.

 
   sed 's///g' -i filename 
      or in vi: :%s///g
   or dos2unix filename filename 


9.   You've done something that has completely screwed up your terminal. Everything you type is either invisible or incomprehensible. Try the following:
    $ ^C
    $ stty sane^J
If this doesn't work, try:
    $ echo ^V^O

10. To determine what program dumped an anonymous core file, use gdb:
    $ gdb -core core
    [...]
    Core was generated by `a.out'.
    Program terminated with signal 6, Abort trap.
    [...]
If you are on a system without gdb, try the file command:
    $ file core
    core: ELF 32-bit LSB core file of 'a.out' (signal 6)
    $

11. To create a vi macro that will wrap the current paragraph to a reasonable number of characters, add the following to your .exrc or.vimrc file:
    map Q {!} fmt -c -u^M
Now, when you press 'Q' in visual mode, the current paragraph will be wrapped to approximately 70 characters.

12.  Due to the Unix concept of sparse files, you can create seemingly enormous files that in reality take next to no disk space. The following program will create a 305,419,897 byte file called 'core' that may result in you receiving a 'cleanup' email message from a less-than-seasoned Unix sysadmin even though it occupies virtually no real disk space.
    $ cat bigcore.c
    #include
    #include

    int main(void) {
        int fd = open("core", O_CREAT|O_WRONLY|O_TRUNC, 0600);
        lseek(fd, 0x12345678, SEEK_SET);
        write(fd, "1", 1);
        close(fd);
        return 0;
    }

    $ cc -o bigcore bigcore.c
    $ ./bigcore
    $ ls -l core
    -rw-------  1 dmr  staff  305419897 May  1 03:50 core
    $ du -k core
    48      core
    $

13.  On older Unix systems, in particular those that don't support MD5password hashing, only the first 8 characters of a password are significant. If you use an 8 character password on these systems, you can type anything you want after the first 8 characters and it will be accepted by login. This allows you to type the first 8 characters of the password as usual, then have some fun. Enter a bunch of crap at superhuman speed, then enter the last few characters with your elbow. Then press backspace twice carefully and retype the characters with your other elbow. Etc....

14.  When recursive copyingcp (cp -Rip, etc.) may not be the best tool for the job. For example, cp copies hard links as separate files, which is probably not what you want. To get a true copy of a directory, try:
    $ tar cf - | (cd ; tar xf -)
This will create an exact copy of 'dir' in 'destdir'. The same principle can be used to create a recursive copy on a remote machine:
  $ tar cf - | ssh remotehost "(cd ; tar xf -)" 

15.  To list the files in another directory that match more than one pattern, it is easiest to do:
    $ ls -l /usr/local/foo/{*.conf,*.local,*.rc}
which is equivalent to:
$ ls -l /usr/local/foo/*.conf /usr/local/foo/*.local /usr/local/foo/*.rc
This syntax is supported by (at least) bashkshcsh and sh.
You can extend this idea to make renaming files in another directory, for example, a little easier:
$ mv -i /usr/local/foo/bar/baz/{stuff,stuff~}

16.  A little insurance against running 'rm -rf *' in the wrong directory -- create an empty file called -i in any critical directory:
$ >-i
or...
$ touch -- -i
If the 'rm -rf *' command is issued in that directory, the shell will expand the '-i' early on and go into interactive mode, thus giving you a chance to say 'Whoa, that was close!', which always sounds better than 'Oh fsck!'.
This tip works because the -i option to rm will override any previous -f.
Be forewarned that this tip only protects against 'rm -fr *', i.e., files and directories in the current directory.
To remove the -i file (or any other file beginning with '-'):
$ rm ./-i
or...
$ rm -- -i

17.  To return to the previous directory in ksh or bash, use:
$ cd -
18.  To use the last argument of the previous command line as an argument, use $_. For example:
$ ls -l /usr/home/dmr/somefile
$ vi $_

19.  To make the up and down arrow keys work and thereby enablecommand line editing and recall in ksh, include the following lines in your ~/.profile:
set -o emacs
alias __A='^P'
alias __D='^B'
alias __B='^N'
alias __C='^F'
alias __H='^A'
You need to enter the actual control characters ^P, ^B, etc.




Mac OS X 10.3 Panther [OLD VERSION]

Linux Ubuntu: Easy to Use Operating System From Shift+Open Complete Redhat Linux 5.2 Operating System Deluxe Secure Server

Solaris One liner

Working on solaris or any unix operating system need a lot of command to learn.But it is difficult to memories all  those command.Keeping those command in hand will help a lot for Unix Administrator. I am here posting some one liner command that may be helpful to all UNIX administrator as well as UNIX beginners:-

Linux Administration: A Beginner's Guide, Fifth EditionUNIX System Administration Handbook (3rd Edition)Unix and Linux System Administration Handbook (4th Edition)Unix Shell Programming (3rd Edition)Classic Shell Scripting

–> change file date stamp
touch –t 199906042020 filename

–> move partitions
ufsdump 0f – /dev/rdsk/c0t0s0s0 | (cd /home; ufsrestore xv -)

–> lay down file system with 1% minfree and inode density
newfs –m1 –i81920 /dev/rdsk/c0t0d0s0

–> check file system
fsck /dev/rdsk/c0t0d0s0

Q: starting sybase
login as sybase, run: ./install/RUN_SYBASE

Q: logging in as sybase sa
isql -U sa

–> dump a partition and pipe to gzip. Watch > 2GB limit
ufsdump 0f – /home | gzip – >/tmp/home.dump.gz

–> rewind offline a tape
mt –f /dev/rmt/0 rewoffl

–> only allow 300MB for user /tmp access
swap – /tmp tmpfs – yes SIZE=300M

–> verbose interactive restore
ufsrestore –ivf /dev/rmt/1

–> remove a printer from a class
lpadmin –p level5-line1 –r level5-line

–> truss a command
truss –-f -–o /tmp/log.txt

–> [DB] feed a script into sybase
isql –Urfe_xfer -Uuser -Ppassword -isqlscript >>blah.txt

–> make a printer class
lpadmin –p level5-line1 –c level5-line

–> remove level2-line2 printer from printer class level2-line
lpadmin -p level2-line2 -r level2-line

–> add level2-line3 to printer class
lpadmin -c level2-line -p level2-line3

–> [DB] how to change your password in isql
sp_password password, password-new

–> move a directory
tar cf – ./games | (cd /tmp; tar xvBpf – )

–> [DB] run a sybase script, and dump to file
$ISQL -i$SCRIPTFILE -U$USER -D$DATABASE -P$PASS_ENC >> $SCRIPTLOGFILE

–> move a directory to another server
tar cf – ./games | rsh brucey cd /tmp\; tar xvBpf -

–> check for SUID SGID files
ncheck -F ufs -s /dev/dsk/c3t0d0s

– remove core files
find / -name core –exec rm –f {} \; -o –fstype nfs –prune

–> rebuild man pages
catman –w –M man-page-directory or /usr/lib/makewhatis

–> vi command to show special characters
: set list

–> adding an account
useradd -u 120 –g dls -d /apps/dls –s /bin/ksh -c “comment” -m dls

–> create a mysql database
mysqladmin -uroot -ppassword create ebs

–> starting mysql database
/etc/rc.d/init.d/mysql.server start
/usr/local/bin/safe_mysqld

–> Invoke CPAN module install
perl –MCPAN –eshell

–> dump to zip
ufsdump 0f – /filesystem | /opt/local/gzip – > /tmp/dump.gz

–> shutdown mysql databse
/usr/local/bin/mysqladmin shutdown -ppassword
/etc/rc.d/init.d/mysql.server stop

–> test the loading of a module
PERL_DL_DEBUG=255 perl -e ‘use CGI;’

–> shows open files
fuser –cu /

–> Writing a Daemon:
1. edit /etc/services
add service and port.
2. edit /etc/inetd.conf
add in: edwardd stream tcp nowait root /bin/sh /bin/sh /home/sextone/bin/SERVER.mine
3. kill –HUP inetd.conf

–> how to mount a file system
mount /dev/dsk/c3t0d0s4 /apps/data/easysoft/DEVT

–> look at sar log
sar –f /var/adm/sa/sa24

–> write file checksums and size
cksum filename

–> show storage array info
ssaadm display /dev/rdsk/c1t5d2s0
–> show all disks on device d
luxadm display d

–> examine for a specific OS finerprint
nmap –sS -p 80 -O -v = examine OS

–> show print jobs
/usr/ucb/lpq –Plevel6

–> Scan for known ports. log it. do OS scan.
nmap –sS -F -o foo.log -v -O www.foo.com//24 =

–> show status of printer
/usr/ucb/lpc status

–> make a swap file:
dd if=/dev/zero of=swapfile bs=1024 count=65535
mkswap ./swapfile
chmod 600 ./swapfile
swapon ./swapfile

–> show open files for process
lsof –p PID

–> show open files for all TCP connections
lsof –iTCP

–> show open files for internet address
lsof -iTCP@10.20.2.9

–> as above
lsof -i @10.20.2.122

–> examine tcp ports
lsof -iTCP@sarah:1-50000

–> show open files for user.
lsof –u username

–> show processes that has the file in use.
lsof /apps/cms/ECMS-Server

–> show open files and retry every 5 seconds
lsof –p process-id –r 5

–> mount a floppy
mount -t vfat /dev/fd0 /mnt/floppy

–> check here for debugging processes and errno.h for errors
/usr/include
/usr/include/sys
/usr/include/sys/errno.h

–> scp a whole directory, preserve mods
sudo scp -prv devel webadmin@203.19.123.140:/home/httpd/cgi-bin

–> take processor 2 and 3 offline.
psradm -f 2 3
–> show processor stats verbose.
psrinfo –v

–> how to skip grant tables in mysql (over ride security)
/usr/local/libexec/mysqld -Sg

–> how to feed in an SQL program
mysql

–> rm all files in directories
find . -type f -exec rm {} \;

–> dump packets to a capture file
sudo snoop –o /tmp/tcp.txt cp

–> backup one liner
tar cvf – /home/ebs | gzip – > ebs.tar.gz

–> Look at selected packets in capture file
sudo snoop -i /tmp/tcp.txt

–> unzip and pipe to tar
gzip -dc

–> watch packets from two servers.
snoop sarah brucey

–> enable ip masquerading
/sbin/ipchains -P forward DENY
/sbin/ipchains -A forward -s 10.100.100.100/8 -j MASQ

-> view su log file
cat /var/adm/sulog

–> establish a default router or gateway.
echo “sagacity.com” > /etc/defaultrouter
echo “10.100.100.100 sagacity.com sagacity” >> /etc/hosts
change /etc/nsswitch.conf so that hosts has files, dns
edit resolv.conf put in
search .
nameserver 203.7.132.98

–> turn off automounter on /export/home.
vi /etc/auto_master, comment out /export/home

–> configuration file for sudoers
/opt/local/etc/sudoers

–> building ssh-1.2.27 on x86Solaris2.6 needed a few things:
/usr/openwin/bin in path
/usr/xpg4/bin in path
declare AR=”/usr/xpg4/bin/ar”
declare NM_PATH=”/usr/xpg4/bin/nm”

–> snoop network packets and get size and time stamp entries.
snoop -S -ta empa1

–> access perl CPAN
perl -MCPAN -e shell
install DBI

–> search for no password entries and lock all accounts.
for i in `passwd –sa | grep NP | awk ‘{print $1’`
do
echo “locking $i”
passwd –l $i
done

–> delete from a tar
tar –delete -f fs_backup_Sunday.tar home/ebs/tmp

–> Example on backing up files to tape. Must specify non rewinding, else you will over-write the files.
for file in `ls`
do
echo “sending $file to tape…”
echo `date`
tar cvpf /dev/rmt/0n $file
done

–> making/adding a partition.
1. use fdisk to make a parition.
2. mkfs -t ext2 -c /dev/hda11
3. mount -t ext2 /dev/hda11 /opt2
4. update /etc/fstab

–> rebuild the windex file
catman –w –M /usr/share/man

–> execute tar on remote host sarah and send tarball to standard output,
which becomes standard input for tar xvf – and the file gets dumped locally,
in this case on crawl. you have to cd to dir before tar or else you
will include path in tar
ssh maggie “cd $DIRNAME; tar cvf – $BASENAME” | (cd $TPATH; tar xvf – )

–> dump a remote filesystem and send it to local tape drive.
ssh -–x $fw /usr/sbin/ufsdump 0cf – $fs | dd obs=63k of=$TAPE

–> encrypt filename 1 and output to 1.crypt file
crypt < 1 > 1.crypt ; rm 1

–> decrypt filename 1.crypt and stdout to screen
crypt < 1.crypt

--> send a file to tape
tar cvpf /dev/rmt/0 filename

–> quicker way to search and replace in vi
: %s/existing/new/g

–> shows where and which shared library files an application uses.
ldd binary

–> shell script stuff:
# repeat a command 100 times
x=100
while [ $x -gt 0 ]
do
command
x=$(($x-1))
done

–> Something very important to remember about partitions
It is important to note that Cylinder 0 contains the disklabel, which
contains the partition table. A normal filesystem can be placed
starting at Cylinder 0, since it will not touch the disklabel.
If you lay down a raw device, for a database, over Cylinder 0,
then you will completely lose all your partitions. You will then
have to restore the disklabel, and backup from tape if you happen to do this.

–> move a partition
find . |cpio -pdm /apps

–> cron structure
min hour day-of-month month weekday command

–> PatchDiag Tool. Get patches from:


patchdiag.xref is available at: http://sunsolve.sun.com/sunsolve/patchdiag/
/opt/local/bin/patchdiag -x /opt/local/lib/patchdiag.xref > patchdiag.`uname -n`

–> command showing system parameters
/usr/sbin/sysdef

–> Get Ambient Temperature of Server
/usr/platform/SUNW,Ultra-4/sbin/prtdiag -v

–> good ps formatting showing percent cpu first.
ps -edf -o pcpu,pid,user,arg

–> full details on ps
/usr/bin/ps –A -o user,pid,pcpu,pmem,vsz,rss,tty,s,stime,time,args

–> chown the hidden files as well.
find . -print -exec chown -R sextone:staff {} \;

–> The nsradmin command is a command-line based administrative
program for the NetWorker system. Normally nsradmin monitors
and modifies NetWorker resources over the network.
/usr/sbin/nsr/nsradmin

–> Spray a server
-c number of packets
-d delay in microseconds
-l pakcet size in bytes
/usr/sbin/spray -c 1 –d 20 -l 4096 maggie

–> Turn on bold.
bold=`tput smso`
offbold=`tput rmso`
echo “${bold}You must be the \”root\” user to run this script.${offbold}”

–> good way to send a dir to tape
tar cf /dev/rmt/0n directory

–> example of bringing up an interface
ifconfig hme0:1 inet 10.2.25.52 up

–> show all connections
netstat –f inet

–> rpcinfo makes an RPC call to an RPC server and reports
what it finds.
rpcinfo -b 390109 2 | sort -u

–> rewind a tape fast
< /dev/rmt/0

--> show loaded modules
/usr/sbin/modinfo

–> find world readable files and dirs
find / -type d –perm -2 –print
find . -type f –perm -2 -print

–> adding in a boot alias, eg:
boot sarahroot1 –s
nvalias sarahroot1 /sbus@1f,0/sunw,fas@e,8800000/sd@9,0:a

–> clever way to archive
tar cvf – `find . –print` >/tmp/dumpfile.tar
tar xvf – tee to a file
echo “Start Date/Time: `date`” | tee -a $LOG_FILE

–> read a snoop file
snoop -i anz-telnet.snoop

–> write a snoop log (this will count the number of connections, which is pretty neat).
snoop –osnoop.log sarah

–> set default run level. 5 for gui.
/etc/inittab

–> show all exported filesystems
showmount -e crawl

–> shows all configurable variables for tcp interface.
sudo ndd -get /dev/tcp
- ?
eg:
sudo ndd -get /dev/tcp tcp_conn_req_max_q
128
ndd /dev/arp \?
ndd /dev/ip \?
ndd /dev/tcp \?
ndd /dev/udp \?
ndd /dev/icmp \?

–> set sticky bit on group files, only the owner can change the mode.
–> the +l is mandatory file and record locking while a program
–> is accessing that file.
chmod g+s,+l file

–> print duplex landscape 4 qudrant printing
mpage –t –l –4

–> install a patch
installpatch .

–> check to see if a patch has been installed
showrev –p |grep package name

–> unzip, untar in a /tmp directory
zcat 104708-16.tar.gz | ( cd /tmp; sudo tar xvf – )

–> check out revision level on ssa controller
/usr/sbin/ssaadm display controller

–> unzip and untar a file without having to create an intermediate tar file
sudo gzip -dc /tmp/270599/post-EOD.tar.gz |tar xvf -

–> selectively extract from a tar archive
tar xvf /tmp/iona.tar ./iona/.sh_history

–> send a bunch of files to tape
tar cf /tmp/rules.tar ruleb* objects.C *.W

–> examine section 5 of man
man -s 5 signal

–> shows signals and definitions of structures, eg sigaction
/usr/include/sys/signal.h

–> location of the limits file on solaris
/usr/include/limits.h

–> send an attachment via email from command prompt
uuencode file.tar.gz file.tar.gz | mailx –s “backup” root@crawl

–> zero a file
cat /dev/null > isam.log

–> good way to restore from cdrom a binary file
zcat < /cdrom/cdrom0/Solaris_2.6/Product/SUNWcsu/install/reloc.cpio.Z |
cpio –idm usr/lib/fs/ufs/ufsrestore

--> running su as a user then ssh
su – dls-PROD -c “/opt/local/bin/ssh drp-stagger \”cd /tmp; /bin/ls\” ”

–> verify a newfs format
sudo newfs –Nv /dev/md/dsk/d96

–> making lost_found. must be 8192 bytes in size.
mkdir ./lost+found;chown root ./lost+found; chgrp root ./lost+found ;chmod 700 ./lost+found’; cd ./lost+found
nofiles=0 ; while [ "$nofiles" -le 650 ] ; do ; /usr/ucb/touch $nofiles ; nofiles=`expr $nofiles + 1` ; done

–> execute lynx
lynx -cfg /usr/lib/lynx.cfg

–> sed search example
sed ‘/Sep\ 25/!d; /castill/!d’ /var/log/syslo

–>should only be used at the EEPROM
boot –r
–> should be used at single user mode
reboot — -r
–> should be used in multiuser mode
touch /reconfigure

–> performing a remote dump

find MFASYS
|cpio -oc |gzip -c
|ssh brucey -l chaup dd obs=18k of=/dev/rmt/0n

- to extract -
cd /ssa/emphasys/sybase/dump
dd ibs=18k if=|gunzip -c |cpio –idc

–> boot block located here.
/usr/platform/`uname –i`/lib/fs/ufs

–> getting a server on the network
add hosts entry for IP address
clear configs: ifconfig pe0 unplumb
ifconfig pe0 10.20.2.27 netmask 255.0.0.0 up
route add default 10.20.0.1 1
verify the routing table: netstat –rn
add resolv.conf entry: domain rabobank.com.au nameserver 192.192.192.252
edit /etc/nsswitch.conf change hosts to files, dns

lesson here is to unplumb interface, and let ifconfig setup the routing.
if you specify an ip address and a netmask it will manage
the routing and the broadcasting.

–> find all, files associated with PID 22240
/usr/proc/bin/pfiles 22240
find file based on inode
find –i number
“ncheck –i number

–> good redirection example
./a.out trash

–> synchronize files from one server to another. This is useful for
synchronizing database dump files, binary files, etc. This is definitely a powerful tool.

rsync -avz -e ssh –rsync-path=”/usr/local/bin/rsync” `pwd` myhost.com:/home/ebs/public_html

–> Example Awk Script

# run with awk -f/tmp/1.awk /etc/group

BEGIN { FS = “:” }
{ print $1 | “sort” }
{ nlines++ }
END { print nlines }

–> awk example.
awk ‘/#/ {print “Got a comment”}’ /etc/hosts

–> delete every 2nd field in file
awk ‘{$2= “”; print}’ datafile > datafile.new

–> awk average/standard deviation program

x1 += $1
x2 += $1*$1

END {
x1 = x1/NR
x2 = x2/NR
sigma = sqrt(x2 – x1*x1)
if (NR > 1) std_err = sigma/sqrt(NR – 1)
print “Number of points = ” NR
print “Mean = ” x1
print “Standard Deviation = ” sigma
print “Standard Error = ” std_err

   
These are simple one liner tips for solaris.
Processor Information:
The psrinfo command displays the Processor info on the Sun Server
# psrinfo -v
Status of virtual processor 0 as of: 08/31/06 12:27:07
on-line since 08/28/06 01:46:34.
The sparcv9 processor operates at 296 MHz,
and has a sparcv9 floating point processor.


Open Boot Prompt (OBP) revision:
The prtconf command displays the Open Boot Prompt revision
#prtconf -V
OBP 3.29.0 2000/12/20 18:41
3.29.0 indicates the revision of the Open Boot Prompt.


Patch Revision info:
The showrev command displays the revision of a particular patch. This helps when you install a version of the patch to check if it is the latest and/or check if it is obsolete.
#showrev -p |grep


System Type:
The uname command can be used to find the hardware type.
#uname -i

SUNW,Ultra-60
The above command is run on a SPARC Ultra60


Solaris revision:
Use the uname command to find the revision number of your Solaris Operating System.
#uname -v

Generic_108528-29
where 108528-29 is the Solaris patching revision.
Please note, Newly installed patch revisions will not show until the server is rebooted.


Solaris Server Version:
The uname command can be used to find the Solaris operating system version.
#uname -r
5.8
or
#uname -a
SunOS myserver 5.8 Generic_108528-29 sun4u sparc SUNW,Ultra-60
where 5.8 indicates Solaris 8.




How do I get Oracle to automatically start when my server boots up?

Oracle provides two UNIX scripts that assist DBAs with starting and stopping the database: dbstart and dbshut. For Windows platforms, the oradim utility is provided for starting and stopping the Oracle instance.

The dbstart utility reads the oratab file, shown in the example below. The oratab file will reside in either /etc or /var/opt/oracle, depending on the UNIX version. It contains three data items separated by colons:

ASG920xr:/usr/oracle/9.2.0:Y

ASG817xr:/usr/oracle/8.1.7:Y

TEST920xr:/usr/oracle/9.2.0:N

PROD920xr:/usr/oracle/9.2.0:N

The first field is the Oracle SID. The second field is the home directory for that Oracle SID. The Y or N instructs Oracle whether to start or stop the particular database when either the dbstart or dbshut command is issued. The dbstart command simply parses the oratab file and starts those databases that have a Y in the third field. It also uses the ORACLE_HOME specified in the file to connect internally to the database and issue the startup command.

The dbstart command can be added to the UNIX servers’ initialization or run level scripts. This enables dbstart to be executed each time the machine is booted or when it changes run levels. The method for implementing this is platform specific, as we see below.

Auto Start on HP-UX and Solaris

For HP-UX version 10 and above, the system initialization scripts are contained in /etc/rc.d directories, where “n” is the operating system run-level. These directories contain scripts that begin with a K or S, followed by a number, and then a file name (S75cron). All scripts that begin with “S” are executed at system startup in ascending order of their number. Scripts beginning with “K” (Kill) are called at system shutdown time.

As a general rule of thumb, the Oracle startup script should have a high sequence number (S99dbstart), which will ensure that other system processes have been started prior to Oracle. Likewise, the kill scripts should have a low sequence number in order to shutdown Oracle early in the process (K01dbshut).

Auto Start on AIX

For AIX servers, the system initialization file is /etc/inittab and the initialization script is /etc/rc. A utility (/usr/sbin/mkitab) can be used to make an entry in the inittab file. The shutdown script for AIX is /usr/sbin/shutdown, although it should not be modified to support dbshut.

To add the dbstart utility to the AIX initialization process, the following steps can be performed:

1. Create the script /etc/rc.oracle. The script should contain the following:

su oracle <

<$ORACLE_HOME>/bin/dbstart

EOF

2. Add the script to the inittab using the mkitab utility.

$ /usr/sbin/mkitab “rcoracle:2:wait:/etc.rc.oracle >/dev/console 2>&1”

All references to <$ORACLE_HOME> should be replaced with the actual Oracle Home directory. Now upon system startup, the dbstart utility is invoked at run level 2.

--------------------------------------------------

Make sure the entry for your database SID in the ORATAB file ends in a capital "Y". Eg:

#   $ORACLE_SID:$ORACLE_HOME:[N|Y] # ORCL:/u01/app/oracle/product/8.0.5:Y # 

The scripts for starting and stopping databases are: $ORACLE_HOME/bin/dbstart and dbshut. SQL*Net (or Net8) is started with the lsnrctl command. Add the following entries to your/etc/rc2.d/S99dbstart (or equivalent - for example HP-UX uses /sbin/rc2.d/*) file:

su - oracle -c "/path/to/$ORACLE_HOME/bin/dbstart"         # Start DB's su - oracle -c "/path/to/$ORACLE_HOME/bin/lsnrctl start"   # Start listener su - oracle -c "/path/tp/$ORACLE_HOME/bin/namesctl start"  # Start OraNames (optional)