Shell Duplicity backup script not running via cronjob

spython01

Member

Reaction score: 8
Messages: 44

I am running FreeBSD 11.1-RELEASE-p10 and trying to schedule a cronjob to run a daily script which will use duplicity(1) to backup my ~/Documents directory to an Azure blob. The script (~/.duplicity/.backup1.sh) reads as follows:

Code:
#!/bin/bash

# the true variable values are in my real script
export AZURE_RESOURCE_GROUP="azure_resource_group"
export AZURE_STORAGE_ACCOUNT="azure_storage_account"
export AZURE_ACCOUNT_NAME="azure_account_name"
export AZURE_STORAGE_ACCESS_KEY="azure_storage_access_key"
export AZURE_ACCOUNT_KEY="azure_account_key"
export CONTAINER_NAME="azure_container_name"
export GPG_KEY="gpg_key"
export PASSPHRASE="passphrase"

HOME="/home/spython01"

/usr/local/bin/duplicity \
    --verbosity info \
    --encrypt-sign-key=$GPG_KEY \
    --full-if-older-than 7D \
    --log-file $HOME/.duplicity/info.log \
    $HOME/Documents \
    azure://$CONTAINER_NAME

# unset key environment variables
unset AZURE_RESOURCE_GROUP
unset AZURE_STORAGE_ACCESS_KEY
unset AZURE_ACCOUNT_KEY
unset GPG_KEY
unset PASSPHRASE

The script permissions are:
-rwxr-xr-x 1 spython01 spython01 1069 Jun 9 11:59 .backup1.sh

and I can run it fine by itself via:
$ . /home/spython01/.duplicity/.backup.sh

Note the "dot space slash" at the beginning.

The issue is that I can't get the script to run via cron(8). My crontab(5) is as follows:
Code:
$ crontab -l
SHELL=/bin/bash
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
# Order of crontab fields
#m    hour    mday    month    wday    command
10    13    *    *    *    . /home/spython01/.duplicity/.backup1.sh

At the appointed time, nothing happens but I do get the following in my /var/log/cron:
Jun 9 13:10:00 t430 /usr/sbin/cron[9838]: (spython01) CMD (. /home/spython01/.duplicity/.backup1.sh)

Per the handbook, when I run:
$ env -i SHELL=/bin/bash PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin LOGNAME=spython01 . /home/spython01/.duplicity/.backup1.sh

I get:
env: .: Permission denied

Any ideas or suggestions?
Thanks in advance!
 
OP
spython01

spython01

Member

Reaction score: 8
Messages: 44

Remove the .
Do you mean remove the . when running the script directly or in crontab(5)?

When I do the former, I get:
Code:
$ env -i SHELL=/bin/bash PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin LOGNAME=spython01 /home/spython01/.duplicity/.backup1.sh
env: /home/spython01/.duplicity/.backup1.sh: No such file or directory
$ /home/spython01/.duplicity/.backup1.sh 
bash: /home/spython01/.duplicity/.backup1.sh: /bin/bash: bad interpreter: No such file or directory

When I update crontab(5) to:
Code:
$ crontab -l
SHELL=/bin/bash
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
# Order of crontab fields
#m    hour    mday    month    wday    command
26    15    *    *    *    /home/spython01/.duplicity/.backup1.sh

Nothing still happens other than:
Jun 9 15:26:00 t430 /usr/sbin/cron[7268]: (spython01) CMD (/home/spython01/.duplicity/.backup1.sh)
 

k.jacker

Aspiring Daemon

Reaction score: 469
Messages: 740

Yes, remove the . from the crontab file. The ./ or . / tells the shell to execute something in the current directory, or relative from the current directory.
Since you execute your script from crontab via the full path, there is no need for the dot, makes no sense.

bash is in /usr/local/bin/
You have to change the shebang in your script, it points to nowhere.... I guess you took your backup1.sh from Linux?
bash is 3rd party software, so on FreeBSD it's in /usr/local/bin/bash.

There is no need to change the SHELL= line in the crontab file.

Edit: whereis bash
 
OP
spython01

spython01

Member

Reaction score: 8
Messages: 44

Yes, remove the . from the crontab file. The ./ or . / tells the shell to execute something in the current directory, or relative from the current directory.
Since you execute your script from crontab via the full path, there is no need for the dot, makes no sense.
Thanks, k.jacker! That did the trick! I appreciate your help on this!
You have to change the shebang in your script, it points to nowhere.... I guess you took your backup1.sh from Linux?
bash is 3rd party software, so on FreeBSD it's in /usr/local/bin/bash.
You are correct. I'm more comfortable in bash(1) but I wouldn't say I'm an expert by any means, as you can see. And, yes, I was referencing a tutorial that assumed I was using Ubuntu. I didn't even realize that my shebang wasn't pointing anywhere. Thanks again!
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 12,044
Messages: 38,506

Remove /etc/ from your $PATH. It doesn't belong there.
 
OP
spython01

spython01

Member

Reaction score: 8
Messages: 44

Remove /etc/ from your $PATH. It doesn't belong there.
Good to know. I guess I need to read the handbook a bit more carefully next time as I didn't notice that the configuration given was for the system crontab, not a user.
 
Top