I'm using a Raspberry 2 with Raspbian and owncloudcmd. To run owncloudcmd I created /home/pi/owncloud.sh #!/bin/sh owncloudcmd --non-interactive -n /home/pi/Pictures/picpreview/ http://my_owncloud_server.de/remote.php/webdav/picpreview
When I strart it manually (sh owncloud.sh) everyting is working as expected. But when I create a crontab -e like this:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# ...
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
*/1 * * * * /home/pi/Pictures/preview.sh
*/1 * * * * /home/pi/owncloud.sh
The other file /home/pi/Pictures/preview.sh looks like this:
NOW=$(date +"%Y-%m-%d_%H-%M")
raspistill -q 50 -awb cloud -sh 40 -co 50 -o ~/Pictures/picpreview/$NOW.jpg
convert ~/Pictures/picpreview/$NOW.jpg[1296x972] ~/Pictures/picpreview/$NOW.jpg
the images in picpreview are not syncronized to owncloud. I already did chmod -x and I also have another sh script in cron that works fine (the one to take the images). I also tried to setup the crontab as sudo -i but same result here (and I dont think it's neccessary to run this as sudo)
preview.sh -> works owncloud.sh -> dont work
Does anyone knows what I'm doing wrong with owncloud.sh?
It sounds like the script (or some command that it uses) relies on some environment variables which are set up when you're running at a command-prompt, but are missing when running via cron.
Cron tends to run things with a pretty minimal environment by default - you could try just adding a new line in the crontab running the command "env > ~/cronenv.txt" to see what the environment contains. Hopefully that will allow you to see what's missing that you need.
Updated:
If you need to set environment variables, you can either add a line near the top of the crontab of the form "NAME=value", or you can put these declarations at the start of the command that you want to run.
For example, in this case you could have used the declaration "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/pi/dev/owncloud/client-build/bin/"
Note that not all variants of cron support the first form (a separate line at the top of the file), in particular Arch Linux and RedHat seem to use a variant that doesn't like this. In that case, you should still be able to use the second form although that means that you have to repeat the environment declaration for each command that needs it.