Checksum validation

Hi,

I’ve asked to transfer 3 to 4 shell scripts to end machine (linux server) where success criteria is measured by validating check sum of transferred files against the original (provided results are captured in a file). If any one could explain the action script logic for performing this, that would be of great help?

My plan is to proceed this below action commands

  1. download (downloading files to be transferred)
  2. continue if (validate size and sha1)
  3. move (transfer files to folder requested)
  4. wait (to set ownership, group and permissions)
  5. struck here… (where cksum of transferred file should be validated against original one and write to .txt file about success and failure status)… need help

Hi @Ipctea,

First of all, if all the files are ending up in the same location, you might want to consider using the Software Distribution Dashboard option to zip up your files (use the “Compress folders at depth” checkbox). Then you can extract the files to the destination instead of having to deal with the “check if location exists / delete if file exists / copy new file” stuff. If your files are going to multiple destinations, then you have to deal with those checks.

For step #5, you are going to want to compare the checksums of the downloaded files against the checksums of the transferred files. I have an example that should help you get started. I’m on Windows though, so the linux commands have not been tested and may need adjustments. And you can make this all shorter by not storing the hashes in parameters, but I did so for readability and in case you want to record them to the results file or something.

parameter "baseFolder" =  "__Download/"

// Move files into subfolders and unescape file names
move "__Download/DD6C34F4880554574EA9C9823CCC1538BBE32CA4" "__Download/File1.bftemp"
move "__Download/87045BB6220608E55F44C6190B2143EF78411212" "__Download/File2.bftemp" 

// Extract the files to the download folder.
extract "File1.bftemp" "{parameter "baseFolder"}"
extract "File2.bftemp" "{parameter "baseFolder"}"

// Record the file hashes of the source files.
parameter "File1SrcHash" = "{sha1 of download file "File1.txt"}"
parameter "File2SrcHash" = "{sha1 of download file "File2.txt"}"

// copy the files to their destinations
// add copy code here

// Record the destination checksums and use an empty string if the file is missing. 
parameter "File1DestHash" = "{sha1 of file "/path/to/dest/File1.txt" | ""}"
parameter "File2DestHash" = "{sha1 of file "/path/to/dest/File2.txt" | ""}"

parameter "ResultsFilePath" = "/path/to/results.txt"
delete "{parameter "ResultsFilePath"}"

// If the hashes don't match, record the filename.
if {parameter "File1SrcHash" != parameter "File1DestHash"}
  runhidden echo File1ChecksumError >> "{parameter "ResultsFilePath"}"
endif

if {parameter "File2SrcHash" != parameter "File2DestHash"}
  runhidden echo File2ChecksumError >> "{parameter "ResultsFilePath"}"
endif

// Use the exit return code to quickly know which devices had any issues.
if {exists file (parameter "ResultsFilePath") whose (content of it does not contain "Error")}
	parameter "returnCode" = "0"
else
	parameter "returnCode" = "1"
endif

exit {parameter "returnCode"}

Thanks a lot, Sean… I’ll give a try to adopt this to Linux flavor.

P.S - here files are going to multiple destinations.