Home Messages Index
[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index

Re: Linux scripting question

  • Subject: Re: Linux scripting question
  • From: "Larry Qualig" <lqualig@xxxxxxxxx>
  • Date: 22 Feb 2006 07:13:57 -0800
  • Complaints-to: groups-abuse@google.com
  • In-reply-to: <1140572663.342964.168890@f14g2000cwb.googlegroups.com>
  • Injection-info: g44g2000cwa.googlegroups.com; posting-host=12.170.48.219; posting-account=I0FyeA0AAABAUAjJ9vi7laKRssUBoQA3
  • Newsgroups: comp.os.linux.advocacy
  • Organization: http://groups.google.com
  • References: <1140572663.342964.168890@f14g2000cwb.googlegroups.com>
  • User-agent: G2/0.2
  • Xref: news.mcc.ac.uk comp.os.linux.advocacy:1083824
Larry Qualig wrote:
> I know this isn't alt.linux.scripting or anything but this is pretty
> much the only group that I post to. People here have a good grasp of
> Linux so I'm going to try here first.
>
> I'm setting up a fairly complex login script that will mount various
> SMB (actually cifs) network drives with the right permissions and
> things like that. I can't mount the drives using fstab because of
> permission problems. I need to do this on a per-user basis.
>
> So I need to modify the /etc/profile script. The script comments say
> not to change /etc/profile and to make my changes externally in
> /etc/profile.local instead. Great... I did this and after much
> debugging I found that my script is getting called twice.
>
> I eventually traced the problem to the fact that /etc/profile is
> getting called twice per login. The part in /etc/profile that calls my
> script is:
>
>    test -s /etc/profile.local && . /etc/profile.local
>
> I saved the original version of the file and changed this to log
> something to a file whenever the script runs and it is in fact being
> called twice per login. I can easily get around this in my script by
> doing what /etc/profile does which is this:
>
> #
> # Avoid overwriting user settings if called twice
> #
> if test -z "$PROFILEREAD" ; then
>     readonly PROFILEREAD=true
>     export PROFILEREAD
> fi
>
> # Most bourn shell clones knows about this
> if test -z "$PROFILEREAD" ; then
>     HISTSIZE=1000
>     export HISTSIZE
> fi
>
> # Set INFOPATH to tell xemacs where he can find the info files
> if test -z "$PROFILEREAD" ; then
>     tmp="$INFODIR"
>     INFOPATH=$INFODIR
>     unset tmp
>     export INFODIR INFOPATH
> fi
>
>
> +++++++++++++++++++++++++++++++++=
>
>
> I can simply set my own environment variable like /etc/profile does (or
> check PROFILEREAD assuming it doesn't change in the future) to get
> around the problem. But....
>
> #1 - I like to understand how/why things work. Seems that I shouldn't
> have to resort to doing this but /etc/profile does so obviously they
> believe things can (and do) get called twice.
>
> #2 - I find it interesting that just about everything else in
> /etc/profile is "protected" with a check to $PROFILEREAD but calling
> /etc/profile.local isn't so it gets called twice.
>
> #3 - Does anyone else have this problem. I'm running SuSE 10.0 with
> dual monitors if that matters.
>
> #4 - Any ideas? I don't have any consoles/Xterms that are opening up
> but /etc/profile is getting run twice. Each time the $LOGNAME is me
> ('larry') and I was able to find that the $PPID is kdm. The scripts
> gets run twice within a very short amount of time. Logging the time via
> 'date' always shows the exact same time down to the second.
>
>
> Thanks all.

Hi guys...

Thanks for the suggestions. I'm at work at the moment but will give
these a try when I get home.

One thing that I'm also going to try is to login to my account through
a console session (no KDE desktop) and see if this
changes anything. Reason being that in the script the name of the $PPID
is 'kdm' and I run dual screens and maybe/somehow the display manager
is being started twice... once for each screen. With a non-GUI console
session this might not happen. It's easy enough to try.

Rather than post individual replies I'll just do it all here. Thanks
again.




(Malware Magnet)

-> /etc/profile ... $HOME/.bash_profile (which, in turn, invokes the
$HOME/.bashrc script which runs /etc/bashrc)?
-> Do both these instances exist?

Good idea. I'll check when I get home. My 'ubu' machine running Ubuntu
is up 24/7 (I still need to open up an SSH port to get to it) but this
is on my desktop which I turn off when I'm not using it.



(Roy Schestowitz)

-> It shouldn't, unless you have some odd setting. Are you using SuSE?
/etc/profile.local is run only once, when you initially log in.

There's no odd setting that I'm aware of but this is odd behavior that
I'm trying to track down. It is SuSE v10.0 with all updates.


-> Use 'echo' (or something else which is verbose) to confirm that the
script gets run twice.

At first I thought I messed something up elsewhere. I finally put some
'echo "xxxx as $LOGNAME" >> /home/larry/log.txt' in to the /etc/profile
script itself which is what brought me to the conclusion that the
script *IS* being called twice. I am 100% certain that I'm not
explicitly calling this from any of my scripts.


>> I eventually traced the problem to the fact that /etc/profile is
>> getting called twice per login. The part in /etc/profile that calls my
>> script is:

>>    test -s /etc/profile.local && . /etc/profile.local

-> That's odd. On my SuSE box there is no attempt to do such a thing. I
can only spot the following:

- if test -f /proc/mounts ; then
-   case "`/bin/ls -l /proc/$$/exe`" in
-     */bash)     is=bash ;;
-     */rbash)    is=bash ;;
-     */ash)      is=ash  ;;
-     */ksh)      is=ksh  ;;
-     */zsh)      is=zsh  ;;
-     */*)        is=sh   ;;
-   esac
- else
-   is=sh
- fi


My profile script has this too. The test for profile.local is made
further down the script. There is a huge comment at the top of
/etc/profile that says not to make changes here because they may not
survive an upgrade and to use profile.local instead.



(Linønut)

> I'm setting up a fairly complex login script that will mount various
> SMB (actually cifs) network drives with the right permissions and
> things like that. I can't mount the drives using fstab because of
> permission problems.



- Yes you can.  You are free to insert a username and credentials into
the fstab entry in various ways.  Here's one way, for host 'server' and
a share named 'share', using /smb instead of /mnt:
- See man smbclient for an explanation of the credentials file.

I'm already using a credentials file. My script tries to mount the
drive and it if fails because of authentication... I use "kdialog" to
prompt the user for a new password and write it out to their
~/.creds.txt file so it's available the next time.

I can do what you're saying in fstab (and it works) BUT it will always
mount the network drives as me (larry) which isn't what I want. Reason
being is that if someone else uses this machine or if I setup another
account for myself or whatever I do *not* want every single user to
automatically have my credentials to access the network with. Currently
only I use this machine but I like to set things up properly for the
long-term and it's also a good way to learn a thing or two.



(BearItAll)

- It is a Suse thing... it's the sort of thing that can bite you in the
bum when you least expect it.

It difficult finding anything about this out on the web. I can easily
create a work around for this and move on but I want to understand
what's happening and *why* I need the work around. All indications are
that ultimately I will need to check for double invocation of my script
but I'd feel a lot more comfortable knowing why I'm doing it.

(Ray Ingles)

- Is there an xterm that's getting called with the "-ls" (login shell)
parameter? That could end up sourcing it twice:

I don't believe so. I shut down all the apps on my desktop so that when
I login nothing gets "restored" by KDE. But I always get the same
thing. Tonight I'll try it with only a console session and with a
different desktop and window manager.


[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index