1

I wrote a simple script that cycles through a file and grabs some links from a file to run through a program called gallery-dl. This script works fine if i run it manually but just wont work with crontab or rc.local, ive tried everything i could think of and have found that while the script does run it doesn't actually download anything like its supposed to. I tested this by having the script create a random directory which worked but the actual download doesn't work when the script is called automaticly but it does when the script is called manually, i dont understand why it wont work when called through crontab or rc.local.


inline=$(echo '/home/pi/automation/gallery-dl-auto') #automation input file
outline=$(echo '/home/pi/downloaded/') #where the files download
cd $outline
while read line; do
  gallery-dl $line;
  sed -i '1d' $inline
done < $inline```

1 Answer 1

0

This symptom (program works normally but not from cron) usually means the program depends on an environment variable that is set when you run normally but not set when run from cron.

In your cron job, add printenv | sort > /tmp/my-cron-env. Then, from the shell prompt, do printenv | sort | diff -u - /tmp/my-cron-env and see what's different. You may need to add some environment settings to your cron job.

4
  • Do you mean as a separate job in cron or do i add it to my pre-existing job? Commented Nov 8, 2020 at 17:22
  • Either. I'd probably modify the existing job
    – Waxrat
    Commented Nov 9, 2020 at 16:05
  • I see, ive been doing other research about how cron works too, the file has this data written to it after running: HOME=/home/pi LANG=C.UTF-8 LOGNAME=pi PATH=/usr/bin:/bin PWD=/home/pi SHELL=/bin/sh What do i need to do to get the script to work in a cron environment? Commented Nov 10, 2020 at 15:59
  • cron just launches whatever command you specify. The command could be the pathname of a shell script, then in the shell script you could export whatever envars you need. Some cron implementations let you put envar settings in your crontab file. You can also use the env command to set environment variables. So, three ways to do what you ask, assuming I'm understanding your question correctly
    – Waxrat
    Commented Nov 13, 2020 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.