I am running a nearly fresh image of Raspbian Stretch 4.9 with a desktop and have a program which creates a new image for the computer background every few minutes.
I am trying to create a cron job to properly update the background using pcmanfm and, having followed the suggestions here, have created the following script called update.sh to set the background:
!#/bin/bash
export DISPLAY=:0
export XAUTHORITY=/home/pi/.Xauthority
pcmanfm -w '/home/pi/folder/image.png'
The script is executable and when it is run from the terminal it functions as intended. I have created a crontab to have this run automatically as such:
* * * * * /home/pi/folder/update.sh > /home/pi/folder/log.txt 2>&1
When the cron job triggers every minute, a pop-up window appears with an error saying "Desktop manager is not active." with a button "OK" to dismiss it, and the log file reads:
** Message: x-terminal-emulator has very limited support, consider choose another terminal
I have tried the command directly in the crontab
* * * * * DISPLAY=:0 && pcmanfm -w '/home/pi/folder/image.png' > /home/pi/folder/log.txt 2>&1
And the error is different this time
Cannot open display:
I am not entirely sure what sense to make of this, though from looking around it seems cron jobs can be finnicky. I am not sure if it is a Path or environment problem because I do not know many details about these things, but I don't think it should be a problem as I am using the full path to the image and the scripts. It shouldn't be a permissions error, because I have tried this on both a user crontab and a system crontab, and both fail. (Besides, the default pi user has root permissions by default anyways.) I am not sure what else to search for or try so I am asking for help if someone could point me in the right direction or has encountered this problem before.
I had exactly the same issue, except I am running Lubuntu 17.04. It appeared lately after a recent update, though cannot pinpoint when. After lot's of research I became suspicious that one of the XDG enviromental variables must be exported too. Following some trial and error, I found that exporting XDG_RUNTIME_DIR solved the problem for me. You may want to give it a try.
To figure out the value run: echo $XDG_RUNTIME_DIR
The working wallpaper changer running from cron for me now looks like:
#!/bin/bash
...
export DISPLAY=:0
export XAUTHORITY=/home/krisz/.Xauthority
export XDG_RUNTIME_DIR=/run/user/1000
pcmanfm --set-wallpaper=${dir}/${file} --wallpaper-mode=crop
...
Related
I have a simple python project to water my plants, it works with a Raspberry and RaspberryPi os lite.
In the project I have a package named app with a __main__.py to launch it, I just type python -m app in the terminal and it works fine.
I tried to make a crontab with * * * * * /usr/bin/python /home/pi/djangeau/app
Nothing happens, whereas if I launch a simple python test script it does.
The cron log gives me that error : 'No MTA installed, discarding output' , not sure this is useful to solve the problem.
I hope I was clear enough. Thank you for your answers. Vincent
MTA is for mailing purposes as cron sends email whereas ubuntu doesn't have MTA. Below is the link for a better understanding:
https://askubuntu.com/questions/222512/cron-info-no-mta-installed-discarding-output-error-in-the-syslog
Finally I figured out:
For exemple that command in bash : python -m app
is equivalent to this one for a crontab :
* * * * * cd /home/pi/djangeau && /usr/bin/python -m app
Just replace the correct path and stars by the schedule you want
I installed the MATE desktop environment into my onprem EC2 instance as per this URL;
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-2-install-gui/
And was able to kick-off terminal commands such as;
mate-terminal --window --zoom=2 --geometry=30x12 --command timer.sh &
Which opened a terminal window and looped over printing the date and time until killed.
Now, I get
Failed to parse arguments: Cannot open display:
I think this might be due to the following, as it caused problems with TigerVNC ;
$> chmod 775 /home/ec2-user
I have tried setting DISPLAY to "localhost:0.0" and ":0.0" but to no avail.
I know its related to gnome but I just can't find enough documentation, so any help is appreciated?
Chris
I am currently trying to get a cron job working, so that the google assistant starts automatically after boot. For that I created this cron job which executes on reboot.
SHELL=/bin/sh
PATH=/usr/bin:/bin:/home/pi/Desktop:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#Reboot lxterminal -t "Google Assistant" -e /bin/bash /home/pi/Desktop/init.sh
lxterminal will open a window with google assistant running within.
Here is my full cron job:
#!/bin/bash
SHELL=/bin/sh
PATH=/usr/bin:/bin:/home/pi/Desktop:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
source /home/pi/env/bin/activate
python3 /home/pi/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc/pushtotalk.py
I already tried answers from similar problems and even specified the path variable for cron, but it still won't work for me. The script isn't the fault, when I execute it manually it runs fine.
The problem wasn't with cron, though I settled for using a systemd service instead.
What I didn't know was, that Lxterminal needed a initalized screen to work and due to the script running on boot it wasn't.
This is an easy fix. Either add an delay of 30 Seconds or other values, depending on your system, to the beginning of your script or simulate the display beeing initalized already with export DISPLAY=:1
I have a Raspberry Pi running Raspbian 8.0. I have a shell script that triggers a Chromium Browser to open and go to a specified URL that changes every day. The shell script works when executed from the terminal. How would I get this to work through Gnome Schedule's GUI? I would like this to trigger everyday at a specified time. I've tried setting the command to /home/pi/test.sh, sh /home/pi/test.sh. I read something about needing to specify the display output since I'm running Gnome Schedule from root which isn't the current user logged in. So for that I tried export DISPLAY=:0 && /home/pi/test.sh. Is this going to be possible?
If you put
export DISPLAY=:0.0 at the top of your script rather than export DISPLAY=:0, this should work.
I have Plesk (or more accurately Parallels Small Business Panel) installed on my linux server. However, my knowledge of linux is pretty limited. I am trying to set up a cronjob that will run a php file.
I have found the scheduled tasks area in plesk and filled in the details for when i want the script to run e.g. 30 9 * * *. However I seem to be having difficulty writing the correct command. I am using:
usr/bin/php -q /var/www/vhosts/mywebsite.co.uk/httpdocs/admin/file_to_run.php
I have checked that the location of php is correct using:
whereis php
I have also checked that the path to the file is correct using:
find / -name 'file_to_run.php'
However the php page is not doing it's job at the specified time. Can anyone help me get to the bottom of this?
Two possibilities
1) Check if the script has an error by doing a dry run on the command line.
Because you will not see this error when the cron user runs the command.
2) Perhaps you want the output to go to a specific file?
You can redirect it as such :
usr/bin/php -q /var/www/vhosts/mywebsite.co.uk/httpdocs/admin/file_to_run.php > /your/destination/the_output
Unless your php script handles everything it needs on the inside, that is.