Issue when using crontab


#1

Hi there, I have a simple script that runs a program installed by homebrew. If I execute the script manual by:
./script.sh

It runs and work great. But if I call the exact same script from a crontab, it seems it cant run the program in script.sh. Anyone have any idea?

The script.sh looks like:
#/bin/bash
cd “/Users/yabbah/automounts/media/tv/Idol”
/usr/local/Cellar/svtplay-dl/2.0/bin/svtplay-dl -A https://www.tv4play.se/program/idol

And the crontab:
* * * * /bin/sh /Users/yabbah/scripts/script.sh >/dev/null 2>&1


(Sean Molenaar) #2

Not really a homebrew question if you ask me, but you can try writing something to a file in the script to see if it even runs at all?


#3

When running from terminal with:
./script.sh >> terminal_out.txt

$ cat terminal_out.txt
Episode 1 of 10
Url: URL-AS-I-CANT-POST-MORE-THEN-TWO-LINKS
Episode 2 of 10
Url: URL-AS-I-CANT-POST-MORE-THEN-TWO-LINKS
Merge audio and video into URL-AS-I-CANT-POST-MORE-THEN-TWO-LINKS
Merging done, removing old files.
Muxing idol.s14e01.idol.2018.del.1-10315860-tv4play.ts into idol.s14e01.idol.2018.del.1-10315860-tv4play.mp4
Muxing done, removing the old file.

When running in crontab as:

          • /bin/sh /Users/niklas/scripts/script.sh >> /Users/niklas/scripts/cron_out.txt

The output say:

$ cat cron_out.txt

Episode 1 of 10
Url: URL-AS-I-CANT-POST-MORE-THEN-TWO-LINKS
Cant detect ffmpeg or avconv. Cant mux files without it.
Episode 2 of 10
Url: URL-AS-I-CANT-POST-MORE-THEN-TWO-LINKS
Cant detect ffmpeg or avconv. Cant mux files without it.

and so on.

This is why I relate it to homebrew, but Im now sure :slight_smile:
/yabbah


(Sean Molenaar) #4

Ah, so it does run. That wasn’t really clear from the original post. It still isn’t really specific to homebrew though.

If the script can’t detect ffmpeg you might need to add /usr/local/bin to the PATH variable that’s available to the cronjob. https://unix.stackexchange.com/questions/148133/how-to-set-crontab-path-variable


#5

But ffmpeg isn’t located under /usr/local/bin, cant be found with ‘whereis ffmpeg’. Thats why I think its something related with programs installed with homebrew?


(Sean Molenaar) #6

Well, the website says that you need ffmpeg (https://svtplay-dl.se/install/) so I guess you need to install ffmpeg.


#7

It was installed with homebrew. Might be why its not in the bin-paths. But I cant find any other way to install it beside homebrew either :confused:


(Sean Molenaar) #8

if it was installed with homebrew it should be in /usr/local/bin, unless you picked a custom path for homebrew in which case this gets a lot more difficult.


#9

bash -lc in the cron did the trick. Thanks for pointing me in the correct direction :slight_smile:


(Sean Molenaar) #10

You’re welcome! Glad to see it’s working.