skyhigh99 wrote: ↑Tue Feb 05, 2019 4:57 pm
I've got a bit of a problem with automating a task with Cron... I'm trying to run a command to take a screenshot of a webpage and save it on the desktop, but it's not running through Cron. If I try to execute it manually, it's working fine.
The command I'm using is: wkhtmltoimage --height 1500 --width 350 google.com /home/pi/Desktop/print.png
I've installed the GUI for Cron and put the command in the box. If I check the log, I can see that the task has been started but it's not outputting a screenshot. I'm new to a lot of this, so am I missing something obvious as to why it's not working?
Thanks
- "If I try to execute it manually, it's working fine."
- Exactly how are you running it manually?
- Are you running it in a terminal window on a logged in gui?
- Via ssh?
- Via vnc?
Tasks started by cron have a very limited environment and don't have access to a GUI.
- Does wkhtmltoimage require a desktop/GUI?
- Did you include the full path to wkhtmltoimage in your crontab entry?
- When cron runs your job, is the desktop running with a user logged in?
If wkhtmltoimage requires a desktop, and one is available when the cron task runs try wrapping your command in a script and calling the script from cron. For example:
Code: Select all
#!/bin/bash
DISPLAY=:0
/path/to/wkhtmltoimage --height 1500 --width 350 google.com /home/pi/Desktop/print.png >> /var/log/error.log 2>&1
Replace /path/to with the correct path.
The above may still fail so check the log file.
While Andyroo has suggested using /var/log/error.log, you may find that unless your cron job is running as root it won't be able to write there. Use something like /tmp/wkhtmltoimage.log instead. Generic names like error.log aren't very usefull as they don't connect back to what generated the log.
Arguing with strangers on the internet since 1993.