Shell script doesn't collect password file ...
Running the below shell script seems to be ignoring the password file I feed it. I suggest this all the time. If I enter it, the rest of the script runs smoothly, but when I run it through cron I really need to get it to read from a 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 source to share
Your problem is line 2:
p=$(<password.txt)
What you are doing here is to run an "empty command" in a subshell, saving its output to a variable p
. Instead, you want to run a command that dumps the contents of the password file to stdout
. So:
p=$(cat <password.txt)
This will do the trick.
a source to share
Where is the password file located? cron
has another PATH
one that can cause the scripts to behave differently when you run them yourself.
Possible solution one, put
cd `dirname $0`
at the top of the script, which will be cd
in the script directory when it is run.
There are two possible solution, try pointing the file directly with an absolute path:
gpg --passphrase-file /some/path/password.txt -o "$destination/$FILENAME" -d "$FILE"
a source to share