Server Backup script not working as iCal alarm

Hi everyone,

I have 4 scripts which are very similar. They check modification dates of certain files on a server, and if the files are less than 24 hours old, creates a compressed archive of the relevant parent folder. This is then moved to a hotfolder and sent to another site so they have up-to-date files.

The thing is that when the scripts are run manually (either as compiled applications or from within Script Editor) they run fine. Because I would like this to be an automatic daily process, I have assigned the scripts to iCal alarms (run script or open file). However, for some reason the scripts run, but return in the logfile that no new files have been found, even though I have deliberately made some test files to collect and it works when running the scripts manually.

I have an on idle script running in the background that ensures all the servers are connected.

My question is: Is this a peculiarity with iCal that people know about? Is there a solution or another method of executing the script/running the application at a certain time of day?

Thanks for reading and for any advice you can give

Regards

Ian

This is the top section of the script that finds the files:


if server_checklist is not equal to {server1, server2} then
	err_mailnotifyroutine()
	quit me
else
	doScript()
end if

to AddDateTo(aName)
	tell ((current date) - 1 * days) to tell 100000000 + day * 1000000 + (its month) * 10000 + year as string ¬
		to return aName & (text 2 thru 3) & "." & text 4 thru 5 & "." & text -2 thru -1
end AddDateTo

on doScript()
	set folder_name to AddDateTo("TestCTV - ") --set folder_name to AddDateTo("Creatives - Overlap Data from ")
	tell application "Finder"
		try
			make new folder at desktop with properties {name:folder_name}
		end try
	end tell
	set pdk to (path to desktop) as string
	set Mast_Arc to (pdk & folder_name) as alias
	
	set Usr_Folder to POSIX path of alias "Customer Creatives:"
	text 1 thru -2 of the result -- Remove the trailing slash; `find` will add one itself
	do shell script "/usr/bin/find " & quoted form of result & " -iname '*.ai' -or -iname '*.eps'"
	set the_files to paragraphs of the result
	set new_items to {}
	set itemstomovelist to {}
	tell application "Finder"
		repeat with this_file in the_files
			try
				set my_file to ((contents of this_file) as POSIX file) as alias
				set my_mod_date to modification date of my_file
			end try
			if my_mod_date is greater than ((current date) - (1 * days)) then
				set end of new_items to my_file
				set x to container of my_file as alias
				repeat 3 times
					set x to container of x as alias
				end repeat
				set end of itemstomovelist to x
			end if
		end repeat
	end tell
--rest of script
end doScript

Since posting, I have discovered CronniX and tried to use that, but the same problem exists - the script will run, but not find files on the server that have creation/modified dates less than 24 hours old. Grrr!

Does anyone know how to even troubleshoot/debug a script when it is being run outside of script editor?

Thanks

Ian

ps I can post the whole script, but it is quite long.

Hi Ian,

try a file specifier instead of an alias, this is recommended if the file isn’t on a local volume


.
 try
	set my_file to POSIX file this_file as Unicode text
	set my_mod_date to modification date of file my_file
end try
.

Stefan,

Thank you for that advice. I shall give it a try and see if it helps.

Regards

Ian

I am getting very unpredictable results :frowning:

For example; I have four Illustrator files on the server that I know have been modified today. When I run just the ‘find’ portion of the script in Script Editor and call the results, it is finding 1 of those files. Run it again and it may find 2 or maybe all 4.

The only answer I can come up with is putting the ‘find’ in a repeat loop and getting either the last result or an average (whatever that would be!)

If it is to do with some internal indexing of the ‘find’ results or latency in doing so, can I guarantee that if I do a ‘find’ x number of times, the last one will be correct?

Very frustrating.

BTW, Stefan, this line comes up with an error


set my_file to POSIX file this_file as Unicode text

'Can’t make POSIX file (item 1 of {a big list}
so I am using:


set my_file to this_file as POSIX file
set my_mod_date to modification date of file my_file

Thanks

Ian