Hi
And welcome to LQ!
I think you have misdiagnosed the problem. Your variable ($FILE) is fine. The problem is the wildcard is not getting expanded.
In a Linux shell, when wild cards are used that are not in quotes, they are expanded by the shell. So, for example, when you say:
Code:
for FILE in ${PGPPATH}/*.pgp;
the shell will try to replace ${PGPPATH}/*.pgp with everything that matches that expression. For some reason in your cron job it is not able to, and so the loop executes once with $FILE set to the actual wildcard expression. That is what you see printed out in your log. (I hope that was clear. I had to try several times for it not to be even more confusing.
)
Just to illustrate with another example, look what happens when I try a directory listing using a wildcard expression that doesn't match anything.
Code:
$ ls junk.*
ls: junk.*: No such file or directory
I have no files in that directory that match junk.*. So the shell cannot do a substitution and the
ls command tries to find a file with an asterisk in its name! Or if I put that into a loop like yours:
Code:
$ for FILE in junk.*; do
> echo $FILE
> done
junk.*
So the question is why can't the shell expand your wildcard expression in the cron job.
One possibliity is it couldn't read the directory. I have just verified that when this is the case the shell silently leaves the wildcard expression unexpanded rather than give you an error message.
You didn't give particulars of how you ran this as a cron job. (Cron jobs can run from /etc/crontab, from files in the directory /etc/cron.d, or from individual users' crontab's, controlled with the
crontab command.) What I am wondering is if when you ran it as a cron job whether it was running as a user that couldn't read the $PGPPATH directory.