Script works fine while execute, but won't run from cronjob

I have a script called "record.sh" It looks like:

#!/bin/bash
/usr/bin/vlc -vvv rtsp://admin:[email protected]:554/ch0_0.h264 --sout=file/ts:Videos/VideoCaptures/recording-$(date +"%Y-%m-%d_%H-%M-%S").mp4 -I dummy --stop-time=3600 vlc://quit
exit

Also make it executable with: chmod +x record.sh

Now the real question. When I double click on the script, it executes fine! But when I make an cronjob (crontab -e)

*/60 * * * * /home/pi/record.sh

it will not run at all.

Even the following cronjob won't work;

*/60 * * * * /usr/bin/vlc -vvv rtsp://admin:[email protected]:554/ch0_0.h264 --sout=file/ts:Videos/VideoCaptures/recording-$(date +"%Y-%m-%d_%H-%M-%S").mp4 -I dummy --stop-time=3600 vlc://quit

What am I doing wrong?


--sout=file/ts:Videos/... -- presumably, the Videos directory is in your home directory. cron's current directory is /. You'll need

--sout=file/ts:$HOME/Videos/...

Additionally, percent signs are special in crontabs and need to be escaped:

recording-$(date +"\%Y-\%m-\%d_\%H-\%M-\%S").mp4

Check your crontab(5) man page.