1850321 Members
2667 Online
104054 Solutions
New Discussion

Paging Bill Hassell

 
SOLVED
Go to solution
MarkSyder
Honored Contributor

Paging Bill Hassell

Bill,

You advised someone yesterday to alias rm and similar commands to prevent disaster. I had nothing to offer to that poor person, and found myself thinking "There but for the grace of God go I". I have taken your advice, but as I did not make the original post cannot give you any points on it.

Put a post on here, even if it's only a full stop, and I'll give you 10 points for helping me to prevent a future disaster!

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
16 REPLIES 16
Pete Randall
Outstanding Contributor

Re: Paging Bill Hassell

Mark,

(Pardon me for butting in!).


I've got two tips for you:

1) To help avoid a situation like the one in the thread yesterday (running rm -rf when the person *thought* they were in /tmp), I put the pwd in root's prompt, like this:

export PS1="`hostname`$PWD:`whoami`# "
tsws1/tmp:root#


2) I doubt Bill will come to collect his bounty. He's not in this for the points. If he was, we would all be chasing him.


Pete

(A big fat zero would be perfect, thanks)

Pete
Bill Hassell
Honored Contributor
Solution

Re: Paging Bill Hassell

An adapted quote:

"There are only two types of system administrators: those that have lost critical files and directories, and thos that are going to"

The 'dangerous' commands and moving root's home directory are standard procedures for me when setting up new systems (and fixing old ones). I like the idea that someone checks your work before you actually type rm. Another very important tool is sudo, freely available from the Liverpool archive. With it, you can eliminate the need for giving out the root password as well as preventing users from accessing dangerous commands. You can even limit the valid parameters allowed for a command (like mount or umount).

I'll be giving an all day sysadmin seminar at HP World this year where I'll cover these tips and a bunch more. http://www.hpworld.com/conference/hpworld2004/about.html


Bill Hassell, sysadmin
Steven E. Protter
Exalted Contributor

Re: Paging Bill Hassell

Watch me closely as I do a Bill Hassell Imitation.

No, I will not be shaving off my hair!

alias

I get this.

autoload='typeset -fu'
command='command '
functions='typeset -f'
history='fc -l'
integer='typeset -i'
local=typeset
ls=/usr/bin/ls
nohup='nohup '
r='fc -e -'
stop='kill -STOP'
suspend='kill -STOP $$'
type='whence -v'
vi=/usr/bin/vi


alias -x rm='/usr/contrib/bin/reallyrm'

the script in /usr/contrib/bin can have reminders prompts, warnings and explanations of doom.

Pete's Suggestion Deserves 10 points. it can be set in the /.kshrc file

and

ENV=/.kshrc in /etc/profile

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: Paging Bill Hassell

I missed the original Bill while testing my alias command.

I like the original better.

All said was meant in good humor.

Hi Bill.

Good Luck,

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ralph Grothe
Honored Contributor

Re: Paging Bill Hassell

Sorry, for interfering your thread.
But I had to smile reading Bill's quote.
I think to have heard sometime this slightly modified version:

There are two types of motorbikers.
Those who have fallen, and those who will fall.
Madness, thy name is system administration
Pete Randall
Outstanding Contributor

Re: Paging Bill Hassell

Boy! Bill just loves to prove me wrong!!

(Lucky for him I give him so many opportunities)



Pete

(0, thanks)

Pete
MarkSyder
Honored Contributor

Re: Paging Bill Hassell

Pete,

I've been using something very similar to your PS1 command ever since I came here 10 months ago. It works fine till I change directory - the prompt doesn't change with me! Any ideas how to fix this? If you have, it's worth more than a big fat zero!

Strangely enough, exactly the same command worked the way I wanted it to on AIX systems (i.e. the prompt changed when I changed directory).

Even if I do get the prompt working, I will still be using Bill's aliases. Every day I use the find command to locate a file (not the same file - my memory's not that bad!) via find / -name etc. I also sometimes tidy a directory of old files via find . -mtime +7 etc.

How easy would it be to type find / when I mean to type find .? Too easy for comfort!

Incidentally, the aliases I have set up are del for rm -i and move for mv -i - I may one day want to use rm without the -i: but only when I'm 100% certain I'm in the right directory.

Mark
The triumph of evil requires only that good men do nothing
Jakes Louw
Trusted Contributor

Re: Paging Bill Hassell

PS1="servername":$PWD)
Trying is the first step to failure - Homer Simpson
MarkSyder
Honored Contributor

Re: Paging Bill Hassell

Thanks Jakes.

I've tried that and it's just the same result - works fine till I change directory.

Mark
The triumph of evil requires only that good men do nothing
Mark Grant
Honored Contributor

Re: Paging Bill Hassell

Try this Mark

PS1="$(hostname):\$PWD "

Never preceed any demonstration with anything more predictive than "watch this"
MarkSyder
Honored Contributor

Re: Paging Bill Hassell

Mark,

A Spinal Tap answer!

Come back and I'll give you another point - it's worth 11 out of 10!

Mark

PS - if anyone doesn't understand the Spinal Tap reference, do yourselves a favour and rent the film. It's brilliant.
The triumph of evil requires only that good men do nothing
Jakes Louw
Trusted Contributor

Re: Paging Bill Hassell

Which shell are you running as default?

I've tested this on Bourne and Korn, and it works OK.

Try this one:

export PS1='hostname':`$PWD) `

(the set of parentheses around PWD are obviously for command substitution).
Trying is the first step to failure - Homer Simpson
Pete Randall
Outstanding Contributor

Re: Paging Bill Hassell

Mark,

You need to set the PS1 prompt in your shell's rc file (.shrc, .kshrc, etc.).

export PS1='$PWD # '

That should do it (I think).


Pete

Pete
MarkSyder
Honored Contributor

Re: Paging Bill Hassell

Thanks everyone.

Mark's suggestion worked, so I don't need to try any others.

Jakes - I'm using korn shell and exactly the same command worked the way I wanted it to when I used AIX. Strange but true.

Pete - I've reluctantly agreed to a 0 for your second posting, but generally if someone has helped, or even tried to help but failed, I give them credit for it.

Mark
The triumph of evil requires only that good men do nothing
Bill Hassell
Honored Contributor

Re: Paging Bill Hassell

The key for PS1 to change PWD is to use single quotes rather than double quotes. The double quotes enclose a string BUT $ parameters are expanded before being assigned to PS1. By using single quotes, nothing is changed and $PWD is sent as is to PS1, thereby allowing the shell to expand it when it is displayed (realtime retrieval of $PWD). Here's a more interesting PS1 (for .profile) which gives you the machine or the user login and the last 2 directories for PWD:

# Terminal character enhancements

export HB=$(/usr/bin/tput dim) # dim text
export HV=$(/usr/bin/tput smso) # 1/2 bright inverse
export IV=$(/usr/bin/tput bold) # inverse
export UL=$(/usr/bin/tput smul) # underline
export BL=$(/usr/bin/tput blink) # blink
export EE=$(/usr/bin/tput sgr0) # end all enhancements

# Some terminal do not have half-bright inverse
# so substitute underline


if tput smso > /dev/null
then
HVUL=$HV
else
HVUL=$UL
fi
HOST=$(hostname)
USER=$(id -un)
PS1='$HVUL$USER $IV${PWD##${PWD%/*/*}/}$EE # '
PS1='$HVUL$HOST $IV${PWD##${PWD%/*/*}/}$EE # '

Pick the first PS1 to show the user login, the second to show the machine name. This code works on all terminals and emulators as long as $TERM matches the terminal. I've attached a simple demo script that shows some of your terminal's display enhancements.


Bill Hassell, sysadmin
MarkSyder
Honored Contributor

Re: Paging Bill Hassell

Thanks Bill.

That file looks very useful. I've saved it to hard disc for future use.

Mark
The triumph of evil requires only that good men do nothing