Search code examples
bashcron

"bad variable name" in bash script started by cron


Works just fine when running it manually on the shell but when I setup a cronjob to run it on reboot I get "bad variable name".

#! /bin/sh
# /etc/init.d/duplicityCleanUp
export PASSPHRASE=foo
duplicity remove-older-than 30D --force --gio smb://remote/archiv/
duplicity remove-all-but-n-full 1 --force --gio smb://remote/archiv/
unset PASSPHRASE

Solution

  • There is a space between the #! and the /bin/sh. I don't think this is the reported problem but it needs fixing *

    I guess that you are using a version of Unix or Linux where /bin/sh is not bash so the export syntax is wrong.

    Alter your script to say

    PASSPHRASE=foo
    export PASSPHRASE
    

    See this answer UNIX export command

    * it's not a problem, see comments