Unix notes

Log Files
Moving Directories/Files
Backup
Restore
Law Soc Backup & Restore
Move Tape
File Commands
Format Disks
Verify Disks
Swap
Binary Measurement
Neat Little Tricks
Utilities
Std IN/OUT/ERR
Diagnostics
Networking
NFS
System Performance
Sequent Specific Cmd's
Run Levels
Cron and At
Shared Memory
Nawk
Vi
Sed
Substitution Trick
Mish Mash


Standard Template

Log Files

/usr/adm/sulog /usr/adm/messages /usr/adm/ktlog/1997/12/1-31 /usr/spool/adm/syslog /usr/spool/audit/RFIFO /usr/lib/cron/log

Moving Directories/Files

tar cvhf - DIR | ( cd /wherever ; tar xf - ) h - follow links rsh HOSTNAME '( cd /directory; tar cf - files | compress )' | \ uncompress | tar xf - *NB* CPIO is better at moving links and preserving date and time find . -print -depth | cpio -omv | resh Node "(cd /DIR ; cpio -imudv)" find . -depth -print | cpio -omv | (cd /DIR ; cpio -imudv) NB* No " ! rsh SYSTEM 'dd if=/dev/sd0' | tar xvf - ;Extract from another System's Tape Drive.

Backup

find DIR -print -depth | cpio -omvB -O /DEVICE /bin/cpio -iBdmv -I /dev/rmt/tm0 -M 'Hungry for tape%d!!!' /bin/find /usr7/local -depth -print -fstype nfs -prune | /bin/cpio -ocBv -M 'Tape Please' -O /dev/rmt/tc0 cpio -iBdmv -I /dev/rmt/rm0 -M 'Load Tape' Copy IN cpio -oBdmv -0 /dev/rmt/rm0 -M 'Load Tape' Copy OUT cd DIR; find . !-name \*.log -exec DO WHATEVER find . -depth -print | cpio -pmdv ../REGIS Move a directory - The long way. X=RGIS_TRN; mkdir ../$X; chown WHOEVER ../$x; find . -depth -print | cpio -pmdv ../$X find . -depth -print | cpio -o | resh sqfin 'cd /usr7a/tools/ ; cpio -idum find . 3.0.7 -depth -print | cpio -o | resh lslive ' cd /usr7/tools/sqr; cpio idum dumpfs

Restore

/etc/restore xvbf 128 /dev/rmt/tx0x85 /etc/restore vibf 128 /dev/rmt/td0 `cat filelist` mt -f /dev/rmt/td0 ranload 2 sensemag /etc/restore -ivsf 2 /dev/TAPE i=interactive v=verbose s=skip f=filename t=table of contents Get TOC restore -tsf 4 /dev/TAPE

Law Soc Backup & Restore

/tmp/restore.sh -P -f /dev/rmt/tx0 RGIS3_ST

Move Tape

mt -f /dev/rmt/tm0 offline|rewind fsf # forward space file count bsf # back space file count weof write EOF at current possition

File Commands

fuser -cu /usr8c - See who is using a file, nice if you need to unmount an fs. ncheck icheck df -t chmod u+t only move file if user chown -R roland roland ls -lsi `which man which apropos; which ls; which ls` du / | sort -rn - Directories in order of size. mknod - Read /dev/MAKEDEV chmod 4711 ~rmops/ksh :-) Three Times - inodetime = creation time mtime = last modified time access time = last time the data was looked at but not changed find . \! \( -name \*.lst -o -name \*.sql \) - find from the cwd down everything except *.lst and *.sql find . -name '*~' -exec rm {} \; find . -mtime 2 -mtime +4 -mtime -10 - find files 2 day old, > 4 day old, < 10 days old

Disks

newfs -d 0 -t 1 -u4096 -n 1 DB newfs -e 1000000 -i65536 -m0% NUMA newfs -d0 -r1 -u 4096 -n1 -e1000000 -i65536 -m0% d rotational delay t tracks/cylinder u sectors/track n distinguish rotational position newfs -N -v Check how disk was formatted. /etc/labelit /dev/rvol/newusr8 usr8 usr8

Verify Disks

rdcp -r /dev/rdsk/qd9s0 fsck -p Do in parrallel < take info from /etc/fstab To look a proc errors and other system failure mesages # mount /dev/dsk/qd0s10 /mnt fsdb - file system debugger

Swap

swap -l list; swap -f show usage; swap -a device - add swap

Binary Measurement

ls is in bytes 120000/1024/1024 = BLOCKS BLOCK * 512 =kilobytes * 1024 = bytes

Neat Little Tricks

/bin/chown rmops `cat ~rmops` nawk 'BEGIN {total=0}; total=total+$1}; END {print total}' ls | paste ---- print ls in four colomns

Neat Utilities

truss - Trace System calls #truss CMD bp - Binary Batch ctrace - C debugger cmd. error - ?? To find out when the system rebooted last look in /usr/adm/messages and search for UTC (Universal Time Clock) you will need to +- the time difference. script FILENAME - keep a log of all you do.

Standard IN/OUT/ERROR

File descriptors 0,1,2 = stdin, stdout, stderr 2>&1 - send stderr to the same place stderr is going to File descriptors 3 & 9 are holding areas, so to make stderr go to stdout and stdout to go to stderr you could COMMAND 3>&2 2>&1 1>&3

Diagnostics

/usr/service/bin/ol_diag Online Diagnostics /usr/include/sys/errno.h

Networking

spray IP/Name arp -a /etc/net_conf/routetab /etc/net_conf/iftab rout -fa f=flush, a=add, ethstat -fa /usr/etc/tcpdump -e -v -x host 192.128.186.12 > /tmp/tcpdump & kill -1 %% of tcpdump /usr/etc/tcpdump -exv ip proto icmp > /tmp/roly & tcptlist; tcpctl; tcputl - part of Oracle SQL*NET arp -a ethstat routed -d -g -s -q -t logfile /etc/netstat -m ( s = per protocol D = Routes. ) /etc/netstat -s | grep keepalive /etc/services for IP and UDP and TCP services rpcinfo -p lsdev Check services available form lsdev You can ping but you cant telnet, - Run netstat -nr then remove any dynamicly re-routed paths which are not valid. route delete XXXXX XXXXXXX cut the IP No's form netstat -nr. ethstat layer 2 netstat - layer 3 & 4

Network File System

/etc/mtab - Currently mounted filesystems /etc/xtab - Currently exported filesystems /etc/rmtab - host:directory name pairs /etc/exports - list of filesystems to be exported exportfs -a - Does what it says. ps -ef | grep [ mountd | statd | rpc ] - I like rpc to check mount_nfs lsdev:usr7/scontrol /usr7tools/scontrol

System Performance

sar -u cpu utilisation -b buffer activity -d block device -y tty activity -y tty activity -c system calls -w swapping/switching -a file access -q run queue -v inode tables -m messages/semaphore -p paging -r unused mem pages/disk blocks and freeswap -A all sar -f 5 20 sar -d 10 who -dl - Show dead processes. who -ft ttyRM/ARMg show who on tty. e everything d dead a all l long L longer f full F fuller

Sequent Specific Cmd's

There is some nice stuff in /usr/lbin/* dumpconf diskid showcfg -s -d ( -s System Memory -d System discription ) File interigation Cmds. /etc/fuser -cu /usr8c - Check who is using this file/directory

Run Levels

/etc/shutdown -s -g0 -i0

Cron and At

/usr/lib/cron/queuedefs a.4j1n a at jobs, b batch jobs, c cron jobs b2j2n90w abc job queue (a-z) j no of jobs n niceness w wait before retry drestart cron - first remove /usr/lib/cron/FIFO At ~~ at only checks in /usr/lib/cron/at.deny if at.allow does not exist.

Shared Memory

ipcs (-b biggest, c creators name, t time, ipcrm -m #

Nawk

Sed

s/Pound/Pence/2 Change only the second occurance of Pound to Pence on each line y/abc../ABC../ Lower to Upper sed -e 's/old/new/' -e '/older/newer' filename /^$/d Delete all blank lines /10,/20,/d Delete from line 10 to 20, !d - All lines except 10-20 /Roland/!d Delete all lines that don't contain Roland

Nawk

egrep "(Anita|Linda|Roly)" /etc/passwd

Vi

:g/old/s//new/p Global Replace and present dG Delet to end of document d1G Delet to begining of document :g/^$/d Delete all blank lines :r!unix-cmp "a5yy :e another file "ap or "bp etc. vi -r Retrieve lost file. :175,185ya a Yank lines into buffer a :pu a Put buffer a :175,185d and then p where you want it

Substitution Tricks

ls -d *.txt | sed 's/\(.*\)\.txt$/mv & \1.doc/' | sh Inside of Vi, :r !ls *.sql -read it :%s/.*/mv & &/ -insert mv in front and copy it after :%s/txt$/doc/ -change second extension :w !sh -Run it :q

Mish Mash

chmod 1777 /tmp or whatever. - Permissions on TMP; rhosts must be 644 chmod u+t only move if owner mount -t iso9660 /dev/cdrom /cdrom expr 23451251234 / 2048 = 965046 kill -STOP;INT.. or -9 -1 etc. NIS - NETWORK INFORMATION SERVICE (NIS and DNS are not the same) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ master server /etc/netgroups - Netgroups /etc/hosts.equiv /etc/defaultdomain found in /var/yp /usr/etc/yp or /etc/yp Advantages Disadvantages insecure - any host can claim to serve a particular domain and then fee bad info to NIS clients anyone can read your NIS maps - a very bad idea if you are connected to the internet! easy to administer, simple flat file each domain must be administered seperately, does not provide a way to linke domains. BIND ~~~~ named /etc/named.boot /etc/named.ca ~/.rhosts primary and secondary LDAP ~~~~ NSLOOKUP ~~~~~~~~ nslook -q=any thatthing.com PHP
~~~ delete files owned by nobody on the webserver <?php
passthru("chmod -R go+rwX /path/to/your/files");
echo "Done!";
?>
or <?php
passthru("rm /path/to/your/files");
echo "Done!";
?>
Unix Links Debian Networking http://www.debian.org/doc/manuals/network-administrator/