Jump to content
Sign in to follow this  
OrthodoxyUSA

Here's a hard one. Open files that you did not open.

Recommended Posts

OrthodoxyUSA

Automated systems are using FTP to transfer very large 7z files over a WAN into a folder on your server.

You would like to test each file (7z -t <filename>) as they are completed during the night.

How will you know that the file is finished copying and free to be tested?

Here's what I've been trying...

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include <Constants.au3>

#Include <File.au3>

#Include <Array.au3>

#RequireAdmin

Global $FileGetList1[1000],$FileGetList2[1000]

FileChangeDir("H:\CIS-NG")

While 1

FileDelete(@TempDir&"\fileget1.txt")

RunWait(@ComSpec & " /c " & "dir H:\CIS-NG\*.* /b /OD >"&@TempDir&"\fileget1.txt",@TempDir,@SW_HIDE)

_FileReadToArray(@TempDir&"\fileget1.txt",$FileGetList1)

For $x = 1 to $FileGetList1[0]

Local $hFile = FileOpen("H:\CIS-NG\"&$FileGetList1[$x], 2)

If $hFile = -1 Then

ContinueLoop

Else

FileClose("H:\CIS-NG\"&$FileGetList1[$x])

FileFlush("H:\CIS-NG\"&$FileGetList1[$x])

RunWait(@ComSpec & " /K " & "C:\Progra~2\7-zip\7z.exe t H:\CIS-NG\"&$FileGetList1[$x]&" -pPassword",@TempDir,@SW_MAXIMIZE)

If @error Then

FileDelete("H:\CIS-NG"&$FileGetList1[$x])

FileDelete("H:\Backups\7z.txt")

FileWrite("H:\Backups\7z.txt","The readability of 7z, "&$FileGetList1[$x]&" has failed. The file has been deleted.")

RunWait(@ComSpec & " /c " & "c:\backup\blat.exe H:\Backups\7z.txt -to backups@domain.com -server inet1.domain.com -subject "&'"'&"FAILED TEST OF 7z, "&$FileGetList1[$x]&" -f 7zTest@domain.com")

Else

FileMove("H:\CIS-NG"&$FileGetList1[$x],"H:\2BBURNED")

FileDelete("H:\Backups\7z.txt")

FileWrite("H:\Backups\7z.txt","The readability of 7z, "&$FileGetList1[$x]&" has passed.")

RunWait(@ComSpec & " /c " & "c:\backup\blat.exe H:\Backups\7z.txt -to backups@domain.com -server inet1.domain.com -subject "&'"'&"PASSED TEST OF 7z, "&$FileGetList1[$x]&" -f 7zTest@domain.com")

EndIf

EndIf

Next

WEnd

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Paul

Share this post


Link to post
Share on other sites
water

To make sure the file has successfully been transferred I would use a lock file:

transfer the lock file xyz.lock (content doesn't matter)

transfer the data file xyz.zip

delete the lock file xyz.lock

As long as xyz.lock exists you can't be sure that xyz.zip has been transferred successfully.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
kylomas

Paul,

Two thiings:

1 - I don't see away out of your while...wend loop

2 - What is @error being set by in the following code?

RunWait(@ComSpec & " /K " & "C:Progra~27-zip7z.exe t H:CIS-NG"&$FileGetList1[$x]&" -pPassword",@TempDir,@SW_MAXIMIZE)

If @error Then

Is it possible thast your pgm (7-zip) is opening a file and encountering an error?

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
OrthodoxyUSA

To make sure the file has successfully been transferred I would use a lock file:

transfer the lock file xyz.lock (content doesn't matter)

transfer the data file xyz.zip

delete the lock file xyz.lock

As long as xyz.lock exists you can't be sure that xyz.zip has been transferred successfully.

That's a good idea. It would work for my situation where I have control over both ends.

Why wouldn't I just copy a text file at the end with the same name as the 7z and then hinge my job from that? My job could delete it when it's finished.

Of course none of this would be an answer for someone who does not have control over the sending end.

I was a bit shocked at not being able to find an easy answer for this inside AutoIt.

I have a small program called Log Monitor 1.4.2 (© 1998-2002 Vadim Dumbravanu) that monitors a folder for changes, and performs an action when a file is closed. It works well for my purpose, but the product is no longer available and I think I could improve upon the idea for my purpose.

Paul

Share this post


Link to post
Share on other sites
OrthodoxyUSA

Paul,

Two thiings:

1 - I don't see away out of your while...wend loop

2 - What is @error being set by in the following code?

RunWait(@ComSpec & " /K " & "C:Progra~27-zip7z.exe t H:CIS-NG"&$FileGetList1[$x]&" -pPassword",@TempDir,@SW_MAXIMIZE)

If @error Then

Is it possible thast your pgm (7-zip) is opening a file and encountering an error?

kylomas

Hi kylomas,

Answer to number one... it was intentional.

Number two... I was hoping to pick up on the exit code of the 7z. (I've never tried before.)

The only problem that the 7-zip is running into is that the file is still open.

Thank for thinking about it!

Paul

Edited by OrthodoxyUSA

Share this post


Link to post
Share on other sites
water

Why wouldn't I just copy a text file at the end with the same name as the 7z and then hinge my job from that? My job could delete it when it's finished.

That's even easier and should work fine for your situation.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
kylomas

Paul,

Using a file in a "handshaking" kind of technique will only work if you are certain that 7z always runs successfully. I would monitor the output to the command window for 7z messages as a basis for further actions (note: I've never used this program so the entire point may be moot).

Command window output can be monitored with the stdout and stderr read functions.

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Blue_Drache

7z is rather difficult to automate properly. I've yet to try the solutions put forward here: due to lack of time/will/Diablo 3


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
OrthodoxyUSA

Don't get hung up on the 7-zip's guys... that part works without problems.

The problem is knowing when the incoming file is closed and no longer being written to, before we start testing the file.

If we start the test before the file is finished OR something else has it open for any reason, the test will fail.

Paul

Share this post


Link to post
Share on other sites
kylomas

Paul,

Precisely, so 7-z output needs to be monitored, yes?

kylomas

edit:additional info

How will you know that the file is finished copying and free to be tested?

see post #10 from the link provided by Blue_Drache

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
jchd

I'm not currently in the position to test anything but while the file is being written to, if you loop trying to open the file in append mode, it _should_ return an error. Again, untested.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×