Solved

pgp batch job

Posted on 2006-10-31
10
381 Views
Last Modified: 2008-01-09
I have pgp commandline installed on my server.  I get a pgp file in a folder on my server everyday.  I need to automate the decrypting of the file.  the command to decrypt is
pgp --decrypt filename
and the filename will be coming in a paramenter.
0
Comment
Question by:casit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 6

Accepted Solution

by:
dave_moats earned 500 total points
ID: 17852582
Here is a batch sample that takes one parameter.

It checks to make sure a parameter was passed in, then makes sure the parameter is an existing file and then calls the pgp command.

[START CODE]
@echo off

:: the incoming parameter will be stored in %1
:: make sure we have a parameter
if "%1"=="" goto DONE

:: now make sure it is a file that exists
if exist %1 (
   pgp --decrypt %1
)

:: just a tag so we can skip to the end if no
:: file name was passed in
:DONE
[END CODE]

Dave
0
 

Author Comment

by:casit
ID: 17855870
Thanks.  That should do it.  I will let you know if it doesn't work.
0
 

Author Comment

by:casit
ID: 17863314
I know this is kind of hard to follow but any clue on why it renames it in the C:\originalcsv folder but then it doesn't copy it to the
C:\BulkProcessor_LambentTesting\BulkProcessorTest\castest\DateOfDeath folder.
[code]
@echo off
:: the incoming parameter will be stored in %1
:: make sure we have a parameter
if "%1"=="" goto DONE

:: now make sure it is a file that exists
if exist %1 (
   pgp --passphrase "xxxxxx" --decrypt %1 --output C:\originalcsv\
)
setlocal
set set count=0
::
:: Default extension
if %ext%.==. set ext=.csv
::
:: Default path
:: Loop for all files in specified path; split name and extension
for %%a in (C:\originalcsv\*) do if "%%~xa".=="". call :process "%%~a" "%%~na"
echo.
echo %count% files found
echo.
goto :eof

:process
set f=%1
set n=%2
set /a count+=1
set new="%p%%n:~1,-1%%ext%"
set newf=%n:~1,-1%%ext%"
ren %f% %new%
copy %new% C:\BulkProcessor_LambentTesting\BulkProcessorTest\castest\DateOfDeath\%newf%
goto :eof
C:\BulkProcessor_LambentTesting\BatchProcessTrigger.exe
[/code]
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:dave_moats
ID: 17863384
Interesting......remove the @echo off line while you are testing and then see what it says at the copy line.

Make sure you run it from a command window so you can see the results.

Seeing the actual commands and any error codes should help.

Dave
0
 

Author Comment

by:casit
ID: 17864435
Here is the output
C:\Documents and Settings\system account\Desktop\automation>unpgp.bat test.pgp

C:\Documents and Settings\system account\Desktop\automation>if "test.pgp" == ""
goto DONE

C:\Documents and Settings\system account\Desktop\automation>if exist test.pgp (p
gp --passphrase "xxxxx" --decrypt test.pgp --output C:\originalcsv\ )
test.pgp:decrypt (0:output file C:\originalcsv\test)

C:\Documents and Settings\system account\Desktop\automation>setlocal

C:\Documents and Settings\system account\Desktop\automation>set set count=0

C:\Documents and Settings\system account\Desktop\automation>if . == . set ext=.c
sv

C:\Documents and Settings\system account\Desktop\automation>for %a in (C:\origin
alcsv\*) do if "%~xa". == "". call :process "%~a" "%~na"

C:\Documents and Settings\system account\Desktop\automation>if "". == "". call :
process "C:\originalcsv\test" "test"

C:\Documents and Settings\system account\Desktop\automation>set f="C:\originalcs
v\test"

C:\Documents and Settings\system account\Desktop\automation>set n="test"

C:\Documents and Settings\system account\Desktop\automation>set /a count+=1

C:\Documents and Settings\system account\Desktop\automation>set new="test.csv"

C:\Documents and Settings\system account\Desktop\automation>set newf=test.csv"

C:\Documents and Settings\system account\Desktop\automation>ren "C:\originalcsv\
test" "test.csv"

C:\Documents and Settings\system account\Desktop\automation>copy "test.csv" C:\B
ulkProcessor_LambentTesting\BulkProcessorTest\castest\DateOfDeath\test.csv"
The system cannot find the file specified.

C:\Documents and Settings\system account\Desktop\automation>goto :eof

C:\Documents and Settings\system account\Desktop\automation>echo.


C:\Documents and Settings\system account\Desktop\automation>echo 1 files found
1 files found

C:\Documents and Settings\system account\Desktop\automation>echo.


0
 

Author Comment

by:casit
ID: 17864769
Well I really need some help help here  I got everything working till the bottom.  I just can't get it to call that .bat on the bottom.  But when I call the .bat directly from the command line it works fine.
[code]
@echo off
:: the incoming parameter will be stored in %1
:: make sure we have a parameter
if "%1"=="" goto DONE

:: now make sure it is a file that exists
if exist %1 (
   pgp --passphrase "xxxx" --decrypt %1 --output C:\BulkProcessor_LambentTesting\BulkProcessorTest\castest\DateOfDeath\
)
setlocal
set set count=0
::
:: Default extension
if %ext%.==. set ext=.csv
::
:: Default path
:: Loop for all files in specified path; split name and extension
for %%a in (C:\BulkProcessor_LambentTesting\BulkProcessorTest\castest\DateOfDeath\*) do if "%%~xa".=="". call :process "%%~a" "%%~na"
echo.
echo %count% files found
echo.
goto :eof

:process
set f=%1
set n=%2
set /a count+=1
set new="%p%%n:~1,-1%%ext%"
set newf=%n:~1,-1%%ext%"
ren %f% %new%
goto :eof
C:\Documents and Settings\system account\Desktop\automation\batch.bat
[/code]
0
 
LVL 6

Expert Comment

by:dave_moats
ID: 17865786
To execute a batch file from within another batch file, you usually need to use the keyword call.

Something like:   call "C:\Documents and Settings\system account\Desktop\automation\batch.bat" ( I am using the quotes because of the spaces in the path. )

Right before you are trying to call the batch file, you have a goto statement.  Could that goto statement be skipping your attempt to call the batch file?

Dave
0
 

Author Comment

by:casit
ID: 17866025
Thanks you so much.  I knew that its just that at 1AM I was thinking straight :)
0
 
LVL 6

Expert Comment

by:dave_moats
ID: 17866046
Lack of sleep is a killer.....have a good one.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question