LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
LinkBack Search this Thread
Old 11-28-2012, 12:26 PM   #1
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,778
Blog Entries: 4

Rep: Reputation: 282Reputation: 282Reputation: 282
Where to set root's prompt ?


Hello friends,
I have a Solaris 10 machine and I want to permanantly set root's prompt. By default it gives me "#" prompt for root. I couldn't find any .profile or .login or any shell initialization such as .bashrc or .cshrc file in root's home i.e. in "/".
I tried appending the prompt command in /etc/profile but it also worked only for cureent session. But it returns to # after openning new terminal.
Please suggest where to define root's prompt?
Thanks in advance!

Last edited by shivaa; 11-28-2012 at 12:27 PM.
 
Old 11-28-2012, 01:31 PM   #2
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: /root
Distribution: Slackware & BSD
Posts: 1,203

Rep: Reputation: 229Reputation: 229Reputation: 229
Quote:
I couldn't find any .profile or .login or any shell initialization such as .bashrc or .cshrc file in root's home i.e. in "/".
I tried appending the prompt command in /etc/profile but it also worked only for cureent session. But it returns to # after openning new terminal.
Try if you can find a PS1 at /etc/bashrc. If none then look from /etc/skel/.bash_profile. If none then force to use your own at /etc/skel/.bashrc_profile by creating it.

IIRC in my slackware a root from su uses a PS1 @ /etc/profile, and a root from login uses /root/.bashrc.

Hope that helps.

Good luck.

Last edited by malekmustaq; 11-28-2012 at 01:34 PM.
 
Old 11-28-2012, 01:49 PM   #3
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: /root
Distribution: Slackware & BSD
Posts: 1,203

Rep: Reputation: 229Reputation: 229Reputation: 229
Or try find it either from your ~/ or /etc.

Quote:
~ $ sudo find -L /etc \( -name "bash*" -o -name "*profile" \)
Hope that helps. Good luck.
 
Old 11-28-2012, 02:08 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
root is not often configured to use bash on Solaris. It usually stays with its default shell which is /sbin/sh and is sometimes configured to use ksh, especially on Solaris 10. Solaris 11 finally use a POSIX shell for root.

/etc/profile or /.profile are correct places to set the prompt, please post what you wrote there and make sure PS1 is exported.
 
Old 11-28-2012, 02:21 PM   #5
wpeckham
Member
 
Registered: Apr 2010
Location: USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix
Posts: 739

Rep: Reputation: 169Reputation: 169
full of hot air here...

I do not use OpenSol myself, so I may be terribly full of it, but if it helps....

1. Generally / is not the root home folder on most Unix variants. More likely /root is the root home. If you have a .profile there you can use that to set the prompt.

2. Otherwise, look for a block in the /etc/profile that checks the UID and takes different actions if it is over or under some value. (Generally 500 or 1000.) Add your setting of the prompt to the block that includes LOW numbers.

3. Test. If that does not work, check back on later parts of the same file and/or login process to see if the value is being overwritten later. IF so, you might need to add later code and undo the earlier changes.

Obviously changing the thing found LAST in the process is better, so creating or modifying .profile in the root home is the preferable option. Earlier changes may be overwritten during upgrades or maintenance events, or may have consequences for other processes, users, or accounts.
 
Old 11-28-2012, 04:55 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Quote:
Originally Posted by wpeckham View Post
I do not use OpenSol myself
OpenSol (actually OpenSolaris) was discontinued a couple of years ago. The question here is about Solaris 10.
Quote:
1. Generally / is not the root home folder on most Unix variants. More likely /root is the root home.
While this is correct for most Gnu/Linux and *BSDs distributions, root has / as its home directory by default on Solaris, just like it does with AIX and HP-UX.
Quote:
2. Otherwise, look for a block in the /etc/profile that checks the UID and takes different actions if it is over or under some value. (Generally 500 or 1000.) Add your setting of the prompt to the block that includes LOW numbers.
You might won't find such code. Having userid 0's prompt being # and all other users being $ is hardcoded in the bourne shell. Moreover, if you switch to root by using su, the default prompt is reset to "# ".
 
Old 11-30-2012, 10:24 AM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,778
Blog Entries: 4

Original Poster
Rep: Reputation: 282Reputation: 282Reputation: 282
Thanks everyone for your responses, here's summery what I've tried so far:
1. There are no /etc/.bashrc or /etc/bashrc files existing.
2. There is no /etc/.profile, but /etc/profile exists there.
3. In root's home (apparently it is "/" only), there is no .bashrc or .profile.

So in the meantime, I appended following in /etc/profile:
Code:
# Personalization
shell=`echo $SHELL`
if [ $shell -eq "/sbin/sh" ]; then
setenv PS1 "$USER{`pwd`}\!:"
elif [ $shell -eq "/bin/bash" ] 
PS1="$USER{`pwd`}\!:"
export PS1
fi
But it also couldn't help, neither after sourcing /etc/profile nor when open a new terminal

4. I manually created /.bashrc and just added:
Code:
PS1="$USER{`pwd`}\!:"
export PS1
And when I switch shell to bash (just invoked bash cmd), .bashrc comes into effect & prompt get set properly & no issues with it.

So now quesiton is, what's initialization file for /sbin/sh shell? and is there any file which comes into effect before /etc/profile or /etc/.login to set root's prompt to "#"?

Last edited by shivaa; 11-30-2012 at 10:56 PM. Reason: Info added
 
Old 11-30-2012, 10:43 AM   #8
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: /root
Distribution: Slackware & BSD
Posts: 1,203

Rep: Reputation: 229Reputation: 229Reputation: 229
Quote:
So now quesiton is, what's initialization file for /sbin/sh shell? and is there any file which comes into effect before /etc/profile or /etc/.login to set root's prompt to "#"?
To trigger /bin/sh as default shell use 'export'.

Does the /etc/profile get honored? Use your block to take "#" into effect: manipulate the setenv and elif lines:

Code:
# Personalization
shell=`echo $SHELL`
if [ $shell -eq "/sbin/sh" ]; then
setenv PS1="$USER{`pwd`}~# "
elif [ $shell -eq "/bin/bash" ] 
PS1="$USER{`pwd`}~# "
export PS1
fi
Hope that works.

Good luck.

Last edited by malekmustaq; 11-30-2012 at 10:46 AM.
 
Old 11-30-2012, 12:47 PM   #9
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,778
Blog Entries: 4

Original Poster
Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
To trigger /bin/sh as default shell use 'export'.
@malekmustaq: Please specify... Where? I want to set prompt for root user for his default /sbin/sh shell and want to know why it's not setting even after modifying /etc/profile. And now I am sure, there comes some other file into effect which takes over /etc/profile.

Also one more thing, when I open a terminal and do:
Code:
# echo $PATH
/usr/sbin:/usr/bin:/usr/openwin/bin:/usr/usb
# which setenv source export
no setenv in /usr/sbin /usr/bin /usr/openwin/bin /usr/usb
no source in /usr/sbin /usr/bin /usr/openwin/bin /usr/usb
no export in /usr/sbin /usr/bin /usr/openwin/bin /usr/usb
And then if I invoke tcsh or bash, and do:
Code:
# tcsh
# echo $PATH
/usr/sbin:/usr/bin:/usr/openwin/bin:/usr/usb
setenv: shell built-in command
source: shell built-in command
export: Command not found
Could you understand, why this wierd behaviour since PATH variable is same in both cases?

Last edited by shivaa; 11-30-2012 at 12:53 PM.
 
Old 11-30-2012, 03:42 PM   #10
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Quote:
Originally Posted by shivaa View Post
I want to set prompt for root user for his default /sbin/sh shell and want to know why it's not setting even after modifying /etc/profile.
Because what you added in /etc/profile is partially incorrect and has no effect, outside perhaps an error message.

This what you might use:

Code:
export PS1
if [ $SHELL = /sbin/sh ]; then
PS1="This is root's prompt # '
else
PS1="This is everyone else's prompt \$ '
fi
 
Old 11-30-2012, 10:47 PM   #11
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,778
Blog Entries: 4

Original Poster
Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Because what you added in /etc/profile is partially incorrect and has no effect, outside perhaps an error message.
Does changing the prompt message make any difference? I don't think so. I have tried what you suggested, but it also couldn't help.
Anyway, what I can conclude is, /etc/profile comes in effect first and takes over .bashrc for all types of users. If prompt is not set in /etc/profile, then it consults .bashrc for the same.

As a workaround I changed root's shell (in /etc/passwd) to /bin/bash and then it's working fine and using .bashrc & prompts cmd set in it. But I guess this could cause many other environment related problems for root. So this is temporary.
 
Old 11-30-2012, 11:31 PM   #12
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: /root
Distribution: Slackware & BSD
Posts: 1,203

Rep: Reputation: 229Reputation: 229Reputation: 229
Do you have a local init script that loads automatically? Usually in Slackware it is located at /etc/rc.d/rc.local, this is the place where we can load some environment specifications or run scripts via init. If you have it in the /etc then set your export block there. But be sure that the tcsh is truly installed not just a link to /bin/bash. Check your shell availability first.

I'm sorry I already forget how it was when I was running Solaris, it was merely a brief time; when Sun sold open sol to Oracle I deinstalled and tried to forget everything. Solaris is the best unix I think; but I have natural allergy to copyrights .

Hope that helps.

Good luck.
 
Old 12-01-2012, 04:27 AM   #13
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Quote:
Originally Posted by shivaa View Post
Does changing the prompt message make any difference? I don't think so.
I don't get what you mean here. Changing PS1 should definitely make a difference.
Quote:
I have tried what you suggested, but it also couldn't help.
What do you mean it couldn't help ?
Quote:
Anyway, what I can conclude is, /etc/profile comes in effect first and takes over .bashrc for all types of users.
This is incorrect. .bashrc is ignored when root is configured to use its default shell (/sbin/sh). When a user's shell is bash, .bashrc is processed after /etc/profile for login shells. Non login shell are not processing /etc/profile.
Quote:
If prompt is not set in /etc/profile, then it consults .bashrc for the same.
This is incorrect, if you are running bash, whatever set in .bashrc rules.
Quote:
As a workaround I changed root's shell (in /etc/passwd) to /bin/bash and then it's working fine and using .bashrc & prompts cmd set in it. But I guess this could cause many other environment related problems for root. So this is temporary.
There is actually no serious risk changing default root shell. I often switch it to ksh on Solaris 10. In any case, you could have let the shell to be /sbin/sh and create a /.profile file with your customizations here. That would have worked for both login and non login shells which seems to be your initial issue.

Last edited by jlliagre; 12-01-2012 at 05:02 AM.
 
Old 12-01-2012, 04:33 AM   #14
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Quote:
Originally Posted by malekmustaq View Post
Do you have a local init script that loads automatically? Usually in Slackware it is located at /etc/rc.d/rc.local, this is the place where we can load some environment specifications or run scripts via init.
Beware not to confuse further the OP. There is no rc.local with Solaris and PS1 is not set by any init scripts.
Quote:
But be sure that the tcsh is truly installed not just a link to /bin/bash.
I don't think the OP ever mentioned tcsh. Linking it with /bin/bash would be a very bogus idea. In any case, tcsh doesn't make use of /etc/profile or .profile. It uses files named .login and .cshrc.
 
Old 12-01-2012, 11:48 AM   #15
wpeckham
Member
 
Registered: Apr 2010
Location: USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix
Posts: 739

Rep: Reputation: 169Reputation: 169
conditionals

What was the root shell before you hanged it?
I would expect it to be /bin/sh, but you should know.

If it is the posix shell, or another shell acting in posix mode, you should be able to CREATE a file in the folder that root logon lands you, named .profile. On that folder set PS1 and then export it. I would not get complex here, just two simple lines should do the job.
Code:
PS1='..>'
export PS1
for example.

(Note: on some systems /bin/sh is really a link to bash, ksh, or another shell. When called this way they should behave in posix mode, but the degree to which this is constrained varies. In reality they all act differently: the shell man pages should be your definitive guide.)

You will NOT find export in your path, it is a shell internal. Some shells implement commands that CAN be found in the path with internal equivalents that either run faster, behave better, have added functionality, or all of the above. Seeking them in your path really does nothing useful for you. To complicate things even more, different shells often implement different internals. Here again, your man pages should guide you.

BTW: export makes environment variables more generally available to called processes and sub-processes, it has NOTHING to do with changing your default shell. I am not sure where that idea originated.

Last edited by wpeckham; 12-01-2012 at 11:54 AM.
 
  


Reply

Tags
prompt, root


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
grub 2 - when / why I need both in grub.cfg ; set root= and search ... --set=root ... masuch Linux - Newbie 5 07-19-2012 03:41 PM
IRAF prompt cl - how do I set up key bindings? keflavich Linux - Software 1 12-18-2009 08:11 AM
[SOLVED] set timeout for ssh prompt vikas027 Programming 2 04-22-2008 03:35 PM
How to set tcsh prompt: # for root and % for user? robson Linux - Newbie 1 10-12-2003 03:13 PM
how set system time by command prompt? yenonn Linux - Newbie 9 08-25-2003 06:40 PM


All times are GMT -5. The time now is 01:33 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration