Raj Patel's Weblog

Home  |  News  | Links | Information | Pictures | Archive  

 

Collection of Unix Guru Universe Tips


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2039 - August 1, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


GETTING MORE FROM SIGSEGV

For those who want to get
more info on SIGSEGV for
your application in Linux,
you can use the following
command "catchsegv".

for eg: consider the program (a.c)
main()
{
char *p = 0;
*p = 'a';
}

$cc a.c
$catchsegv a.out #produces the following output


*** Segmentation fault
Register dump:
EAX: 00000000 EBX: 4010e1ec ECX: 08048398 EDX: 4010f098
ESI: 4000ae60 EDI: bffffafc EBP: bffffab0 ESP: bffffaac

EIP: 080483a8 EFLAGS: 00010296

CS: 0023 DS: 002b ES: 002b FS: 0000 GS: 0000 SS: 002b

Trap: 0000000e Error: 00000006 OldMask: 00000000
ESP/signal: bffffaac CR2: 00000000

FPUCW: ffff037f FPUSW: ffff0000 TAG: ffffffff
IPOFF: 00000000 CSSEL: 0000 DATAOFF: 0000ffff DATASEL:
0000

ST(0) 0000 0000000000000000 ST(1) 0000 cf118de5ab2a5800
ST(2) 0000 feb02a6c405d9ad4 ST(3) 0000 0000000000000000
ST(4) 0000 8000000000000000 ST(5) 0000 8000000000000000
ST(6) 0000 0000000000000000 ST(7) 0000 847fffdee0000848

Backtrace:
/usr/src/bs/BUILD/glibc-2.1.3/csu/init.c:0(??)[0x80483a8]
/lib/libc.so.6(__libc_start_main+0xff)[0x400369cb]
??:0(_start)[0x8048311]
"csv" 25L, 860C


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2040 - August 2, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


COUNTING BLANK LINES

Counting blank lines in
a file which may include
spaces and tabs:

cat filename |awk ' /^['\ '|'\\t']*$/ { ++x } END { print "No. of Blank Lines = " x } '


This tip generously supported by: rajibroy@engineer.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2041 - August 3, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


CHANGE TO LAST DIRECTORY

Return to the previous directory:

To return to the last directory we
were working in type.

cd ~-

This tip generously supported by: Prashant.Mhatre@nasd.com

 

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2043 - August 5, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FINDING CONTROL CHARACTERS

To find out the control
characters in a file, we
can use following two methods:

% cat -vet filename

or edit the file using vi:

:set list

This tip generously supported by: tb.unnikrishnan@citicorp.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2044 - August 6, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


KILL IDLE USERS

Here is a quick script to
kill idle users at the 10
hour mark.

Cchange the 10 to the hour
you would like to kill at
and #run as cron every hour
This is for HP UNIX, check
the fields on the "who"
command for your flavor

------- cut here ----------

who -u | cut -c 1-10,39-50 | grep 10: > current
for each IDLE_USR ( `cat current | awk '{print $3}'` )
kill -9 $IDLE_USR
end
exit (0)

------- cut here ----------

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2049 - August 11, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


TAR IS A ZIP

Ever want to tar and compress
a file all in one command:

tar cf - /home/foo | compress > foo.tar.Z

gzip can be used the same way
tar cf - /home/foo | gzip > foo.tar.Z

If you wanted to capture the
output so you had an index file
of what the tar file contains:

For sh, ksh use:
tar cvf - /home/foo 2>foo.idx | compress > foo.tar.Z

For csh use:
(tar cvf - /home/foo | compress > /foo.tar.Z) >&foo.idx

and an index file will be created.

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2050 - August 12, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


VI INDENTATION

Indent your lines or remove
the indentation in the vi
editor.

<< Shifts the current line to the left by one shift width.
>> Shifts the current line to the right by one shift width.

You can set the shift width
by command

:set sw

For example, the command to
set the shift width to 4
characters is

:set sw=4.

This tip generously supported by: neetas@noida.hcltech.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2051 - August 13, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


GRABBING THE HIDDEN

To easily select all
hidden files, use the
following:

.[^.]* ..?*

For example,
echo .[^.]* ..?*

will output a list of
all hidden files in your
current directory.

.[^.]* selects all files
starting with a dot but NOT
having a dot as their
second character.

..?* selects all files
starting with two dots and
having at least one additional
character

Together, they will retrieve
ANY file starting with '.'
except '.' and '..' (even
tricky ones like '...hideme')

The ^ (caret) symbol can be
used as the first character
inside [ ] at any time to say
"not one of the following"
rather than the usual "any one
of the following."

[^0-9a-fA-F] will match any
character that is NOT a hex
digit.


This tip generously supported by: wurzel@concentric.net


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2052 - August 14, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FIND AND EDIT STRINGS

Ever found a need to find
for a particular string
across the file system and
edit all those files which
contains that particular
string??

Here is a simple way.

Suppose you want to search
for a pattern "mphasis" across
file system and edit those
files..

Just type this at the
command prompt:

vi `find . -name "*" -exec grep -l mphasis {} \; -print`


This tip is supported by: Manjunath.Alkod@mphasis.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2053 - August 15, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


ARCHIVE ONLY FILES

The following will archive
only the regular files in
a directory, ommitting
subdirectories and hidden
files:

ls -al | awk '$0!~/^d/ {print $9}' | xargs tar cvf archive_name.tar


This tip generously supported by: steve-g@bigfoot.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2054 - August 16, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


GEEK DECODER RING

Ever want to sneek some not
quite politically correct
witticism or other thought
past the "non-technical"?
Or maybe you just want to
un[en|de]code bits, hex or
uu text (boring, but more
practical).

Here's some simple perl
code you can use for a
geek/nerd/dweeb "decoder
ring":

ENCODE INTO BITS, HEX, UU:

perl -ne'$b=unpack("b*",$_);@l=$b=~/.{0,56}/g;
print(join("\n",@l))' <<RM
Tron rules!
RM

Just change the "b*" to "h*"
for hexidecimal or "u*" for
uuencoding.

DECODE FROM BITS, HEX, UU:

perl -ne'chomp;$a.=pack"b*",$_;END{print"\n$a\n\n"}'<<RM
00101010010011101111011001110110000001000100111010101110
00110110101001101100111010000100
RM

I include my favorite
messages that I otherwise
might not write out in clear
text in my signature file along
with the decoder code. It's
enough to scare away most. But,
I've found those technically
superior types get more of a
kick out of "decoding" (cut
and paste to UNIX/LINUX
command line) the message
during their more productive
moments. ;-)


This tip generously supported by: rmuhle@tuxzone.net

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2055 - August 17, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FINDING DISKS W/O ROOT

On a Solaris system, ever want
to know how many disks are attached
but do not have root access?

% ls -al /dev/dsk/*s2 | grep -v c0t6

However you won't know the
size of the disk space?

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2056 - August 18, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


SECURE BACKUPS OVER NET

Securely backup a partition
across a network using dd,
gzip and SSH:

1. The partition to be backed
up must be unmounted.

2. The following does the trick:

dd if=/dev/partition_to_be_backed_up | gzip | ssh user_name@backup.server
dd of=name_of_backup_file.gz

As an example, the following
backs up an image of a floppy disk:

dd if=/dev/fd0 | gzip | ssh user_name@backup.server dd of=floppy.img.gz

3. To restore a backed-up
partition across a network:
(From the backup server)

dd if=name_of_backup_file.gz | gzip -d | ssh user_name@target.server dd
of=/dev/target_partition

To complete our floppy disk example:
dd if=floppy.img.gz | gzip -d | ssh user_name@target.server dd of=/dev/fd0


This tip generously supported by: steve-g@bigfoot.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2057 - August 19, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


SPELL-CHECK WITHIN VI

To spell-check without
leaving a vi session:

:w !spell -b


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2058 - August 20, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


PROTCOLS WITH NETSTAT

Use the command:

% netstat -an

It will show you what ports
are in use on the local and
foreign machines as well as
the protocol running over that
port for that connection and
IP address information. It
also displays the state of
the socket being used.

Using the above tip user can
identify the port to which he
wants to send data is busy
or free.


This tip generously supported by: athresh_2000@yahoo.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2059 - August 21, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


CUT FROM STANDARD COMMANDS

To properly cut the output of
unix standard commands; such
as ls, ps; and properly handle
them without all the extra
spaces, use this:

% ls -lt| tr -s " " | cut -f6-10
% ls -lt| tr -s " " | < --do what ever-- >

tr -s " " ==> here tr in
effect removes all the extra
formatting extra spaces
introduced by unix shell,
for display, and translates
in to format easy to work
with.

If we dont use this tr, then
the -c option of cut will be
unreliable because of varying
size field lengths in the
output and also -f option
will be unreliable because of
extra formatting delimiters.

ls -lt | tr -s " "
ps -ef | tr -s " "

gives us proper output to
properly extract data or
columns.

This tip generously supported by: snlmurthy@yahoo.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2060 - August 22, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


DEMO TO MULTIPLE TERMINALS

Ever want to show multiple
people what you are doing in
a shell.

In the shell doing the demo
type:

% csh -i |& tee /tmp/demo
or
$ csh -i 2>&1 | tee /tmp/demo

In the other shells that are
going to watch the demo type:

% tail -f /tmp/demo


That's it!


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2061 - August 23, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


STAT FOR THE INODE

The stat command is available
on newer flavors of Unix and
linux to provide inode
information about a file.

% stat /etc/hosts

File: "/etc/hosts"
Size: 1348 Filetype: Regular File
Mode: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/
root)
Device: 3,2 Inode: 294992 Links: 1
Access: Tue Aug 21 15:06:19 2001(00000.00:00:00)
Modify: Wed Aug 30 09:19:35 2000(00356.05:46:44)
Change: Wed Aug 30 09:19:35 2000(00356.05:46:44)

It also provides other useful
information about files.

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2062 - August 24, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


NICE NOT SO NICE

Nice is nice, but it
isn't so nice sometimes
on foreground jobs.

The reason, if the system
gets really busy your
terminal session could hang
waiting to get more CPU
time.

It is possible that killing
the job becomes impossible
on a very system, since
the CPU may never give the
process enough CPU time to
recognize the kill signal
waiting.

Using nice on an interactive
program, like vi, could
also be a bad idea.

So play nice, with nice.

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2063 - August 25, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


RENICE CPU HOGS

have you ever wanted to
automatically force a
process that uses up
most of the CPU.

renice 20 `ps -augxww | sort -rn +3 -4 | head -1 | awk '{print $2}'`

Note: Check your 'ps'
command. Your arguments
may differ.

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2064 - August 26, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


TERMINAL RESET

To reset your terminal after
accidently opening a binary
file you can use the
following command:

# tput sgr0

This is supported on Solaris.
I haven't verified on other
SVR4 flavors.


This tip generously supported by: chris.penland@sbs.siemens.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2065 - August 27, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


DID IT REBOOT?

If you believe your users
like to reboot their systems,
here is a way you will be
able to detect it.


#!/bin/ksh
#
# Boot Notification Script
# /etc/rc2.d/S99notify - Sends e-mail notification to the
administrators
# when the system is booted.
#

#*****************************************************************

PATH=/usr/sbin:/usr/bin

DATE="`date`"

SRVNM=`uname -n`

# The next variable can be set for multiple addresses
# (i.e. jsmith@yahoo.com,jsmith@hotmail.com)
MAILADD=monitor

mail $MAILADD <<EOF
From: $0
To: $MAILADD
Subject: Boot of $SRVNM

$DATE

$SRVNM has booted up.

If this is news to you, please investigate.

EOF

exit 0


This tip generously supported by: gideon@infostruct.net
Pal Szabo (System Engineer - T Systems Dataware)

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2066 - August 28, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


RECREATING DIRECTORY TREES

This problem frequently
occurs. There is a machine
with a complex directory
structure, and you want to
have a copy of this directory
tree on another machine.

It is for testing purposes
(for example), and you want
to copy permissions,
UID/GID, and the directory
tree but don't want to copy
user files.

Here is the fastest
solution:
machine_a # cd /mydir
machine_a # find . -depth -print | cpio -o -O /tmp/dir.cpio

Copy the dir.cpio to
another machine.

machine_b # mkdir /mydir ; cd /mydir
machine_b # cat /tmp/dir.cpio | cpio -id


This tip generously supported by: paul@dataware.hu


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2067 - August 29, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


ROTATE THE ALPHABET

Rot13 simply rotates any
alphabet characters but 13
places, so the letter 'a'
becomes a letter 'n', and
an 'x' becomes a 'k' etc...

To encode a file type:

% rot13 <filename>

And repeat to decode.

(Note original file is
overwritten by encrypted
version.)

Simply create this small
script, and save with the
filename of 'rot13'
remembering to set
appropriate permissions.


#!/usr/local/bin/bash

tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]' < $1 1>temp1;

mv temp1 $1;


This tip generously supported by: dan.mcgrath@virginmobile.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2068 - August 30, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


ACCIDENTS WITH CRONTAB

Ever typed the crontab
command and forgot
the -l option?

That's kinda dangerous,
for if you hit ctrl-D
to get back to the
prompt, your crontab's
gone.

To prevent this, make a
script with the following
contents:

#!/bin/ksh
if [[ $# -eq 0 ]] ; then
echo "crontab: no option specified. Aborted."
exit 2
else
/usr/bin/crontab "$@"
fi


Make sure the script is
executable and put it in
a directory that's in your
PATH BEFORE the /usr/bin
directory.

Now if you type crontab
without option or filename,
you'll just get an error
message. If you want to pipe
some stuff to crontab, you
still can do it like this:

% somecommand | crontab -


This tip generously supported by: kees.couprie+ugu@swift.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2069 - August 31, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


SPLIT SCREEN EDITING

You can split screen
into multiple windows
in vi.

(Depending on your
version of VI)

TO create the empty
window enter the
command:

:new

TO move between the
screens use the
commands:

To Move to lower window
<ctrl-w>j

Move to upper window
<ctrl-w>k

TO make the current
window the only window
on the screen closing
all other windows,
use:

:only


VIM supports this
feature and can be
found at: http://www.math.fu-berlin.de/~guckes/vim/

This tip generously supported by: mailalokagg@yahoo.co.in


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2070 - September 1, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


LINE # OF A PATTERN

If you are finding a
particular pattern in
a file and want to know
in which line no. it is
present then give this
command.

grep -n "pattern" <filename> | cut -d":" -f1

e.g. Finding hello in
hello.world file

grep -n "hello" hello.world | cut -d":" -f1


This tip generously supported by: baivab.mitra@citicorp.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2071 - September 2, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


MULTIPLE IP ADDRESSES

Ever wanted to make your
m/c support more than one
IP addresses?

Well, here is the good
old way:

1. To make a machine support
a new (virtual) IP address:

$ ifconfig hme0:1 132.186.67.157 255.255.254.0 132.186.67.255 up

Where:
- First param is hme0 is
the physical name of the
primary interface for your
m/c, (it can be e.g. le0
for other flavours).
':1' is the logical name.
To make it simple, logical
name is kinda branch of the
original. So basically what
your doing with this command
is making hme0 to support one
more IP address on a new
branch named 'hme0:1'.

- Second param is 'new the IP
address'.

- Third and Fourth are netmask
and broadcast address
respectively. Contact your
SysAdm or RTFM. :).

Note: bringing up a virtual IP
address on a node can be
divided in two steps:
1> Create
2> Bring up.
In this case both are done by
this one command.

- Fifth one you know,
don't you?

2. To bring this virtual IP
address down (without
deleting it):

$ ifconfig hme0:1 down

3. To bring this virtual IP
address up agn(hme0:1 has to
exist for this):

$ ifconfig hme0:1 up

4. To delete this virtual
IP address:

$ ifconfig hme0:1 0 down

Note: Assigning 0 as IP
address, deletes it.

IMPORTANT: All of these commands
requires root permission. If
user with lower authority try
to do this, the result may not
be good.

(manuals say problems arising
from that can be tough to
diagnose)

Wondering about where to
use it: We're using this in a
cluster environment to give
client only one IP address
which we make sure is always
up n running on one of the
nodes.


This tip generously supported by: bhatt.kashyap@blr.spcnl.co.in

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2072 - September 3, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FILES OPENED BY A PROCESS

This is supported on Sun
Solaris, not too sure about
other Unix flavours.

I badly wanted to find out
all the files opened by
a process, and that is
when I found pfiles.

Usage :
/usr/proc/bin/pfiles <pid>

Where pid is the process-id
of the process.

It lists the inode numbers
of all the files, opened
by that process.


This tip generously supported by: mdhar@miel.mot.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2073 - September 4, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


MAINTAINING LOG AND TMP FILE

If you need to maintain an
application that generate
a lot of logfiles or tmp
files with running numbers
as part of the filename and
uses a common extension.
These two command together
will help to maintain it
for a window of time.

It compress those files that
are more than 24hrs and
have it remove after 120hrs.
You need to put it in
daily cron.

find $LOGDIR -name '*.ext' -mtime +0 -exec compress {} \;
find $LOGDIR -name '*.Z' -mtime +5 -exec rm -f {} \;

You can change the time to
suit your needs and use
wherever compressing utility
you have to save space.
If you need to maintain
directories created by
application here are help;

find $LOGDIR -type d -mtime +0 -exec compress -r {} \;
find $LOGDIR -type d -mtime +5 -exec rm -f {} \

The compression is to save
space while waiting to be
deleted. Application
developers may need to read
these files/directories so
keep those files/directories
for a certain amount of time
before deleting.


This tip generously supported by: tyl@computer.org

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2075 - September 6, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


CHECKING PROCESS MEMORY

Pmap is a tool that prints
out a maaping of process
memory. It can be found at:

/usr/proc/bin/pmap

It is available in Solaris 2.4
ownwards.

Usage is:

/usr/proc/bin/pmap -x 3456

Where 3456 is the process id.

This prints outs the memory
usage associated with the
process id.

This tip generously supported by: ashutosh.varshney@st.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2076 - September 7, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


SUPRESSING BLANK LINES

To suppress the blank
lines in a text file:

sed '/^$/d' <text_file>
awk 'NF>0' <text_file>


This tip generously supported by: M.Nithyanandham@blr.spcnl.co.in

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2077 - September 8, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


PROCESS EXECUTION TIME

To find the execution
time of a process,

The 'time' command
will tell you the answer.
'man time'.

Syntax:
time <executable/command (with arguments)>

For Ex:
$ /usr/bin/time find / -name csh.1 -print

real 1:15.5

(time elapsed between
invocation and
termination)

user 0.3

(time spent in user
process code)

sys 3.3

(time spent in system
code)

The executable/command
is run by the 'time'
as a child process and
then elapsed, user,
system time are reported.
There is a csh version
of 'time'. It will
report the time in
different format.


In Solaris 'ptime' gives
more accurate results.

/usr/proc/bin/ptime command/executable [ arg ... ]

This tip generously supported by: M.Nithyanandham@blr.spcnl.co.in

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2078 - September 9, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FTP WITHOUT PROMPTS

When transferring the
files through FTP, if
you don't want to
answer yes/no for
transferring each file.
Then there are 2 ways
to do that:


1) ftp -i <machine>
or
2) Set the prompt mode to 'off ' in ftp prompt.

ftp> prompt
Interactive mode off.


This tip generously supported by: M.Nithyanandham@blr.spcnl.co.in


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2079 - September 10, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


WHAT TIME IS IT REMOTELY?


To get time on a remote UNIX machine within the same domain,
you can use the command:

% telnet <remote_machine> 13

Trying <IP address>...
Connected to <remote_machine>
Escape character is '^]'.
Fri Aug 27 19:20:27 1999
Connection closed by foreign host.

You can create a handy alias for the following command
to get the remote time:

telnet <remote_machine> 13 | grep :


This tip generously supported by: bhavin@informix.com


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2080 - September 11, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


METAVALUES FROM A SHELL SCRIPT

Getting a file's size, link count or other metavalue in a shell script:

When you want to extract a specific piece of meta information about a
specific file (such as it's size, link count, or one of its time stamps)
you can use the find -printf option and any of the various
%-directives listed in the find(1) man page. Example:

size=$(find some_file -printf "%s" )

(under ksh, bash, and similar shells). Here the $() form
is used as a more readable equivalent to the older `` (back
tick) operator. (Another advantage to the $() is that it
is nestable). To get the user name of the owner of a
file "foo" you could use:

set owner = `find foo -maxdepth 0 -printf "%u"`

(here we're using the csh syntax). This also uses
the -maxdepth option in case "foo" is actually a
directory name; since we don't want find to
spend time traversing directory and printing the
owners to ALL of the entries thereunder. A
maxdepth of zero ensures that this will only print
the detail we want on the specific link that we
named on the command line.

This can be much more flexible than the options provided
by the test command (try to see which of two files is
larger, or if to files are owned by the same user or
assigned to the same group, using just test).

This tip generously supported by: jdennis@linuxcare.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2081 - September 12, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


VULNERABILITIES IN UNIX


Information provided by the Sans Institute:
<A HREF="http://www.sans.org">http://www.sans.org</A>


The ten most commonly exploited UNIX vulnerabilities?

Poor system administration practices

Reusable/poor passwords

Flawed SUID programs (e.g., rdist, binmail)

HTTP servers and CGI application vulnerabilities

Default "+" entries in the /etc/hosts.equiv file

NFS/NIS vulverabilities sendmail program bugs

Buffer overruns (e.g., gets(), syslog())

SUID shell scripts


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2082 - September 13, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


HOW MANY COMMANDS HAVE I RUN?

If you're a csh/tcsh/zsh user, you've seen the supposed feature
that lets you display how many commands you've run in your
prompt:

set prompt="\! %"

The \! (or %h or %! for tcsh) displays not really a current
count of commands run, but the current history event number.

Think of it in those terms, and you'll discover it becomes quite
useful.

For example, how many times have you typed some enormously long
command line, only to have it fail because several other conditions
weren't met?

You spend the next several prompts typing various commands to
get conditions set up just right, and then have to retype the
entire long command.

Or, if it hasn't scrolled off the screen yet, just type ! followed
by the history event number displayed in the prompt for that big
long command. It's that simple:

prompt 23 % command -with some -very +long /argument/list
command: Example command failed.
prompt 24 % cd /to/correct/directory
prompt 25 % rm certain.files
prompt 26 % !23
command -with some -very +long /argument/list
command: Example command succeeds.
prompt 27 %

You can even apply the standard csh modifiers to !<number>. For
example, particularly useful is !<number>:p, which just prints
the command typed on prompt <number> instead of executing it
again:

prompt 26 % !23:p
command -with some -very +long /argument/list
prompt 27 % !!
command -with some -very +long /argument/list
command: Example command succeeds.
prompt 28 %

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2083 - September 14, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


TAKE NOTES AT 3AM

Always keep a notebook of what you do as root. That way,
when you can't remember what you did at 3am (small wonder),
all you have to do is trace your steps back.

This can be kept online as well.

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2084 - September 15, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


BE CAREFUL WITH NIS+

To rebuild your /etc/passwd file use:
nisaddent -rv -f /etc/passwd passwd

HOWEVER, if you perform the above command
you must perform the following command on
the shadow file:
nisaddent -mv -f /etc/shadow shadow

DO NOT USE the nisaddent -rv -f command on
the /etc/shadow file, this command will confuse
replica servers and lock everyone off of a system.

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2085 - September 16, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


KEEP THOSE DAEMONS RUNNING

Here is a script that will keep daemons running
if the decide to die for some unforseen reason.

This tip generously supported by: ken@theglobeandmail.com

-------------------- cut here -----------------

#!/bin/csh
#
# NAME
# keepitup.csh - Keep demons up and running
#
# SYNOPSIS
# keepitup.csh
#
# DESCRIPTION
# If any of the following processes are down, then start them up
# again. This script can be run every few minutes from a crontab.
#
# AUTHOR
# Ken Stevens <kstevens@globeandmail.ca>

foreach daemon ( \
/opt/GIS/apps/EventDispatcher/scripts/EventDispatcher.pl \
/opt/GIS/apps/CatchFTP/scripts/ProcessFTP.pl \
/opt/GIS/apps/NewsHound/scripts/NewsHound.pl \
)

ps -e | fgrep `echo $daemon:t | cut -c1-8` > /dev/null

if ( $status > 0 ) then
echo Restarting $daemon
date
$daemon &
endif

end


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2086 - September 17, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


PROTECT THE ROOT DIRECTORY AT ALL COST

Here is a little extra guard that can be taken if
anyone attempts, or accidentally recursively removes
files inside a directory. If and when it occurs,
the person will constantly be prompted with the
question"are you sure?"

Here is how it works in a safe area:

% cd /usr/tmp
% mkdir foo
% touch /usr/tmp/foo/\-i
% chmod 000 /usr/tmp/foo/\-i

NOTE: Use the fully qualified path to create the
file when creating.

% cd foo
% touch fee fii foo fum
% rm -rf *


Every little bit helps!

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2087 - September 18, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


THE EXECUTION OF FIND

The -exec extension to the find command is a very useful and
flexible utility.

You can use it to get a nice list of all the files in a directory
tree:

find . -type f -exec ll {} \;

or to copy all the files in a directory tree into one, large
directory:

find . -type f -exec cp -p {} /newdir \;

Or say now that you've copied all those files into one directory
there are too many .bak files to delete all at once with the 'rm'
command (yes, that's possible):

find . -name \*bak -exec rm {} \;

There are also bunches of other useful exensions to the 'find'
command. Check out the man page, and you'll find a great tool
for basic sysadmin stuff.

This tip generously supported by: emathias@wwa.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2088 - September 19, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


NULL ROOT PASSWD WITHOUT VI

As admins We never forget the root password,
RIGHT?

Although sometimes we do inherit machines in
which we don't know the root password.

Here is a way to null the root password from
the password file.

It comes a time in every admins life that we
will have to go into mini-root and change the
password file without the use of vi.

The following example shows how to achieve this
on the /etc/shadow file, but the same basic
commands can be achieved on the /etc/passwd file
for those platforms that don't support shadow
passwords.

Use "ed" - and the 13 dots method
---------------------------------
# cp /etc/shadow /etc/shadow.bak
# ed /etc/shadow
1p
s/:.............:/::/
1p
w
q


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2089 - September 20, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


RENAME A LARGE NUMBER OF FILES


This a an oldie but a goodie. There always comes a
time when a large number of files need to be renamed.

Here is one quick way to do it:

=================== cut here ===========================

#!/bin/sh

for i in *
do
echo $i
mv $i `basename $i`.bak
done


 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2090 - September 21, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


INETD.CONF CLEAN UP

In most cases, vendors install the /etc/inetd.conf
file pretty wide open. There are many processes in
this file that do not have to be running.

One good way to improve the systems performance is
to not run the unnecessary daemons.

If you do not plan to offer or run those
services, then comment them out and restart
inetd daemon.

Here is a list of the less common daemons, that
can turned off on workstations (Servers may
require some of these daemons).

finger
uucp
http
bootp
dhcp_bootp
tftp
ntalk
walld
...etc...

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2091 - September 22, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


UPGRADING OPERATING SYSTEMS

There are many cases where a vendor will tell you
that with each new upgrade of the operating system
one does not need to wipe the disk clean.

Whenever possible, and given the chance, wipe
clean the system disk with a "newfs" or "mkfs",
depending on your unix flavor.

If a version number leaps an entire number
for example, Version 5.3 -> version 6.2, it
is highly recommended that the disk be wiped
clean. In some cases it can be safe to
upgrade without wiping a system disk if the
version is not a full leap for example,
Version 5.2 -> Versions 5.3

Past history has shown that in some cases the
following could happen if a system disk wasn't
wiped clean first:

1) New versions mixed with older patches can
cause the system to become unstable.

2) Old configuration files are not compatible with
the newer O.S.

3) Some 3rd party software or device drivers wouldn't
be compatible.

4) Loss of unknown modified system files.

5) The new kernel will not be able to compile sometimes.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2092 - September 23, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


UMOUNT BUSY DEVICES

The "umount" command unmounts a currently
mounted filesystem, which can be specified either
as a mounted-on directory or a filesystem.

If a mount point is busy, there are a couple
things to try:

On some non-BSD based machines you can use the
command "umount -k" to force the system to drop a
busy device.

# umount -k /hosts/foo

If you are on a standalone system or none of the
filesystems are being exported, then "cd /" in
all open shells or windows and umount.

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2093 - September 24, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


LOCK THAT FILE DOWN

Sometimes you want to make a file very very secure.

To do this, change the permissions to 000

# chmod 000 [file]

No one except root will be able to access it.
Even the owner will have to change the
permissions to be able to do anything to it.

Although It's like a red flag that says..
"I'm an important file"


NOTE: DO NOT EVER DO THIS TO THE /etc/passwd FILE!

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2094 - September 25, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


JUST THE DIRECTORIES

It useful to be able to list all directories in
the current directory without any of the files.

ls -l | grep "^d"

Alias it by adding this in your .login
or .profile or .cshrc files in your home directory:

alias dir 'ls -l | grep "^d"'

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2095 - September 26, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


KILL A USER, IN THE UNIX SENSE

DISCLAIMER: UGU is not telling you to kill your users.
If you so choose to it is at your own discretion and you
are doing it at your own risk.

Although we all have that ONE USER...

To kill all the processes associated with a particular user
simply:

# kill -9 `ps -aef|grep jondoe |awk '{ print $2 }'`

If you want to be a nice admin, tell him first.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2096 - September 27, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


KEEP THE USERS OFF WITH NOLOGIN

There is a way to disable any new login attempts into a
system. This can be achieved by simply creating a file
called /etc/nologin.

It can have a null file size or a message can be
placed into the file informing the status of the
system. If a user attempts to login remotely, a
message will display with contents of the
/etc/nologin file, and then disconnect the user.

However, ftp connections are not affected by this, if
ftpd is running.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2097 - September 28, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FIND THE HOG

Hot Tip for Space Cops: (aren't we all?)

If your users keep using up all the space in your home directory,
here is a way to apprehend the top offenders.

cd /home
du -ks *|sort -nr|pg

(Note: The "k" option may not be necessary in non-posix systems.)
This string will show you all the directory sizes in order,
largest first. Now if you are going to do a little cleanup yourself,
in one of those directories run:

ls -ls|sort -nr|pg

This will list files by size largest first. That way when you do your
compress,
move, or remove, you may actually reclaim a significant amount of space.

This tip generously supported by: uspncjpf@ibmmail.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2098 - September 29, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


COLLECTING FILES

NOTE: Depending on how the command is used, an
admin with root can abuse their privileges.

If there are similar files on a system and you wish
to collect the contents of those files (possibly
for security reasons) the following command
will search a system for a filename and output
the contents into a file to be viewed.

# find / -name .rhosts -perm -004 -print > rhosts 2>e &

Another use was brought up that one could
learn what other commands users use. They
may have thought of some tricks you may not have:

# find / -name .bash_history -perm -004 -print >o 2>e &



 




Click here to send an email to the editor of this weblog.
© Copyright 2002 Raj Patel.
Last update: 8/1/02; 12:07:50 pm.


Archives Pictures Information Links News Home