views:

60

answers:

4

Running the below shell script seems to ignore the password file I'm feeding it. I'm continually prompted for it. If I enter it, the rest of the script goes without a hitch, but as I'm running it via cron, I really need to get it to read from the file... Any suggestions?

#!/bin/sh
p=$(<password.txt)
set -- $p
pass_phrase=$1
destination="/var/www/d"
cd /var/sl/
for FILE in *.pgp;
do
    FILENAME=${FILE%.pgp}
    gpg --passphrase "$pass_phrase" --output "$destination/$FILENAME" --decrypt "$FILE"
    rm -f $FILE
done
A: 

You probably need to specify a full path to the file. Or in your cron job, first cd to the directory containing that file.

glenn jackman
A: 

Does --passphrase really exist? According to the manpage it doesn't, but the versions might be different.

Patrick
A: 

Where is the password file? cron has a different PATH, which can cause scripts to behave differently when you run them yourself.

Possible solution one, put

cd `dirname $0`

at the top of the script, which would cd into the script's directory when it runs.

Possible solution two, try specifying the file directly with an absolute path:

gpg --passphrase-file /some/path/password.txt -o "$destination/$FILENAME" -d "$FILE"
armandino
+1  A: 

Your problem lies in line 2:

p=$(<password.txt)

What you are doing here is to run an "empty command" in a subshell, storing its output in the variable p. What you rather want to do though, is to run a command that outputs the contents of the password file to stdout. So:

p=$(cat <password.txt)

This will do the trick.

Roland Illig