Solved

pgp batch job

Posted on 2006-10-31
10
373 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
scoresSpecial  challenge 13 57
bigHeights  challenge 13 64
CONDITIONAL MAX STATEMENT IN T-SQL 3 72
Math Equation 23 105
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

839 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