如何从由cron运行的脚本运行GPG? [英] How to run gpg from a script run by cron?

查看:180
本文介绍了如何从由cron运行的脚本运行GPG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了,看起来像一个部分的脚本:

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-passphrase \
    --simple-sk-checksum -c  $file
done

有关,如果我手动运行该脚本某些原因,工作完全正常,所有文件都是加密的。如果我运行这个作为cron作业,回声$文件工作正常(我看加密<文件>在日志中),但文件不会被加密, GPG沉默失败,并没有标准输出/ stderr输出。

For some reason if I run this script manually, works perfectly fine and all files are encrypted. If I run this as cron job, echo $file works fine (I see "encrypting <file>" in the log), but the file doesn't get encrypted and gpg silent fails with no stdout/stderr output.

任何线索?

推荐答案

事实证明,答案是比我预想的更容易。有一个 - 批参数丢失,GPG试图从/ dev / tty的,不为cron作业存在阅读。要调试,我已经使用 - 出口通状态写入错误参数。但要使用我被退出状态2,呼应 $?如CD-人提出报道的启发。

It turns out that the answer was easier than I expected. There is a --batch parameter missing, gpg tries to read from /dev/tty that doesn't exist for cron jobs. To debug that I have used --exit-on-status-write-error param. But to use that I was inspired by exit status 2, reported by echoing $? as Cd-Man suggested.

这篇关于如何从由cron运行的脚本运行GPG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆