Running .profile

I want to put a bit of code to synchronise some data in ~/.profile to run
when a shell starts - Ok so far so good.

The question is how do I know within .profile whether it is being invoked by
bash from a terminal login of from a GUI (e.g. KDE) login.

The synchronisation may take some time so I would rather it was NOT run
within .profile if starting KDE (running from Autostart instead allows nice
messages to the user) so I need to be able to put something in .profile like

if ! RunningFromKDE ]] ; then
Synchronise
fi

Lets take this further - how about running .profile for IceWM, xfce etc
logins.

Any ideas?

Alan

Fudokai wrote:

> I want to put a bit of code to synchronise some data in ~/.profile to
> run when a shell starts - Ok so far so good.
>
> The question is how do I know within .profile whether it is being
> invoked by bash from a terminal login of from a GUI (e.g. KDE) login.
>
> The synchronisation may take some time so I would rather it was NOT
> run within .profile if starting KDE (running from Autostart instead
> allows nice messages to the user) so I need to be able to put
> something in .profile like
>
> if ! RunningFromKDE ]] ; then
> Synchronise
> fi
>
> Lets take this further - how about running .profile for IceWM, xfce
> etc logins.
>
> Any ideas?

Detach your synchronise process regardless of how .profile is invoked ?


Per Jessen, Zürich (22.6°C)
http://en.opensuse.org/User:pjessen

Per Jessen wrote:

> Fudokai wrote:
>
>> I want to put a bit of code to synchronise some data in ~/.profile to
>> run when a shell starts - Ok so far so good.
>>
>> The question is how do I know within .profile whether it is being
>> invoked by bash from a terminal login of from a GUI (e.g. KDE) login.
>>
>> The synchronisation may take some time so I would rather it was NOT
>> run within .profile if starting KDE (running from Autostart instead
>> allows nice messages to the user) so I need to be able to put
>> something in .profile like
>>
>> if ! RunningFromKDE ]] ; then
>> Synchronise
>> fi
>>
>> Lets take this further - how about running .profile for IceWM, xfce
>> etc logins.
>>
>> Any ideas?
>
> Detach your synchronise process regardless of how .profile is invoked ?
>
>
If by that you mean
Synchronise &

I’m already doing that

Alan

For KDE, there’s an environment variable KDE_FULL_SESSION you could check for a full login; maybe there are similar ones for the other WMs. There’s always a check for a null $DISPLAY, but that causes problems if you’re logged in remotely with X-forwarding enabled.

Maybe the best approach is to dump all the environment variables in all the cases you want to check for, and apply a little Boolean algebra :slight_smile:

env | more

Fudokai wrote:

> Per Jessen wrote:
>
>> Fudokai wrote:
>>
>>> I want to put a bit of code to synchronise some data in ~/.profile
>>> to run when a shell starts - Ok so far so good.
>>>
>>> The question is how do I know within .profile whether it is being
>>> invoked by bash from a terminal login of from a GUI (e.g. KDE)
>>> login.
>>>
>>> The synchronisation may take some time so I would rather it was NOT
>>> run within .profile if starting KDE (running from Autostart instead
>>> allows nice messages to the user) so I need to be able to put
>>> something in .profile like
>>>
>>> if ! RunningFromKDE ]] ; then
>>> Synchronise
>>> fi
>>>
>>> Lets take this further - how about running .profile for IceWM, xfce
>>> etc logins.
>>>
>>> Any ideas?
>>
>> Detach your synchronise process regardless of how .profile is invoked
>> ?
>>
>>
> If by that you mean
> Synchronise &
>
> I’m already doing that

Hmm, if your .profile is waiting for that to finish, try running
synchronise with nohup.


Per Jessen, Zürich (17.7°C)
http://en.opensuse.org/User:pjessen

Per Jessen wrote:

> Fudokai wrote:
>
>> Per Jessen wrote:
>>
>>> Fudokai wrote:
>>>
>>>> I want to put a bit of code to synchronise some data in ~/.profile
>>>> to run when a shell starts - Ok so far so good.
>>>>
>>>> The question is how do I know within .profile whether it is being
>>>> invoked by bash from a terminal login of from a GUI (e.g. KDE)
>>>> login.
>>>>
>>>> The synchronisation may take some time so I would rather it was NOT
>>>> run within .profile if starting KDE (running from Autostart instead
>>>> allows nice messages to the user) so I need to be able to put
>>>> something in .profile like
>>>>
>>>> if ! RunningFromKDE ]] ; then
>>>> Synchronise
>>>> fi
>>>>
>>>> Lets take this further - how about running .profile for IceWM, xfce
>>>> etc logins.
>>>>
>>>> Any ideas?
>>>
>>> Detach your synchronise process regardless of how .profile is invoked
>>> ?
>>>
>>>
>> If by that you mean
>> Synchronise &
>>
>> I’m already doing that
>
> Hmm, if your .profile is waiting for that to finish, try running
> synchronise with nohup.
>
>

This isn’t the problem/solution. I’ll try to be clearer …

I want to run the Synchronise function in .profile if I’m logging on to a
standard text-based terminal.
If I’m starting KDE I DON’T want to start the Synchrionise in .profile, I’ll
create an Autostart script to run Synchronise instead (and give nice kdialog
messages to the user).

Currently I actually do start the Synchronise in .profile as a background
process and test for it still running in the Autostart script, sending
kdialog messages if it is.

Alan

Fudokai wrote:

> I want to run the Synchronise function in .profile if I’m logging on
> to a standard text-based terminal.
> If I’m starting KDE I DON’T want to start the Synchrionise in
> .profile, I’ll create an Autostart script to run Synchronise instead
> (and give nice kdialog messages to the user).

Okay, that’s different to what you started out saying. I don’t know how
to determine if a user is logging in under a GUI or not.


Per Jessen, Zürich (17.7°C)
http://en.opensuse.org/User:pjessen

There are several variables you can check ( $TERM, $DISPLAY ). But the easiest (fastest, safest) would be to write an .xprofile (for example) and run it from whatever xinirtrc or Xsession you’re using to start X.