Solved

pgp batch job

Posted on 2006-10-31
10
362 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
Comment Utility
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
Comment Utility
Thanks.  That should do it.  I will let you know if it doesn't work.
0
 

Author Comment

by:casit
Comment Utility
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
 
LVL 6

Expert Comment

by:dave_moats
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:casit
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks you so much.  I knew that its just that at 1AM I was thinking straight :)
0
 
LVL 6

Expert Comment

by:dave_moats
Comment Utility
Lack of sleep is a killer.....have a good one.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
gHappy challenge 67 108
matchUp  challenge 6 48
tripleUp challenge 7 65
countHi challenge 25 84
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article will show, step by step, how to integrate R code into a R Sweave document
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now