AJSG1969
Posts: 42
Joined: Tue Oct 24, 2017 3:24 pm

xterm: Xt error: Can't open display: %s

Fri Nov 10, 2017 5:30 pm

This is the bash file:

Code: Select all

Code: Select all

echo "Test Script"
xterm -e "airodump-ng wlan0mon" & sleep 5
pkill airodump-ng
Runs perfectley when called by the command in a Terminal window:

Code: Select all

sudo bash test.sh
when in crontab I run it like this:

Code: Select all

16 * * * * DISPLAY=:0 xterm -e sudo /home/pi/Desktop/Active/test.sh
I get on screen:

Test Script
No protocol specified
Warning: This program......suid bit on the executable.
xterm: Xt error: Can't open display: %s

Same error apart from the "No protocol specified". What do you think could be the issue?

Thanks.

Andrew.

gkaiseril
Posts: 627
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: xterm: Xt error: Can't open display: %s

Fri Nov 10, 2017 5:39 pm

It looks like you are calling your script without specifying the shell program to run.

You should include the shebang line as the first line of your script.

#!/bin/bash

or specify the bash shell in the chron entry.


16 * * * * DISPLAY=:0 xterm -e sudo /bin/bash /home/pi/Desktop/Active/test.sh
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.

AJSG1969
Posts: 42
Joined: Tue Oct 24, 2017 3:24 pm

Re: xterm: Xt error: Can't open display: %s

Fri Nov 10, 2017 8:04 pm

Code: Select all

#!/bin/bash
echo "Test Script"
xterm -e "airodump-ng wlan0mon" & sleep 4
pkill airodump-ng
Unfortunately that wasn't the problem, still gives me the same issue. Going slightly crazy here as it works perfectly in Ubuntu...

Cheers.

Andrew.

ait
Posts: 127
Joined: Sun Oct 30, 2011 6:51 pm

Re: xterm: Xt error: Can't open display: %s

Fri Nov 10, 2017 8:10 pm

hello,
just a suggestion:
try it without xterm -e

User avatar
Paeryn
Posts: 2614
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: xterm: Xt error: Can't open display: %s

Fri Nov 10, 2017 8:39 pm

It looks like you are ultimately trying to run xterm in the shell script when the script is being run as root. Root won't ordinarily have authority to open a window on a user's desktop so the xterm should (and does) fail, the "No protocol specified" and "xterm: Xt error: Can't open display:" error messages are typical of what you get when a user tries to connect to an X display that the user doesn't have authority to connect to.
She who travels light — forgot something.

AJSG1969
Posts: 42
Joined: Tue Oct 24, 2017 3:24 pm

Re: xterm: Xt error: Can't open display: %s

Fri Nov 10, 2017 9:10 pm

Paeryn wrote:
Fri Nov 10, 2017 8:39 pm
It looks like you are ultimately trying to run xterm in the shell script when the script is being run as root. Root won't ordinarily have authority to open a window on a user's desktop so the xterm should (and does) fail, the "No protocol specified" and "xterm: Xt error: Can't open display:" error messages are typical of what you get when a user tries to connect to an X display that the user doesn't have authority to connect to.
In Ubuntu I set the user as no password like so...

sudo visudo

then add
#includedir /etc/sudoers.d
root ALL=NOPASSWD: ALL
framemanager001 ALL=(ALL:ALL) NOPASSWD: ALL
fm ALL=(ALL:ALL) NOPASSWD: ALL

I have tried running the same in Raspian but get the same issue as previously described.

AJSG1969
Posts: 42
Joined: Tue Oct 24, 2017 3:24 pm

Re: xterm: Xt error: Can't open display: %s

Fri Nov 10, 2017 9:14 pm

ait wrote:
Fri Nov 10, 2017 8:10 pm
hello,
just a suggestion:
try it without xterm -e
I can run it from a terminal...

Code: Select all

sudo bash /home/pi/Desktop/Active/a.sh
But from crontab I cannot see it running at all...

Code: Select all

12 * * * * sudo bash /home/pi/Desktop/Active/a.sh

User avatar
Paeryn
Posts: 2614
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: xterm: Xt error: Can't open display: %s

Fri Nov 10, 2017 9:46 pm

AJSG1969 wrote:
Fri Nov 10, 2017 9:10 pm
Paeryn wrote:
Fri Nov 10, 2017 8:39 pm
It looks like you are ultimately trying to run xterm in the shell script when the script is being run as root. Root won't ordinarily have authority to open a window on a user's desktop so the xterm should (and does) fail, the "No protocol specified" and "xterm: Xt error: Can't open display:" error messages are typical of what you get when a user tries to connect to an X display that the user doesn't have authority to connect to.
In Ubuntu I set the user as no password like so...

sudo visudo

then add
#includedir /etc/sudoers.d
root ALL=NOPASSWD: ALL
framemanager001 ALL=(ALL:ALL) NOPASSWD: ALL
fm ALL=(ALL:ALL) NOPASSWD: ALL

I have tried running the same in Raspian but get the same issue as previously described.
I don't know how Ubuntu is doing things but X authorisation doesn't care whether the user running the program is root or not, the point is that root (or any other user) isn't ordinarily authorised to connect to a user's display without having that user's authorisation key. Root can easily use any user's authorisation key (since root has access to the user's file where it is stored) to give itself authority, but just being root should never be enough.

I suppose Ubuntu could be set up so that [email protected] has authority for each user's X-session, I've never set up user-based authorities so not sure on exactly how to specify it.
She who travels light — forgot something.

AJSG1969
Posts: 42
Joined: Tue Oct 24, 2017 3:24 pm

Re: xterm: Xt error: Can't open display: %s

Sat Nov 11, 2017 8:27 am

Paeryn wrote:
Fri Nov 10, 2017 9:46 pm
I don't know how Ubuntu is doing things but X authorisation doesn't care whether the user running the program is root or not, the point is that root (or any other user) isn't ordinarily authorised to connect to a user's display without having that user's authorisation key. Root can easily use any user's authorisation key (since root has access to the user's file where it is stored) to give itself authority, but just being root should never be enough.
I'm a little at a loss here, from what I understand the "pi" user has already root authorisation via the sudo command in Raspbian. In Ubuntu the only change I make to run the script is to allow sudo to be run without asking for a password as the script needs to be automated in crontab.

Any help is much appreciated.

Andrew.

Return to “Raspbian”