1

I'm trying to encrypt symmetrically (with gpg) a file from a cron job. The line in my script doing this is :

c/usr/bin/gpg --no-tty -vv --exit-on-status-write-error --batch --passphrase-file /home/backup/full/pass --cipher-algo AES256 --symmetric  fullbackup.tar.bz2 > error.log 2>&1

It's working well when I execute the script from prompt, but not from crontab.

I tried with or without the options --no-tty,--batch,--quiet,--passphrase-fd 0 with an cat passfile, --passphrase-file /gpg/mypass and others tricks found on other topics (here). Nothing works. The script is ran from crontab as root.

Adding a logfile with 2>&1 >error.log doesn't help as the file (70 bytes) is populated with random binary characters.

I'm on debian with gpg 1.4.12.

What else can I try?

Here is the script :

#!/bin/bash

#creating the tar
tar -cpjf /home/backup/full/fullbackup.tar.bz2 --directory=/to_backup
#enc it
/usr/bin/gpg --no-tty -vv --exit-on-status-write-error --batch --passphrase-file /home/backup/full/pass --cipher-algo AES256 --symmetric  fullbackup.tar.bz2 > error.log 2>&1

#[...] ftp upload
Community
  • 1
  • 1
Patator
  • 164
  • 1
  • 9
  • `gpg` is an application, not a verb. What are you trying to do? From the command line given, I guess you want to symmetrically encrypt a file. You also seem to successfully encrypt _something_, as you don't receive an error message, but some encrypted output. Please post the _exact_ cron line you're using and a minimal script example that leads to the problem ([how to post an SSCCE](http://sscce.org)). In a cron job, you should always use absolute paths. – Jens Erat May 05 '15 at 10:08
  • Thank you. I edited my post, correcting the typo and adding my script, wich is very simple : creating a tar from a directory, encrypting it, upload it with ftp. – Patator May 05 '15 at 12:14
  • I'd guess you're encrypting nothing (an empty string, or maybe a newline character) successfully. You could try piping the output through `| gpg --list-packets`. And my second guess is that giving an absolute path for the file to encrypt (`/home/backup/full/fullbackup.tar.bz2`), everything will work as expected. – Jens Erat May 05 '15 at 12:19
  • Ok... Shame on me. your 2nd though was the good one... rookie mistake. Thanks for your help! – Patator May 05 '15 at 14:20

1 Answers1

0

As pointed out by Jens Erat, gpg was needing the full path to the file to encrypt.

Community
  • 1
  • 1
Patator
  • 164
  • 1
  • 9