0

I'm not sure if this is more appropriate here or over in Stackexchange so sorry if I got it wrong.

I was wondering if I could get some help: So I'm trying to use cron to run my shell script which consists of multiple duplicity calls (so I can back up different things without it all being jumbled together in a mess)

In my crontab

09 15 * * * /home/backup.sh

in my home/backup.sh

duplicity --no-encryption --exclude /home/itq/anotherOne /home/itq file:///media/backup/backup/tester/Ian

duplicity --no-encryption /media/ab file:///media/backup/backup/tester/ab

The problem that I'm getting is that

Command line error: Expected 2 args, got 1
Enter 'duplicity --help' for help screen.
/home/backup.sh: 2: /home/backup.sh: file:///media/backup/backup/tester/Ian: not found
Command line error: Expected 2 args, got 1
Enter 'duplicity --help' for help screen.
/home/backup.sh: 5: /home/backup.sh: file:///media/backup/backup/tester/ab: not found

even though it works just fine when I run it from terminal (outside of the script). It's probably worth noting that /media/backup is a harddrive that I've mounted to the system (it's called backup, and is the first backup file after media) so IDK if that changes anything.

IanQ
  • 103
  • 2

1 Answers1

0

I'm not familiar with duplicity, but your description about difference between running the script in terminal and by cron would suggest that tasks run by cron could be using a different interpreter. Try adding the following line to the very start of your script file.

#!/bin/sh
  • Thanks! Silly question, but is it also possible to get it to stop posting an update to /var/mail/root ? I'm scheduling it as sudo (setting up the backup system for a research lab and I don't have ownership of all their files) – IanQ Jul 13 '16 at 19:56
  • It is. If you want to disable it for all cron jobs, edit your crontab file by `crontab -e` and add to the top of the file `MAILTO=""`. This _should_ disable the mail alerts. If you want to do it just for the one cron task, it looks something like this: `0 1 10 10 * /path/backupscript.sh >/dev/null` But i'm not sure on the specifics from top of my head. – BorysekOndrej Jul 13 '16 at 20:01