Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GPG and System Command

Status
Not open for further replies.

menkes

Programmer
Nov 18, 2002
47
US
I have a script that does several functions, one of which is decrypt a file. We previously used PGPCmdLine, but need to switch to GnuPG (GPG) v1.2. We are running on W2K Server using Perl 5.8.

The specific line in question is:
Code:
$status = system($gpg, "--passphrase-fd", "0", "$some_dir\\$some_file", "<", "$another_dir\\Passphrase.txt");
This code reads in the appropriate passphrase from an external file to decrypt a source file.

When I run the script from the command line, all is well. However, this script needs to be called from a Windows Scheduled Task. When running from the Scheduled Task, the script aborts when it reaches the above code.

Note: The same user is utilized from the command line and from the Scheduled Task.

Any ideas? I am thinking the "<" is causing the problem, but not sure why or how to fix.
 
When $some_dir\\$some_file or $another_dir\\Passphrase.txt are interpolated, do they have embedded blanks? e.g. C:\Progam Files\my.file? if it does, you will need to quote it for Windows' benefit
Code:
$status = system($gpg, "--passphrase-fd", "0", "[red]\"[/red]$some_dir\\$some_file[red]\"[/red]", "<", "[red]\"[/red]$another_dir\\Passphrase.txt[red]\"[/red]");
You should probably do this anyway, even if it doesn't fix the problem, just to guard against embedded blanks in the future.

Also, are the paths of the files relative? Maybe when you run it from the scheduler, it starts in the wrong working directory?
 
I thought system just expected a single string, rather than multiple parameters?
Code:
$command="$gpg --passphrase-fd 0 \"$some_dir\\$some_file\" < \"$another_dir\\Passphrase.txt\"";
system($command);

But I've been wrong before ;-)
--Paul

cigless ...
 
No, it takes a list. But as all it seems to do is to join the list with a blank space, and execute the whole thing, then I guess the distinction is largely academic...
 
Thanks for the input.

I did check the paths, neither of which have spaces. I quoted them anyways as suggested. Still no luck.

As for the list instead of a single string...habit. Single string when a parameter is from user input can be used to run commands you did not intend to run. The list format protects against this. For this script, there is no user input so does not matter. But best to pick the safest approach and be consistent.

Anyhoo...still hoping someone has an answer to this dilemna.
 
Ah, found the answer.

I rechecked all and found that the user was NOT the same. For the Scheduled Task, it was using a domain admin account. When I changed it to a local admin account, it worked just fine.

Don't really understand why....but I'll take what I can get.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top