FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 11-26-2007, 12:27 AM
 
Default How to tell Cron X is running or not

Scripts that test for X running might work in a shell but not when the
script is run by cron.

For example: This code:
tty|grep pts
retval=$?
if [[ $retval > 0 ]];then
print "X isn't running just now... postponing rsync of WWW
until such time as it is... exiting"
exit
fi

Runs fine when run from a user shell, but when cron runs it the test
always fails to be true.

So how can I test for X running in case where script will be run by cron?

--
gentoo-user@gentoo.org mailing list
 
Old 11-26-2007, 12:56 AM
"Andrey Falko"
 
Default How to tell Cron X is running or not

On Nov 25, 2007 8:27 PM, <reader@newsguy.com> wrote:

Scripts that test for X running might work in a shell but not when the
script is run by cron.

For example: *This code:
*tty|grep pts
*retval=$?
*if [[ $retval > 0 ]];then
* *print "X isn't running just now... postponing rsync of WWW

* *until such time as it is... exiting"
* *exit
*fi

Runs fine when run from a user shell, but when cron runs it the test
always fails to be true.

So how can I test for X running in case where script will be run by cron?

How about something like this:* retval=`ps aux | grep tty | grep X | awk '{print $2}'`

Or retval=`cat /tmp/.X0-lock`

Or even better:

if [[ -e "/tmp/.X0-lock" ]];then

...

*

--

gentoo-user@gentoo.org mailing list
 
Old 11-26-2007, 01:40 AM
 
Default How to tell Cron X is running or not

"Andrey Falko" <ma3oxuct@gmail.com> writes:

> How about something like this: retval=`ps aux | grep tty | grep X | awk
> '{print $2}'`
>
> Or retval=`cat /tmp/.X0-lock`
>
> Or even better:
>
> if [[ -e "/tmp/.X0-lock" ]];then

Yup, both of those should work from cron or anywhere. In my case and
probably many other as well, I could shorten the ps approach to:
ps aux|grep '[X] :0'

But looking for /tmp/.X0-lock is probably the most reliable. Thanks

--
gentoo-user@gentoo.org mailing list
 
Old 11-26-2007, 05:35 AM
 
Default How to tell Cron X is running or not

On Sun, Nov 25, 2007 at 08:40:08PM -0600, reader@newsguy.com wrote:
> Yup, both of those should work from cron or anywhere. In my case and
> probably many other as well, I could shorten the ps approach to:
> ps aux|grep '[X] :0'
>
> But looking for /tmp/.X0-lock is probably the most reliable. Thanks

Try xdpyinfo. If $DISPLAY is not set, try xdpyinfo -display :0.0 for
the usual main display. ssh -X -Y makes up its own names, but you
haev to figure out whether cron programs should even know about the
display in general, or the ssh ones in particular.

At any rate, try this:

if xdpyinfo >/dev/null; then echo "X running"; else echo "No X"; fi

--
... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._.
Felix Finch: scarecrow repairman & rocket surgeon / felix@crowfix.com
GPG = E987 4493 C860 246C 3B1E 6477 7838 76E9 182E 8151 ITAR license #4933
I've found a solution to Fermat's Last Theorem but I see I've run out of room o
--
gentoo-user@gentoo.org mailing list
 
Old 11-26-2007, 07:03 AM
Neil Bothwick
 
Default How to tell Cron X is running or not

On Sun, 25 Nov 2007 20:40:08 -0600, reader@newsguy.com wrote:

> Yup, both of those should work from cron or anywhere. In my case and
> probably many other as well, I could shorten the ps approach to:
> ps aux|grep '[X] :0'

Or use "pidof X".


--
Neil Bothwick

Top Oxymorons Number 46: Found missing
 
Old 11-26-2007, 05:14 PM
 
Default How to tell Cron X is running or not

Neil Bothwick <neil@digimed.co.uk> writes:

> pidof X

Vey nice ...
Neil are those green bananas on your head or leaves?

--
gentoo-user@gentoo.org mailing list
 

Thread Tools




All times are GMT. The time now is 09:23 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org