0

I have the following script:

#!/bin/bash
echo "$(date +"%r")"

if [ "$FOLDER_ID" != "0" ]
then
  node /sync.js -d $FOLDER_ID -l /Downloads
fi

I'm using docker container and I have passed the env variable FOLDER_ID when started the container. This variable supposed to be set when starting the docker container by passing it as ENV.

When I run this script, the node command runs as expected, but when the cron job runs the script, it prints the date at but doesn't execute the node command correctly (I think the issue is related to the $FOLDER_ID variable).

  • 2
    I can't let it pass without commenting: echo "$(date +"%r")" is just a long way of saying date +%r. Separately, I don't suppose FOLDER_ID has any spaces or tabs in it? – Jeff Schaller Mar 9 at 1:26
  • no it does not. I can use FOLDER_ID in the commandline with no problems – ialqwaiz Mar 9 at 1:29
  • another common problem with cron jobs is that they (as you've seen) run with a new, bare, environment. Are there any other environment variables (perhaps related to the 'node' command or your script) that are also missing? – Jeff Schaller Mar 9 at 1:46
  • Yes. I have two different folder_id variables and I have the same issue with the second part of the script. I assumed I didn't use the env variables correctly... – ialqwaiz Mar 9 at 1:50
  • @ialqwaiz Cron jobs run in a limited environment with certain restrictions, one of which is a limited set of environment variables. If you're relying on specific environment variables (such as the FOLDER_ID variable), you'll need to set them explicitly before using them in your script. – Haxiel Mar 9 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.