I am new to Unix and ksh script writing. I wrote a script that decrypts a gpg message. I get this error that I do not know how to resolve. I was hoping someone could look at my script and help me figure out what is going on. Thank you for any assistance you can provide. Here is the error:
gpg: processing message failed: eof
Here is my script:
#!/bin/ksh
####################################################################
# 1. Decrypt Inbound File #
# #
# Two parms are required: output file #
# encrypted file(to be decrypted) #
# #
####################################################################
# Variable declaration #
####################################################################
outputF=$1
encryptedF=$2
id=$$
####################################################################
# print_message #
# prints messages to log file #
####################################################################
print_message()
{
message="$1"
echo "`date '+%m-%d-%y %T'` $message"
}
#####################################################################
# Validate input parameters and existence of encrypted file #
#####################################################################
if [ $1 -eq ""] || [ $2 -eq ""]
then
print_message "Parameters not satisfied"
exit 1
fi
if [ ! -f $encryptedF ]
then
print_message "$id ERROR: $encryptedF File does not exist"
exit 1
fi
#####################################################
# Decrypt encryptedF #
#####################################################
gpg --output "$outputF" --decrypt "$encryptedF"
echo "PASSPHRASE" | gpg --passphrase-fd 0
print_message "$id INFO: File Decrypted Successfully"
This is not a gpg problem :-) Your script tries to run the gpg binary twice. The first call tries to decode the file:
gpg --output "$outputF" --decrypt "$encryptedF"
Since no means of passphrase input is given, gpg tries to read the passphrase from the console. What now happens, depends on your gpg configuration, ksh behaviour, etc., but I suspect interaction with STDIN is somehow crippled, resulting in the EOF error.
The solution of your problem: You have to add the passphrase source to the decryption call:
echo "PASSPHRASE" | gpg --passphrase-fd 0 --output "$outputF" --decrypt "$encryptedF"