Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Red Hat Install (http://www.linux-archive.org/red-hat-install/)
-   -   Determine if x is running (http://www.linux-archive.org/red-hat-install/242905-determine-if-x-running.html)

02-09-2009 09:21 PM

Determine if x is running
 
I'm am writing a script that sets some various security settings on
Redhat Boxes. I would like to try to determine if a gui may be running
on the box the script is run on. If so, I would echo some additional
text to stdout that instructs the user that they may required to
manually perform some additional settings manually. Things having to do
with screen savers. Anyway, I thought about the following:

1. use the runlevel command or who -r to see if the system is in
runlevel 5. This seems flawed since the box may have been started in
runlevel 3 and the startx command may have been used. The commands would
show runlevel 3.
2. Check if the environment variable DISPLAY is set. If so, seems like
there is a good chance that they are running a gui. (maybe)

Is there a better way to check this that anyone can think of?

_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe

Ray Van Dolson 02-09-2009 09:25 PM

Determine if x is running
 
On Mon, Feb 09, 2009 at 02:21:24PM -0800, redhat@buglecreek.com wrote:
> I'm am writing a script that sets some various security settings on
> Redhat Boxes. I would like to try to determine if a gui may be running
> on the box the script is run on. If so, I would echo some additional
> text to stdout that instructs the user that they may required to
> manually perform some additional settings manually. Things having to do
> with screen savers. Anyway, I thought about the following:
>
> 1. use the runlevel command or who -r to see if the system is in
> runlevel 5. This seems flawed since the box may have been started in
> runlevel 3 and the startx command may have been used. The commands would
> show runlevel 3.
> 2. Check if the environment variable DISPLAY is set. If so, seems like
> there is a good chance that they are running a gui. (maybe)
>
> Is there a better way to check this that anyone can think of?

Would it be sufficient for your needs to check is the X process is
running?

Theoretically, there is probably some way to interact with a running X
server directly from a script (even if you're not in control of its
terminal) to determine if it's running.

Also, X typically listens on port 6000 locally.

Ray

_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe

"Karl Pearson" 02-10-2009 05:30 AM

Determine if x is running
 
On Mon, February 9, 2009 3:25 pm, Ray Van Dolson wrote:
> On Mon, Feb 09, 2009 at 02:21:24PM -0800, redhat@buglecreek.com wrote:
>> I'm am writing a script that sets some various security settings on
>> Redhat Boxes. I would like to try to determine if a gui may be
>> running
>> on the box the script is run on. If so, I would echo some additional
>> text to stdout that instructs the user that they may required to
>> manually perform some additional settings manually. Things having to
>> do
>> with screen savers. Anyway, I thought about the following:
>>
>> 1. use the runlevel command or who -r to see if the system is in
>> runlevel 5. This seems flawed since the box may have been started in
>> runlevel 3 and the startx command may have been used. The commands
>> would
>> show runlevel 3.
>> 2. Check if the environment variable DISPLAY is set. If so, seems
>> like
>> there is a good chance that they are running a gui. (maybe)

DISPLAY is set by the user's login process, so it would be empty for a
cron job.

>>
>> Is there a better way to check this that anyone can think of?
>
> Would it be sufficient for your needs to check is the X process is
> running?
>
> Theoretically, there is probably some way to interact with a running X
> server directly from a script (even if you're not in control of its
> terminal) to determine if it's running.
>
> Also, X typically listens on port 6000 locally.

Just run runlevel and it will return what runlevel is currently being
run in the second response, i.e: on boot, it will show N 5 or N 3 for X
or text depending on what's in /etc/inittab on the initdefault line.

Now then, that doesn't handle startx, but how many times might that
actually happen. On my servers, there's no CRT/LCD, so no user will be
running startx. They might run vncserver, however, and use an X display
remotely. But, they better not leave it in that state, else that will be
disabled for them. All the users in my network have Linux PCs anyway,
and have no reason to be on the server unless they are editing a web
page, but then they can use fish:// in Konqueror or sftp:/// in
Nautilus.

I suspect I've confused more than helped, but ask away and someone
smarter than me will respond.

Karl

>
> Ray
>
> _______________________________________________
> Redhat-install-list mailing list
> Redhat-install-list@redhat.com
> https://www.redhat.com/mailman/listinfo/redhat-install-list
> To Unsubscribe Go To ABOVE URL or send a message to:
> redhat-install-list-request@redhat.com
> Subject: unsubscribe
>


---
Karl Pearson
Karlp@ourldsfamily.com
Owner/Administrator of the sites at
http://ourldsfamily.com
---
"To mess up your Linux PC, you have to really work at it;
to mess up a microsoft PC you just have to work on it."
---


_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe

Rick Stevens 02-10-2009 05:30 PM

Determine if x is running
 
Karl Pearson wrote:

On Mon, February 9, 2009 3:25 pm, Ray Van Dolson wrote:

On Mon, Feb 09, 2009 at 02:21:24PM -0800, redhat@buglecreek.com wrote:

I'm am writing a script that sets some various security settings on
Redhat Boxes. I would like to try to determine if a gui may be
running
on the box the script is run on. If so, I would echo some additional
text to stdout that instructs the user that they may required to
manually perform some additional settings manually. Things having to
do
with screen savers. Anyway, I thought about the following:

1. use the runlevel command or who -r to see if the system is in
runlevel 5. This seems flawed since the box may have been started in
runlevel 3 and the startx command may have been used. The commands
would
show runlevel 3.
2. Check if the environment variable DISPLAY is set. If so, seems
like
there is a good chance that they are running a gui. (maybe)


DISPLAY is set by the user's login process, so it would be empty for a
cron job.


Is there a better way to check this that anyone can think of?

Would it be sufficient for your needs to check is the X process is
running?

Theoretically, there is probably some way to interact with a running X
server directly from a script (even if you're not in control of its
terminal) to determine if it's running.


The easiest way is a small shell script:

#!/bin/bash
RES=`ps ax | grep -v grep | grep -i xorg`
if [ $? -eq 0 ]; then
echo X is running
else
echo X is NOT running
fi

(substitute the name of your X server for "xorg" if you're not running
XOrg). On top of that, $RES will be empty if X isn't running, and will
contain the line from "ps ax" describing it if X is running.

This should work regardless of if the machine starts X by going into run
level 5 and firing up a greeter or startx from some other run level. It
looks for the instance of the X server itself.


Also, X typically listens on port 6000 locally.


Not unless you TELL it to. It will listen on local Unix domain ports,
but not TCP/IP.



Just run runlevel and it will return what runlevel is currently being
run in the second response, i.e: on boot, it will show N 5 or N 3 for X
or text depending on what's in /etc/inittab on the initdefault line.

Now then, that doesn't handle startx, but how many times might that
actually happen. On my servers, there's no CRT/LCD, so no user will be
running startx. They might run vncserver, however, and use an X display
remotely. But, they better not leave it in that state, else that will be
disabled for them. All the users in my network have Linux PCs anyway,
and have no reason to be on the server unless they are editing a web
page, but then they can use fish:// in Konqueror or sftp:/// in
Nautilus.

I suspect I've confused more than helped, but ask away and someone
smarter than me will respond.


The shell snippet I provided
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer ricks@nerd.com -
- AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 -
- -
- I.R.S.: We've got what it takes to take what you've got! -
----------------------------------------------------------------------

_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe

"Karl Pearson" 02-11-2009 12:41 AM

Determine if x is running
 
On Tue, February 10, 2009 11:30 am, Rick Stevens wrote:
> Karl Pearson wrote:
>> On Mon, February 9, 2009 3:25 pm, Ray Van Dolson wrote:
>>> On Mon, Feb 09, 2009 at 02:21:24PM -0800, redhat@buglecreek.com
>>> wrote:
>>>> I'm am writing a script that sets some various security settings on
>>>> Redhat Boxes. I would like to try to determine if a gui may be
>>>> running
>>>> on the box the script is run on. If so, I would echo some
>>>> additional
>>>> text to stdout that instructs the user that they may required to
>>>> manually perform some additional settings manually. Things having
>>>> to
>>>> do
>>>> with screen savers. Anyway, I thought about the following:
>>>>
>>>> 1. use the runlevel command or who -r to see if the system is in
>>>> runlevel 5. This seems flawed since the box may have been started
>>>> in
>>>> runlevel 3 and the startx command may have been used. The commands
>>>> would
>>>> show runlevel 3.
>>>> 2. Check if the environment variable DISPLAY is set. If so, seems
>>>> like
>>>> there is a good chance that they are running a gui. (maybe)
>>
>> DISPLAY is set by the user's login process, so it would be empty for a
>> cron job.
>>
>>>> Is there a better way to check this that anyone can think of?
>>> Would it be sufficient for your needs to check is the X process is
>>> running?
>>>
>>> Theoretically, there is probably some way to interact with a running
>>> X
>>> server directly from a script (even if you're not in control of its
>>> terminal) to determine if it's running.
>
> The easiest way is a small shell script:
>
> #!/bin/bash
> RES=`ps ax | grep -v grep | grep -i xorg`
> if [ $? -eq 0 ]; then
> echo X is running
> else
> echo X is NOT running
> fi
>
> (substitute the name of your X server for "xorg" if you're not running
> XOrg). On top of that, $RES will be empty if X isn't running, and will
> contain the line from "ps ax" describing it if X is running.
>
> This should work regardless of if the machine starts X by going into run
> level 5 and firing up a greeter or startx from some other run level. It
> looks for the instance of the X server itself.
>
>>> Also, X typically listens on port 6000 locally.
>
> Not unless you TELL it to. It will listen on local Unix domain ports,
> but not TCP/IP.
>
>> Just run runlevel and it will return what runlevel is currently being
>> run in the second response, i.e: on boot, it will show N 5 or N 3 for
>> X
>> or text depending on what's in /etc/inittab on the initdefault line.
>>
>> Now then, that doesn't handle startx, but how many times might that
>> actually happen. On my servers, there's no CRT/LCD, so no user will be
>> running startx. They might run vncserver, however, and use an X
>> display
>> remotely. But, they better not leave it in that state, else that will
>> be
>> disabled for them. All the users in my network have Linux PCs anyway,
>> and have no reason to be on the server unless they are editing a web
>> page, but then they can use fish:// in Konqueror or sftp:/// in
>> Nautilus.
>>
>> I suspect I've confused more than helped, but ask away and someone
>> smarter than me will respond.
>
> The shell snippet I provided

HA! I knew you thought you were smarter than me! I knew you were too, by
the way... :)

> ----------------------------------------------------------------------
> - Rick Stevens, Systems Engineer ricks@nerd.com -
> - AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 -
> - -
> - I.R.S.: We've got what it takes to take what you've got! -
> ----------------------------------------------------------------------
>
> _______________________________________________
> Redhat-install-list mailing list
> Redhat-install-list@redhat.com
> https://www.redhat.com/mailman/listinfo/redhat-install-list
> To Unsubscribe Go To ABOVE URL or send a message to:
> redhat-install-list-request@redhat.com
> Subject: unsubscribe
>


---
Karl Pearson
Karlp@ourldsfamily.com
Owner/Administrator of the sites at
http://ourldsfamily.com
---
"To mess up your Linux PC, you have to really work at it;
to mess up a microsoft PC you just have to work on it."
---


_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe

Rick Stevens 02-11-2009 04:44 PM

Determine if x is running
 
Karl Pearson wrote:

On Tue, February 10, 2009 11:30 am, Rick Stevens wrote:

Karl Pearson wrote:

On Mon, February 9, 2009 3:25 pm, Ray Van Dolson wrote:

On Mon, Feb 09, 2009 at 02:21:24PM -0800, redhat@buglecreek.com
wrote:

I'm am writing a script that sets some various security settings on
Redhat Boxes. I would like to try to determine if a gui may be
running
on the box the script is run on. If so, I would echo some
additional
text to stdout that instructs the user that they may required to
manually perform some additional settings manually. Things having
to
do
with screen savers. Anyway, I thought about the following:

1. use the runlevel command or who -r to see if the system is in
runlevel 5. This seems flawed since the box may have been started
in
runlevel 3 and the startx command may have been used. The commands
would
show runlevel 3.
2. Check if the environment variable DISPLAY is set. If so, seems
like
there is a good chance that they are running a gui. (maybe)

DISPLAY is set by the user's login process, so it would be empty for a
cron job.


Is there a better way to check this that anyone can think of?

Would it be sufficient for your needs to check is the X process is
running?

Theoretically, there is probably some way to interact with a running
X
server directly from a script (even if you're not in control of its
terminal) to determine if it's running.

The easiest way is a small shell script:

#!/bin/bash
RES=`ps ax | grep -v grep | grep -i xorg`
if [ $? -eq 0 ]; then
echo X is running
else
echo X is NOT running
fi

(substitute the name of your X server for "xorg" if you're not running
XOrg). On top of that, $RES will be empty if X isn't running, and will
contain the line from "ps ax" describing it if X is running.

This should work regardless of if the machine starts X by going into run
level 5 and firing up a greeter or startx from some other run level. It
looks for the instance of the X server itself.


Also, X typically listens on port 6000 locally.

Not unless you TELL it to. It will listen on local Unix domain ports,
but not TCP/IP.


I suspect I've confused more than helped, but ask away and someone
smarter than me will respond.

The shell snippet I provided


HA! I knew you thought you were smarter than me! I knew you were too, by
the way... :)


Not really, just been doing this stuff for over 30 years. SOMETHING'S
gotta rub off!
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer ricks@nerd.com -
- AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 -
- -
- If it's stupid and it works...it ain't stupid! -
----------------------------------------------------------------------

_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe

"Karl Pearson" 02-12-2009 05:20 AM

Determine if x is running
 
On Wed, February 11, 2009 10:44 am, Rick Stevens wrote:
> Karl Pearson wrote:
>> On Tue, February 10, 2009 11:30 am, Rick Stevens wrote:
>>> Karl Pearson wrote:
>>>> On Mon, February 9, 2009 3:25 pm, Ray Van Dolson wrote:
<<< Stuff deleted >>>
>>>> I suspect I've confused more than helped, but ask away and someone
>>>> smarter than me will respond.
>>> The shell snippet I provided
>>
>> HA! I knew you thought you were smarter than me! I knew you were too,
>> by
>> the way... :)
>
> Not really, just been doing this stuff for over 30 years. SOMETHING'S
> gotta rub off!

I'm really hoping it will begin to rub off on me... I've been doing
this, though not as intensely as you, for about 23 years.

Karl Pearson
Owner/Administrator, the sites at
http://ourldsfamily.com
karlp@ourldsfamily.com

> ----------------------------------------------------------------------
> - Rick Stevens, Systems Engineer ricks@nerd.com -
> - AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 -
> - -
> - If it's stupid and it works...it ain't stupid! -
> ----------------------------------------------------------------------
>
> _______________________________________________
> Redhat-install-list mailing list
> Redhat-install-list@redhat.com
> https://www.redhat.com/mailman/listinfo/redhat-install-list
> To Unsubscribe Go To ABOVE URL or send a message to:
> redhat-install-list-request@redhat.com
> Subject: unsubscribe
>


---
Karl Pearson
Karlp@ourldsfamily.com
Owner/Administrator of the sites at
http://ourldsfamily.com
---
"To mess up your Linux PC, you have to really work at it;
to mess up a microsoft PC you just have to work on it."
---


_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe

Rick Stevens 02-12-2009 05:17 PM

Determine if x is running
 
Karl Pearson wrote:

On Wed, February 11, 2009 10:44 am, Rick Stevens wrote:

Karl Pearson wrote:

On Tue, February 10, 2009 11:30 am, Rick Stevens wrote:

Karl Pearson wrote:

On Mon, February 9, 2009 3:25 pm, Ray Van Dolson wrote:

<<< Stuff deleted >>>

I suspect I've confused more than helped, but ask away and someone
smarter than me will respond.

The shell snippet I provided

HA! I knew you thought you were smarter than me! I knew you were too,
by
the way... :)

Not really, just been doing this stuff for over 30 years. SOMETHING'S
gotta rub off!


I'm really hoping it will begin to rub off on me... I've been doing
this, though not as intensely as you, for about 23 years.


It helps if you're abrasive and "prickly", like me. You find you also
have to remove lots of lint and other things that stick to you. :-)
----------------------------------------------------------------------
- Rick "Hedgehog" Stevens, Systems Engineer ricks@nerd.com -
- AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 -
- -
- The gene pool could use a little chlorine. -
----------------------------------------------------------------------

_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe

"Karl Pearson" 02-12-2009 07:01 PM

Determine if x is running
 
On Thu, February 12, 2009 11:17 am, Rick Stevens wrote:
> Karl Pearson wrote:
>> On Wed, February 11, 2009 10:44 am, Rick Stevens wrote:
>>> Karl Pearson wrote:
>>>> On Tue, February 10, 2009 11:30 am, Rick Stevens wrote:
>>>>> Karl Pearson wrote:
>>>>>> On Mon, February 9, 2009 3:25 pm, Ray Van Dolson wrote:
>> <<< Stuff deleted >>>
>>>>>> I suspect I've confused more than helped, but ask away and someone
>>>>>> smarter than me will respond.
>>>>> The shell snippet I provided
>>>> HA! I knew you thought you were smarter than me! I knew you were
>>>> too,
>>>> by
>>>> the way... :)
>>> Not really, just been doing this stuff for over 30 years.
>>> SOMETHING'S
>>> gotta rub off!
>>
>> I'm really hoping it will begin to rub off on me... I've been doing
>> this, though not as intensely as you, for about 23 years.
>
> It helps if you're abrasive and "prickly", like me. You find you also
> have to remove lots of lint and other things that stick to you. :-)

I'll have to remember that. Hedgehog is better than porcupine then, huh?
Thinking about likening IT folks to different animals, why is it that
one that comes to mind is 'skunk'?

Karl

> ----------------------------------------------------------------------
> - Rick "Hedgehog" Stevens, Systems Engineer ricks@nerd.com -
> - AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 -
> - -
> - The gene pool could use a little chlorine. -
> ----------------------------------------------------------------------
>
> _______________________________________________
> Redhat-install-list mailing list
> Redhat-install-list@redhat.com
> https://www.redhat.com/mailman/listinfo/redhat-install-list
> To Unsubscribe Go To ABOVE URL or send a message to:
> redhat-install-list-request@redhat.com
> Subject: unsubscribe
>


---
Karl Pearson
Karlp@ourldsfamily.com
Owner/Administrator of the sites at
http://ourldsfamily.com
---
"To mess up your Linux PC, you have to really work at it;
to mess up a microsoft PC you just have to work on it."
---


_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe

John Reynolds 02-12-2009 07:53 PM

Determine if x is running
 
Karl Pearson wrote on 02/12/2009 12:01:04
PM:



>

> On Thu, February 12, 2009 11:17 am, Rick Stevens wrote:

> > Karl Pearson wrote:

> >> On Wed, February 11, 2009 10:44 am, Rick Stevens wrote:

> >>> Karl Pearson wrote:

> >>>> On Tue, February 10, 2009 11:30 am, Rick Stevens
wrote:

> >>>>> Karl Pearson wrote:

> >>>>>> On Mon, February 9, 2009 3:25 pm, Ray Van
Dolson wrote:

> >> <<< Stuff deleted >>>

> >>>>>> I suspect I've confused more than helped,
but ask away and someone

> >>>>>> smarter than me will respond.

> >>>>> The shell snippet I provided

> >>>> HA! I knew you thought you were smarter than me!
I knew you were

> >>>> too,

> >>>> by

> >>>> the way... :)

> >>> Not really, just been doing this stuff for over 30 years.

> >>> SOMETHING'S

> >>> gotta rub off!

> >>

> >> I'm really hoping it will begin to rub off on me... I've
been doing

> >> this, though not as intensely as you, for about 23 years.

> >

> > It helps if you're abrasive and "prickly", like me.
*You find you also

> > have to remove lots of lint and other things that stick to you.
:-)

>

> I'll have to remember that. Hedgehog is better than porcupine then,
huh?

> Thinking about likening IT folks to different animals, why is it that

> one that comes to mind is 'skunk'?

>

We're the ones constantly being badgered.



John R_______________________________________________
Redhat-install-list mailing list
Redhat-install-list@redhat.com
https://www.redhat.com/mailman/listinfo/redhat-install-list
To Unsubscribe Go To ABOVE URL or send a message to:
redhat-install-list-request@redhat.com
Subject: unsubscribe


All times are GMT. The time now is 04:42 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.