On Wednesday 20 February 2013 20:01, Bill McCormick conveyed the
following to alt.os.linux.debian...
> On 2/20/2013 10:47 AM, Richard Kettlewell wrote:
>
>> Bill McCormick<
wpmcc...@gmail.com> writes:
>>
>>> I want to make sure that a system has the same prompt for all users,
>>> and that no matter how a user edits his start up, the prompt will
>>> always contain some portion of the FQDN.
>>>
>>> What is the simplest way to accomplish this?
>>
>> By technical means: modify the shell (fairly easy) and somehow
>> prevent your users running other shells without petty restrictions
>> (hard, without reducing the usefulness of the system).
>>
>> By non-technical means: management diktat. Has the advantage that
>> the users can ignore it.
>>
> Since I'll be doing this repetitively on relatively clean systems, I
> think the best option is to make the change to /etc/bash.bashrc and
> /etc/skel/.bashrc. I think that should cover the root user and any new
> users created.
Yes, but, again, only insofar as the user his-/herself does not change
their $PS1. Duplicating it in /etc/skel/.bashrc isn't going to change
the fact that the user can always edit that file - unless you do things
like "chattr +i" (on the local copy of the file in the user's home
directory) and/or set up an ACL.
> One thing I was trying to do is bash script the change by doing
> something like this:
>
> $ cat /etc/skel/.bashrc| sed 's/\\h/$(hostname -f|sed
> 's/\.service\.fibertech\.local//')/' > /etc/skel/.bashrc
For starters, there's no need to do that because - as Richard Kettlewell
said - the "\n" already covers the hostname. Secondly, see below...
> But that doesn't work. I'm not much of a sed mavan, or even a bash
> scripting mavan for that matter.
First of all, that's what we call UUOC ("useless use of cat"), but more
importantly, you are truncating the file (by way of your redirect)
before you are actually processing its contents with sed, so naturally,
that wouldn't work. If you're going to modify an existing file with sed
and you want to keep the modifications on disk, you will need to make
use of an intermediary step via a temporary file.
But, as stated already, the whole exercise of editing the file via sed
is pointless because a Bourne-compatible UNIX shell already has a series
of built-in tokens which can be used to represent the hostname -
abridged or the complete FQDN - and other values in the $PS1 variable.
Either way, whatever you do, you will never be able to prevent the user
from modifying their $PS1, even if the user has to do it manually each
time they log in. So perhaps it would be advisable if you told us why
exactly you want to go about and do this. It is possible that your
whole thought process of preventing the modification of the user's $PS1
is only one way of accomplishing that which you really want.