I find myself having to check within a script whether a download via ‘/tool fetch’ successfully finished. It seemed easiest to store the current time/date via ‘/system clock get time’ and ‘/system clock get date’, try to fetch the file and compare its creation-time, but despite the documentation claiming that the type of that attribute is ‘time’, on 3.28 I find that it’s a string instead:
/system script> :put ("timestamp is " . [/file get [/file find name=test.txt] creation-time] . " and typeof creation-time is " . [:typeof [/file get [/file find name=test.txt] creation-time]]);
timestamp is aug/10/2009 16:46:03 and typeof creation-time is str
Is there any way to convert that string back into a time type variable? I was only able to cast strings like ‘8h4m36s’ but cannot figure out how to add a date portion to that.
Or am I overlooking a far simpler method to detect whether the download successfully finished?
What if your downloadscript wrote “finished” in a log or to a txt file ? If I remember correctly the script wait for the download to complete before executing the rest of the script, not sure what happends if connection is lost though..
Because if the file download fails due to a 404 (for example), previously downloaded files with the same name stick around and have their original file size. If nothing else works I can delete the file after processing and simply check for existence after a download, but for our business process it’s far preferable to keep the file around.
How do you use [:totime] on a string such as “aug/13/2009 17:02:03”? I was only able to convert strings such as “17h02m03s” (which I could construct from “17:02:03”), and couldn’t get anywhere with dates at all. Since the last successful download may have been on the previous day, simply comparing times instead of datetimes is insufficient.
Just create varables for day, month and year and use string manipulation to fill in those variables from your creationtime, then compare those values to current date..