pgp batch job

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.
casitAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
dave_moatsConnect With a Mentor Commented:
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
 
casitAuthor Commented:
Thanks.  That should do it.  I will let you know if it doesn't work.
0
 
casitAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
dave_moatsCommented:
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
 
casitAuthor Commented:
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
 
casitAuthor Commented:
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
 
dave_moatsCommented:
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
 
casitAuthor Commented:
Thanks you so much.  I knew that its just that at 1AM I was thinking straight :)
0
 
dave_moatsCommented:
Lack of sleep is a killer.....have a good one.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.