How to run gpg from a script run by cron?

后端 未结 7 1304
予麋鹿
予麋鹿 2021-02-05 04:10

I have a script that has a part that looks like that:

for file in `ls *.tar.gz`; do
  echo encrypting $file
  gpg --passphrase-file /home/$USER/.gnupg/backup-pas         


        
7条回答
  •  长情又很酷
    2021-02-05 04:35

    You should make sure that GPG is in your path when the cronjob is running. Your best guess would be do get the full path of GPG (by doing which gpg) and running it using the full path (for example /usr/bin/gpp...).

    Some other debugging tips:

    • output the value of $? after running GPG (like this: echo "$?"). This gives you the exit code, which should be 0, if it succeded
    • redirect the STDERR to STDOUT for GPG and then redirect STDOUT to a file, to inspect any error messages which might get printed (you can do this a command line: /usr/bin/gpg ... 2>&1 >> gpg.log)

提交回复
热议问题