Command does not work when executed via cronjob

0

I'm trying to create a cronjob that runs the following command

sudo sh /usr/local/bin/send_site_backup_files_to_dropbox.sh |
ts "[%Y-%m-%d %H:%M:%S]" 2>&1 |
tee /var/log/send_backups_to_dropbox.log |
mailx -s "Report for Vesta backup files sent to Dropbox" [email protected]'

The command executes a script that uploads the backups from my server to my dropbox folder. It works perfectly when I run it through PuTTy . However when I run via cronjob the following error is returned to my email:

/bin/sh: -c: line 0: unexpected EOF while looking for matching '"'
/bin/sh: -c: line 1: syntax error: unexpected end of file

Without this part ts "[%Y-%m-%d %H:%M:%S]" 2>&1 it works, then the problem is there.

    
asked by anonymous 11.04.2018 / 23:11

1 answer

1

Escape % :

"[\%Y-\%m-\%d \%H:\%M:\%S]"

Read more here

Another alternative:

Create a file that will be executed by the routine:

executeotina.sh

#!/bin/bash
sudo sh /usr/local/bin/send_site_backup_files_to_dropbox.sh |
ts "[%Y-%m-%d %H:%M:%S]" 2>&1 |
tee /var/log/send_backups_to_dropbox.log |
mailx -s "Report for Vesta backup files sent to Dropbox" [email protected]'

In your crontab, call the file executarotina.sh

    
11.04.2018 / 23:17