Linux 版 (精华区)
发信人: netiscpu (说不如做), 信区: Unix
标 题: [M] su root 运行的两个常见问题
发信站: 紫 丁 香 (Sat May 23 20:09:04 1998), 转信
本文摘自Linux-Admin Mailling-List.
[问题] su root environment, xterm titles
Here's two for the FAQ, one of which I know
has been discussed here, and one I haven't seen before.
I don't have answers; that's what I'm looking for. ;-)
Question 1:
I added a "Root Shell" entry to my menu in
WindowMaker. What it does is execute the command
`xterm -e su` (Note I symlink xterm -> rxvt). The problem
is *your* environment is still remembered. What I want
is to have this window have the exact same properties as
if I logged in as root. I want the same $PATH, etc. so
everything in sbin is easily accessible, "." is removed from
the path, etc. What is the best way to do this?
Question 2:
How do I get my xterm (rxvt) to display the currently
running program with options (or any arbitrary string)
in the title bar with the title bar automatically updated
with each command. I do know how to set this when the
window is created (ex: the "Root Shell" described above
has "Root Shell" in the title bar, but the title bar never
changes). I know this has been discussed here before,
so I plan on checking the archives, but if someone has
a quick answer for me, I'd appreciate the tip.
Thanks!
~Patrick
[回答1]
I believe su can take an argument '-' which will load the environment
files of the requested user. So 'su -' will give you root access and load
all of root's settings.
> Question 2:
> How do I get my xterm (rxvt) to display the currently
> running program with options (or any arbitrary string)
> in the title bar with the title bar automatically updated
> with each command. I do know how to set this when the
> window is created (ex: the "Root Shell" described above
> has "Root Shell" in the title bar, but the title bar never
> changes). I know this has been discussed here before,
> so I plan on checking the archives, but if someone has
> a quick answer for me, I'd appreciate the tip.
>
I found these commands in O'Rielly & Associate's csh tcsh book:
alias settitle 'echo -n "ESC]2;\!*^G"'
alias seticon 'echo -n "ESC]1;\!*^G"'
alias setall 'settitle \!* ; seticon \!*'
They allow you to change the title's of the window. Make sure you get the
escape characters ok. It's escape control-] I'm not sure if this will
work with (ba)sh since that's the default shell for root.
----------------------------------------
__ ||
[|-dmund L_]au
`-
() _
[]nformation & ((omputer ((cience
''
_ ()
|U|niversity of ((alifornia, []rvine
`-'
[回答2]
xterm -e su -
--
Rob Riggs Devil's Thumb Entertainment
Network Administrator Boulder, CO - (303) 938-1200
rob@DevilsThumb.COM http://www.DevilsThumb.COM/~rob
"The notion of errors is ill-defined." - IRIX 'netstat' man page
[回答3]
Give the `-l' flag to su. From the su manpage:
-, -l, --login
Make the shell a login shell. This means the fol-
lowing. Unset all environment variables except
`TERM', `HOME', and `SHELL' (which are set as
described above), and `USER' and `LOGNAME' (which
are set, even for the super-user, as described
above), and set `PATH' to a compiled-in default
value. Change to USER's home directory. Prepend
"-" to the shell's name, to make it read its login
startup file(s).
> Question 2:
> How do I get my xterm (rxvt) to display the currently
> running program with options (or any arbitrary string)
> in the title bar with the title bar automatically updated
> with each command. I do know how to set this when the
> window is created (ex: the "Root Shell" described above
> has "Root Shell" in the title bar, but the title bar never
> changes). I know this has been discussed here before,
> so I plan on checking the archives, but if someone has
> a quick answer for me, I'd appreciate the tip.
I don't know about rxvt, but for an xterm, put the following into your
~/.bashrc:
function settitle
{
title="`whoami`@`hostname`:`pwd`"
echo -n " 2;$title" > /dev/tty
}
case $TERM in
xterm)
PROMPT_COMMAND=settitle
;;
esac
--
Glynn Clements <glynn@sensei.co.uk>
[回答4]
If you want not to change user, but become user, use 'su -' instead of 'su'
>Question 2:
>How do I get my xterm (rxvt) to display the currently
>running program with options (or any arbitrary string)
>in the title bar with the title bar automatically updated
>with each command. I do know how to set this when the
>window is created (ex: the "Root Shell" described above
>has "Root Shell" in the title bar, but the title bar never
>changes). I know this has been discussed here before,
>so I plan on checking the archives, but if someone has
>a quick answer for me, I'd appreciate the tip.
You can use the following script :
===
#!/bin/sh
echo -ne "\033]2;"$@"\7\033]1;"$@"\7"
exec $@
===
Arguments you'll give to the script will be put in xterm title and
then executed.
Bye.
--
If you continually give you will continually have.
--
With best of best regards, Pawel S. Veselov (aka Black Angel)
Internet e-mail : vps@mindless.com
Web page : http://www.math.spbu.ru/~vps/ | ICQ UIN : 5252265
[回答5]
For bash I did this as follows :
[vps@phoenix]~$ type winicon
winicon is a function
winicon ()
{
echo -ne "\033]1;$1\7"
}
[vps@phoenix]~$ type wintitle
wintitle is a function
wintitle ()
{
echo -ne "\033]2;$1\7"
}
[vps@phoenix]~$ type winname
winname is a function
winname ()
{
echo -ne "\033]2;$1\7\033]1;$1\7"
}
Bye.
--
If you continually give you will continually have.
--
With best of best regards, Pawel S. Veselov (aka Black Angel)
Internet e-mail : vps@mindless.com
Web page : http://www.math.spbu.ru/~vps/ | ICQ UIN : 5252265
[完]
--
Enjoy Linux!
-----It's FREE!-----
※ 来源:.紫 丁 香 bbs.hit.edu.cn.[FROM: mtlab.hit.edu.cn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.402毫秒