zuputoddu
zuputoddu

Reputation: 11

Raspberry Pi OS - at command does nothing

I have a Pi 3B+ with Pi OS (PRETTY_NAME="Raspbian GNU/Linux 10 (buster)")

I want to run a script at a certain time, using at command.

For testing purposes i have made a test1.sh, to open Chromium browser using pyautogui.

This file is located in /home/pi/test1.sh and contains the following:

#!/usr/bin/python3
import pyautogui
pyautogui.click(67, 20) #click Chromium icon

This .sh executes fine when clicked in the GUI and also when I run it typing ./test1.sh in the Terminal.

Trying to use at command does not work and yields the following:

pi@raspberrypi:~ $ at 11:50
warning: commands will be executed using /bin/sh
at> ./test1.sh
at> < EOT> (Here is where I type ctrl+D)
job 11 at Fri Nov  5 11:50:00 2021

At the specified time, nothing happens. I know it must be something I am doing wrong, but for the life of me I can not figure out what it is. Help?

Edit:

the first / in the shebang was missing in the post, but not in the file.

atq returns nothing

ps ax returns text below (cut for brevity)

 PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:05 /sbin/init splash
    2 ?        S      0:00 [kthreadd]
    3 ?        I<     0:00 [rcu_gp]

date returns accurate date and time

cat /var/mail/pi returns the following:

Subject: Output from your job       11
To: pi@raspberrypi
Message-Id: <E1miwnI-0000tR-83@raspberrypi>
From: pi@raspberrypi
Date: Fri, 05 Nov 2021 11:50:00 +0100

sh: 49: ./test1.sh: not found

From pi@raspberrypi Fri Nov 05 12:05:00 2021
Return-path: <pi@raspberrypi>
Envelope-to: pi@raspberrypi
Delivery-date: Fri, 05 Nov 2021 12:05:00 +0100
Received: from pi by raspberrypi with local (Exim 4.92)
    (envelope-from <pi@raspberrypi>)
    id 1mix1o-0000xA-KG
    for pi@raspberrypi; Fri, 05 Nov 2021 12:05:00 +0100

This suggests that the file is not there, but when I type ls it is clearly shown.

Using the full path /home/pi/test1.sh also returns nothing but the mail received states the following:

Subject: Output from your job       13
To: pi@raspberrypi
Message-Id: <E1mjHmv-0000NT-4B@raspberrypi>
From: pi@raspberrypi
Date: Sat, 06 Nov 2021 10:15:01 +0100

Traceback (most recent call last):
  File "/home/pi/test1.sh", line 3, in <module>
    import pyautogui
  File "/home/pi/.local/lib/python3.7/site-packages/pyautogui/__init__.py", line 249, in <module>
    import mouseinfo
  File "/home/pi/.local/lib/python3.7/site-packages/mouseinfo/__init__.py", line 223, in <module>
    _display = Display(os.environ['DISPLAY'])
  File "/usr/lib/python3.7/os.py", line 678, in __getitem__
    raise KeyError(key) from None
KeyError: 'DISPLAY'

Upvotes: 0

Views: 393

Answers (1)

zuputoddu
zuputoddu

Reputation: 11

As pointed out by @linuxfan in the comments:

The DISPLAY variable is not set.

problem was fixed by doing the following:

pi@raspberrypi:~ $ at now + 1 minute
warning: commands will be executed using /bin/sh
at> export DISPLAY=:0.0
at> /home/pi/test1.sh
at> <EOT>
job 17 at Sun Nov  7 10:55:00 2021

Upvotes: 1

Related Questions