Posts

Showing posts with the label dos

Running Logon Scripts with CPAU

Image
I like scripting . It helps me manage my client PC 's, perform redundant tasks, push out software updates, among other things. Most of the users on my network do not have privileges to install software, so this affects how some of my scripts function . I discovered that setting GPO to install applications with elevated privileges doesn't mean that the logon scripts also get processed the same way. This annoyed me, and I quickly found a solution. Introduce CPAU, from http://www.joeware.net/ . A neat little utility that takes the place of RUNAS, and very easy to use. I use it to launch my domain logon script, as it copies a HOST file , and other batch files run locally by the scheduler service, which are not allowed write by ordinary users. The following line encodes a file that will run logon.cmd using the credentials provided it. \\mydc\netlogon\cpau.exe -u mydomain\UserWithPermissions -p UserWithPermissionsPassword -ex \\mydc\netlogon\logon.cmd -file \\mydc\netlogon...

Awwwwww, crap!

After all the work I did on these batch files that decrypt PGP files, and un-tar the contents, I've found an error, and a pretty major *duh* one at that. Seems my logic was way off when it came to doing some date checking. Since the files I check have a naming convention that uses the previous days date, I was simply subtracting one from %TODAY%. Seems ok, right? No. This is the *duh* part. I simply subtracted 1. From 1001, that makes 1000. That's not a day, when you are using MMDD as the convention. What I was looking for was 930. NOT the same. SSSssoooooo, I added a bit I found on Experts Exchange (THANK you..for saving me MUCHO time). I was also having some issues trapping the ERRORLEVEL. Apparently, since FOR loops in DOS batch scripts are executed as one command, PGP never has a chance to pass it's exit code to my IF check, so this was also modified. The modded file is here .

shBrushBatch for Google SyntaxHighlighter

I really like highlighting my code in this blog. Ever since finding the Google SyntaxHighlighter Widget at FaziBear's , I've been going through all my old code, and cleaning up my posts. I read a nice article at WaltCo Tech about extending it to incorporate other brushes for WordPress. He also seems to do what I do, but a bit better when it comes to explaining things: WriteItDownNowBeforeYouForgetHowYouDidThatOldMan I'm really not that old, but I do tend to stick my fingers in many things, and coding tends to be one of them. At times, I'll find myself trying in vain to use a function from VB in PHP, or something of that nature. One of the hazards of not being fluent maybe? In any case, I've created my own brush for DOS Batch scripts: dp.sh.Brushes.Batch = function() { var builtins = 'APPEND ATTRIB CD CHDIR CHKDSK CHOICE CLS COPY DEL ERASE DELTREE ' + 'DIR EXIT FC COMP FDISK FIND FORMAT FSUTIL HELP JOIN ' + ...

More PGP Fun

This process outlined is not unlike what I wrote about in my post here , but involves a bit more logic. The script has to check for files that were posted that morning, but also have a file naming convention of the previous day. I've also got about 200 EMR postscript files to sort by date of service. First, the source PGP/tar files must be checked for existence, and must be a pair with the proper date formatted file name. @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION :: ////////////////////////////////////////////// :: :: Set path variables for key access, passphrase, :: and source our key files. SET PGPPATH=C:\PGP_keys\ SET PGPPASS=MYPGPPASS :: The "KEY" to a successful import of our keys is running these coMMands as the user :: that will be running this script. :: pgp +batchmode -ka %PGPPATH%SECRING.SKR :: pgp +batchmode -ka %PGPPATH%PUBRING.PKR :: pgp -ke 0xEC671710 > %_LOGFILE% ECHO -- START %DATE% - %TIME% -- >> %_LOGFILE% ECHO -----------------------...

Using Batch to decrypt PGP and more

Image
This script was recently written to automatically process files on our FTP server. They come in daily, in pairs, and dated with todays date, e.g. XXERUP0912.dat.pgp. The script checks for existence, ensures a pair is found, makes sure they are the right and same date, then decrypts them and calls an external program I wrote to inject them into a SQL database for querying via ASP, which I also wrote. If any of the steps fail, it gets logged, and an email notification is sent to a number of folks. I had a bit of an issue with expansion, but found the error of my ways in short order... @ECHO On SETLOCAL ENABLEDELAYEDEXPANSION :: ////////////////////////////////////////////// :: :: Set path variables for key access, passphrase, :: and source our key files. SET PGPPATH=C:\PGP_Keys\ SET PGPPASS=MYPGPPASS :: The "KEY" to a successful import of our keys is running these commands as the user :: that will be running this script. :: pgp +batchmode -ka %PGPPATH%SE...

Database updates

I needed a method to update a database application across a WAN, and found that I could do this with my Linux firewalls, and Windows batch scripting. The topology is this: Win2k Svr -> Linux FW -> Internet Win2k Svr batch file: @ECHO OFF SET _LOGFILE=mydb.log Net Stop "SQL Anywhere - mydb" >> "%_LOGFILE%" ATTRIB -R "C:\Program Files\mydb Software\mydb\mydb.db" ATTRIB -R "C:\Program Files\mydb Software\mydb\mydb.log" NET USE Z: \\win2ksvr\home\backup\backup\mydb admpass /USER:domain\admin FOR /F "tokens=2,3,4 delims=/ " %%i in ('DATE /T') do set d=%%k%%i%%j FOR /F "tokens=1,2,3 delims=:. " %%i in ('TIME /T') do set t=%%i%%j%%k XCOPY "C:\Program Files\mydb Software\mydb\mydb.log" Z: CALL :REPORT %ERRORLEVEL% "C:\Program Files\mydb Software\mydb\mydb.log" XCOPY "C:\Program Files\mydb Software\mydb\mydb.db" Z: CALL :REPORT %ERRORLEVEL% "C:\Program Files\mydb Softwar...