I am having some problems with scheduling import with Cron. I wrote a shell script to take a screenshot with import and store it in a hidden directory to be out of the way until the images are needed. The script works flawlessly on it's own, but when I schedule it in Cron, the new screenshots never show up. Cron is working just fine, so that's not the problem. Here's the original script:
I saved this to /usr/bin/grabber and made it executable. Like I said, it works fine on it's own, even when I just type "grabber" into the run dialog or a terminal.
In crontab, I set it up like this:
(It's set to run every minute only for testing until I get it working)
I've tried several variations of the script, including condensing it into a static command ("/usr/bin/import -window root -quiet -geometry 640x400 -silent /home/<USERNAME>/.grabber/`date '+%Y%m%d%H%M%S'`.jpg" and "/usr/bin/import -window root -quiet -geometry 640x400 -silent /home/<USERNAME>/.grabber/`date`.jpg") both in the script and inserting it directly into crontab instead of telling it to run the script. I would much rather the dynamic script, but whatever works. I have also tried putting it in /etc/crontab as "* * * * * <USERNAME> /usr/bin/grabber", but that still didn't work.
Any advice?
Code:
#!/bin/bash # Takes a screenshot with ImageMagick. # Screenshot will save to ~/.grabber/ # The name of the file screenshot='grab'; # Adds the date and time to the filename nano=`date '+%Y%m%d%H%M%S'`; # Adds the file extension extension='.jpg'; # Generate a filename file="$HOME/.grabber/$screenshot-$nano$extension"; # Use ImageMagick to take the screenshot import -window root -quiet -geometry 640x400 -silent $file;
In crontab, I set it up like this:
Code:
* * * * * /usr/bin/grabber
I've tried several variations of the script, including condensing it into a static command ("/usr/bin/import -window root -quiet -geometry 640x400 -silent /home/<USERNAME>/.grabber/`date '+%Y%m%d%H%M%S'`.jpg" and "/usr/bin/import -window root -quiet -geometry 640x400 -silent /home/<USERNAME>/.grabber/`date`.jpg") both in the script and inserting it directly into crontab instead of telling it to run the script. I would much rather the dynamic script, but whatever works. I have also tried putting it in /etc/crontab as "* * * * * <USERNAME> /usr/bin/grabber", but that still didn't work.
Any advice?
Comment