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: Roy Schestowitz <newsgroups@xxxxxxxxxxxxxxx>
  • Date: Wed, 22 Feb 2006 04:53:06 +0000
  • Newsgroups: comp.os.linux.advocacy
  • Organization: schestowitz.com / MCC / Manchester University
  • References: <1140572663.342964.168890@f14g2000cwb.googlegroups.com> <slrndvnlek.8d5.malware.vbs@localhost.localdomain>
  • Reply-to: newsgroups@xxxxxxxxxxxxxxx
  • User-agent: KNode/0.7.2
__/ [ Malware Magnet ] on Wednesday 22 February 2006 03:09 \__

> On 2006-02-22, Larry Qualig <lqualig@xxxxxxxxx> 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.

There are some good scripting folks at comp.os.linux.misc. They even tailored
a few scripts for me in the past. For free! *grin*

>> 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.

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. In my case:

xbindkeys -f ~/Main/Programs/Scripts/Definitions/xbindkeysrc
cd ~/Main/Programs/wayv/
~/Main/Programs/wayv/wayv ~/Main/Programs/wayv/wayv.conf &
crontab ~/Main/Programs/Scripts/Definitions/cron

I suggest you keep a local copy of such a file in your home directory or else
it might not be backed up when you migrate or upgrade. Use 'echo' (or
something else which is verbose) to confirm that the script gets run 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

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   ;;

>> 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"
>>     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.

As I said, this seems irregular. /etc/profile gets called once, and so does
/etc/profile.local . You rarely ever need to get down to this level. YaST
(or equivalent) should handle them and write to them when you make changes
in the front end (if ever). Changing such files, including for instance
.bashrc, is something which is utterly unnecessary. Even .kde/Autostart/ is
managed by a front end.

>> #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.

Opening of consoles/Xterms should not have an effect. This invokes other sets
of files. /etc/profile.local is called only once at the start and it appear
as though /etc/profile leads to a small chain or reaction.

>> Thanks all.
> Hi Larry,
> Is it possible that the logins are invoking both:
> 1. /etc/profile
> 2. $HOME/.bash_profile (which, in turn, invokes the $HOME/.bashrc script
> which runs /etc/bashrc)?
> Do both these instances exist?

I think it would be intersting to find out what Larry's $HOME/.bashrc
actually contains.


Roy S. Schestowitz      |    Prevalence does not imply ideali$M
http://Schestowitz.com  |    SuSE Linux     |     PGP-Key: 0x74572E8E
  4:35am  up 4 days 16:54,  8 users,  load average: 0.30, 0.47, 0.42
      http://iuron.com - Open Source knowledge engine project

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