1 |
On Nov 25, 2007 8:27 PM, <reader@×××××××.com> wrote: |
2 |
|
3 |
> Scripts that test for X running might work in a shell but not when the |
4 |
> script is run by cron. |
5 |
> |
6 |
> For example: This code: |
7 |
> tty|grep pts |
8 |
> retval=$? |
9 |
> if [[ $retval > 0 ]];then |
10 |
> print "X isn't running just now... postponing rsync of WWW |
11 |
> until such time as it is... exiting" |
12 |
> exit |
13 |
> fi |
14 |
> |
15 |
> Runs fine when run from a user shell, but when cron runs it the test |
16 |
> always fails to be true. |
17 |
> |
18 |
> So how can I test for X running in case where script will be run by cron? |
19 |
|
20 |
|
21 |
How about something like this: retval=`ps aux | grep tty | grep X | awk |
22 |
'{print $2}'` |
23 |
|
24 |
Or retval=`cat /tmp/.X0-lock` |
25 |
|
26 |
Or even better: |
27 |
|
28 |
if [[ -e "/tmp/.X0-lock" ]];then |
29 |
... |
30 |
|
31 |
|
32 |
|
33 |
> |
34 |
> |
35 |
> -- |
36 |
> gentoo-user@g.o mailing list |
37 |
> |
38 |
> |