Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"bad variable name" in bash script started by cron

Tags:

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
like image 577
steros Avatar asked Oct 08 '14 07:10

steros


2 Answers

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

like image 85
Vorsprung Avatar answered Sep 19 '22 12:09

Vorsprung


They way you export or set your variables are incompatible with your shell. When executing the script - try and use different shell.

sh yourscript.sh 
bash yourscript.sh 
ksh yourscript.sh
csh yourscript.sh
zsh yourscript.sh 

Mostly bash will work for you.

like image 44
Muthuveerappan Avatar answered Sep 21 '22 12:09

Muthuveerappan