Categories
DOS PowerShell Tips

SVN checkout using BATCH and PowerShell

Few days back I was working on a script to automate project builds. And at one step I was required to checkout code from source control and build the application. Since everything was done using a single script there was no way I could prompt to user GUI because in this case it was just a plain PowerShell script. After bit to experimenting and Googling, I was able to find a solution that fit my need, but then I thought to use same script as a batch script (of course with some modifications) and I was surprised to see that many commands in PowerShell are declared and used differently then what we normally do in batch script. That was same case with SVN commands.

I use Tortoise SVN for both work and myself, so I am showing this using it. But if you look at help file it is clear that Tortoise SVN is more like a GUI tool not something that can be used via CLI, in fact it is even recommended by author himself to use Official SVN tools instead of Tortoise SVN. But lucky for us, Tortoise SVN already includes official SVN tools !! You can find them at “%ProgramFiles%\TortoiseSVN\bin\”, it includes exes like SVN, SVNAdmin, SVNLook, SVNVersion etc. If they are not there then most likely they are excluded during installation (which is default installation choice). So just grab installation EXE from Tortoise SVN site and run installer again to install these tools.

Categories
DOS Tips

File Integritry verfication … using File Checksum Integrity Verifier

Lets say you download a file from internet and you want to make sure that this file’s source is legitimate (say you just downloaded new ISO of Ubuntu from their site). Or in another case you want to make sure that there is no corruption in file that you just downloaded from internet (now you may argue that why bother ? Can’t you just download that file again ? … but sometimes it’s not that simple … and that’s how it works in office bureaucracy Open-mouthed smile) … in both of these cases usually you can ask for hash key generated using either MD5 or SHA-1 algorithms from person who sent you that file and compare those keys with key generated by you and if that matches then everything is good … and if it doesn’t then something funny is going on. In fact, today it is very common practice by many companies to provide MD5 and/or SHA-1 hash keys for their software to make sure that they are not tempered with.

And File Checksum Integrity Verifier aka FCIV is a mouthful name of a tiny utility by MSFT. Sole purpose of this utility is to create or compare file integrity using MD5 or SHA-1 hashing algorithms. First step for that is of course to get FCIV from MSFT Download Center. Only issue (!!) is there is no GUI for this utility, so you will need to use terminal to run this utility.

Following is copy from help of this tool,

//
// File Checksum Integrity Verifier version 2.05.
//

Usage:  fciv.exe [Commands] <Options>

Commands: ( Default -add )

        -add    <file | dir> : Compute hash and send to output (default screen).

                dir options:
                -r       : recursive.
                -type    : ex: -type *.exe.
                -exc file: list of directories that should not be computed.
                -wp      : Without full path name. ( Default store full path)
                -bp      : specify base path to remove from full path name

        -list            : List entries in the database.
        -v               : Verify hashes.
                         : Option: -bp basepath.

        -? -h -help      : Extended Help.

Options:
        -md5 | -sha1 | -both    : Specify hashtype, default md5.
        -xml db                 : Specify database format and name.

To display the MD5 hash of a file, type fciv.exe filename

Categories
DOS Tips

Archiving using 7ZIP commandline

Couple of days back I had to create a script to archive all files from number folders as part of bigger data transfer task. Since that machine was a bit of older flavor of Windows it didn’t had PowerShell, and I had to reboot machine is I wanted to install PowerShell so I decided to use my favorite script language … batch script to accomplish task.

In my script I used WinRAR (because we have licenses for that) but since I have 7ZIP at home machine, I have modified a script to use 7Zip instead of WinRAR (other business logics). I have one folder called “sample” and this script archives all files located inside of this folder and creates a 7ZIP file called Test.7z. It is just one line command,

Categories
DOS VBScript

Send Email in Batch File (using VB Script) without installing SMTP server

In my never ending desire to use Batch files to do just about anything, I was recently needed batch file to send an email to users once task is completed with “Success” or “Failure” results. And since I was already using batch files to do number of things, I thought it wouldn’t harm if it can do one more thing …. send email to users !! Actually it is not possible to send email just from plain DOS commands so I added a bit flavor to it with use of good ‘ol VB Script. This distant cousin of batch script has always been popular among system admins, hackers and various other titles you can think of, due to its ability to access system level resources and more close ties to standard programing language VB.

I found over Google that most people suggest to use “CDO.Message” object to send email in VB Script. But there were not any “correct” script which solved my problem, it is because most of those scripts were required me to install SMPT server in my machine. But finally I was able to find a script which was doing exactly what it suppose to do (I honestly don’t remember which site was that because I had checked number of forums).

Finally working script is (with minor modification to original script),

Categories
DOS

If … Else in Batch file

If you have ever used If .. Else in batch file then you know that how frustrating it is to work with it. In fact if you google this case then you will find that it is very common belief that ELSE doesn’t exits for BATCH files !!! I think it is just because very specific requirement to use this command is to write them in proper format.

Recently I had to add some “extra” feature in my backup script … an email notification via batch file for success or failure of operation. After spending many hours in forums finally I was able to figure out this mystery. Batch script will recognize If .. ELSE … only if it is written in following format,

Categories
DOS How To

FTP connection using BATCH file

I really love DOS commands. They are so powerful and yet simple (most of the time). Few days back I was required to create a script to download files from FTP site to local folder, and this has to be done at scheduled time. I decided to use my all time favorite script language to do this job …. yes a batch file with dos commands, honestly it is not like that I am partial to batch file and dos commands (hmm, may be a little bit)  but I personally find PowerShell a bit cryptic. And thus I try to avoid it’s use (plus our production servers don’t have PowerShell installed)

Ok, aside from my reasons for not using PowerShell, I was able to create a tiny script for my task. Script is very simple, it opens up a connection to ftp site. Provides user id and password. Selects FTP download directory (in this demo script it also selects file). And download it to local folder. And this is a simple TEXT file.

Categories
DOS Tips

Infinite loop in DOS

Few days back I was working on some task and as a part of that I was required to run some command line utility. Now condition was to keep running that utility all the time and for whatever reasons it crashes it should start by itself.

Now, I could do it by creating another application or service which monitors this utility all the time and if it crashes, this service or monitoring app restarts that utility. But I thought it is more work just for a simple task. Instead I chose a different and easy approach. I created a batch file that runs in infinite loop and made this utility run inside that loop. For sake of some history I also added a log for each restart event. And that’s it !!

I am posting my script below (of course it is not original script but it is nearly as original)