Command does not work when executed via cronjob

Asked

Viewed 65 times

0

I’m trying to create a cronjob executing 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 backups from my server to my folder on Dropbox. It works perfectly when I run it by Putty. But when it runs via cronjob it is returned to my email the following error:

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

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

1 answer

1


Escape the %:

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

Read more here


Alternative:

Create a file with what will be executed by routine:

executarotish.

#!/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

  • Thank you very much, the second alternative was the one that worked. In the first one still presents the same error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.