[techtalk] Telnet, solaris and .profile

Fan, Laurel Laurel.Fan at compaq.com
Thu Aug 17 10:32:52 EST 2000


Britta Koch, britta at linuxchix.org, said:
> My home directory at work is mounted via NFS on my Linux box. 
> It's got a .profile and a .bash_profile file. When I login
> from Linux, it reads my .bash_profile file. When I telnet into
> the Solaris 5.6 box that hosts my home directory, my .profile
> file is not read (and I don't want it to read my .bash_profile
> - they're different files for a reason). It's annoying me that I
> always have to . .profile after logging in. Is there any way 
> I can automate this?

What shell are you using, and is it one that normally runs .profile?

One way to do things differently on different computers is to have it
check what os/hostname it is, and run a different file depending on
what it comes up with.  Here's a way that works in both bash and csh:

in the 'main' script (say, .profile), have these two lines:
---cut---
source script.`uname`
source script.`hostname`
---cut---

(and you can of course have stuff that you want to do all the time
in the main file as well)
the `` (backticks) mean "run this program and put the results here",
so if I was on Linux, running uname gives me "Linux", so that would
turn into "source script.Linux", and if I was on solaris, running
uname gives me "SunOS", so that would turn into "source script.SunOS".
Of course, change the "script" part of it to something that makes sense,
like .profile if you're doing your profile.[1]

So now, for each system you need os- or host- specific stuff in[2], create
a file for the script.`uname` and script.`hostname`.  One easy way to do
this is to actually log in to the system you want it for, and do a
emacs/vi/cat > or whatever literally script.`uname`, which prevents
you from making any typos.  You might also want to do an
echo script.`uname` beforehand, just to make sure it makes sense.

One disadvantage is that if you don't have a system-specific file for
a particular system it'll give an error.  I actually like this, because
it lets me see if I'm missing any systems.

hope this made sense and/or was useful..


[1] an alternative is to put the specific files in a different directory,
like .profiles/ (you can probably figure out how to call them from the
above)

Another alternative is to run the files instead of sourcing them.  This
probably won't work very well for .profile kinds of things, but may work
for other scripts, especially if for some reason you wrote them in
different languages, or if some of them are symlinks to the 'real'
programs and some of them are programs you wrote.

[2] if you only want to do it on hostnames or only want to do it on
unames, you can obviously just take the line out.  You can also do it
with other things, like possibly whether your home dir is local or
nfs'd (I don't know if or how to do this, I haven't used nfs much)





More information about the Techtalk mailing list