I have a headless ubuntu server that I only have command line access. I’ve been able to create a backup job that runs successfully when I manually run the backup command from the command line. I’m trying to schedule the same command to run from Crontab on a schedule. Whenever it runs from the Crontab it returns the error -
[exit status 200] Found 1 commands but expected 2, commands:
For Troubleshooting - I installed Cronitor will allows me to select and run Cron jobs. When I trigger the backup cron job using Cronitor it also runs successfully.
Can crontab not be used to run backup commands. Is there something else I should be using instead?
You should be able to use crontab to run Duplicati jobs. Sounds like you are missing some command line options though. Maybe it would be easier to put the full command line with all parameters in a shell script, then just call the shell script from crontab?
Any chance the issue relates to ‘single’ vs “double” quoting?
I haven’t used Cron in a few years but surely you need to feed it the command line for Duplicati, which probably needs to be enclosed in quotes but contains loads of double quotes " ". That means the string that is the Duplicati command line would likely need to be enclosed in a set of single quotes ’ ’ otherwise the string will be trimmed off at the next double quote resulting in fewer than expected values being passed on, eg. 1 command vs 2 commands.
This is a common issue when getting another program to run other “outside” code. It’s possible Cronitor adds the single quotes on it’s own in the background (or stores the string in a completely different way) whereas Crontab may not auto enclose in single quotes, explaining why ‘the same command’ gave different results.
As someone who always wants to use double quotes for everything, I’m painfully aware that sometimes a double quote really isn’t the same as a single quote.
I’m also a big fan of using script files as @drwtsn32 suggests. Scripts are generally easy to manage, can be edited directly and you can easily back them up, transfer and reuse them. I’ve “kicked myself in the ampersand” way too many times for not putting a command line into a script only to have to rebuild it all over again after a failure or machine swap.
The “sixth” field (the rest of the line) specifies the command to be run. The entire command portion of the line will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile.
Having said that, it took some looking to find examples of a complex command line. Scripts were plentiful.
Quoting can be a pain… I don’t know if any of this relates to the issue. Post actual sanitized line if you like.
Putting it between triple backticks will keep it presented literally, otherwise forum software may interpret it.