2014-10-08 187 views
2

当在shell上手动运行它时工作得很好,但是当我设置一个cronjob在重新启动时运行它时,我得到“bad variable name”。由cron启动的bash脚本中的“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 
+0

'#!/bin/sh'有错误的空间。它应该是'#!/ bin/sh'。 – fedorqui 2014-10-08 09:37:49

+2

@fedorqui我认为这个空间太错了,但显然它是可以接受的... http://stackoverflow.com/questions/10197690/perl-shebang-space – 2014-10-08 11:00:09

+1

@MarkSetchell有趣!我每天都在这个网站学习东西。非常好知道。 – fedorqui 2014-10-08 11:39:07

回答

7

还有就是#!/bin/sh之间的空间。我不认为这是报道的问题,但它需要修复

我想你使用的是Unix或Linux版本,其中/bin/sh不是bash,所以 导出语法是错误的。

改变你的脚本说

PASSPHRASE=foo 
export PASSPHRASE 

看到这个答案UNIX export command

+0

你可以检查:“ls -lrt/bin/sh”来查看它是否真的指向bash – user1729564 2016-02-11 09:38:53