Uptime 7 days or more prompt to restart

Hi im a SYS admin and i was wondering if some one might be able to give me a hand. I wish to have an apple script that will pop up a message telling the user to reboot if the uptime is 7 days or more and if not to not display a message.

I plan to have it running every hour through a Launch Agent but i am stuck on the syntax i need in the script.

The reason for this is because we have many systems running eg mcx etc that require a reboot now and again. Some people leave the machine on for weeks and causes a nightmare for me. My idea is to have a message that keeps popping up and they reboot because they get annoyed with it.

Hi,

look at this article, it describes an installer for a launchd agent, which triggers a script daily at a specific time

The shell command uptime displays the uptime beside other information.
You have to parse the string to get the time part.
This example works for time strings < 24 hr, I haven’t tested it for longer periods, because I shut down my computer every night


set uptimeResult to do shell script "uptime"
set {TID, text item delimiters} to {text item delimiters, "up  "}
set uptimeResult to text item 2 of uptimeResult
set text item delimiters to ","
set uptimeResult to text item 1 of uptimeResult
set text item delimiters to TID
uptimeResult

Thanks with the help for getting me started. This is what i have with tested on a machine that was up for 14 days. The problem is i dont konw what sytax to use to add in if uptime ends with 7 days or greater than or something like that. At the moment the script runs because it is looking for 14 days and works but tomorrow will be day 15 and it will fail.



set uptimeResult to do shell script "uptime"
set {TID, text item delimiters} to {text item delimiters, "up  "}
set uptimeResult to text item 1 of uptimeResult
set text item delimiters to ","
set uptimeResult to text item 1 of uptimeResult
set text item delimiters to TID
try
	if uptimeResult ends with "14 days" then
		
		display dialog "Your computer has not been restarted for over a week. Please reboot as soon as possible to ensure that all security patches deployed to the machine are applied. This also helps the machine run at optimum performance. "
	end if
end try







try this


set uptimeResult to do shell script "uptime"
set {TID, text item delimiters} to {text item delimiters, "up  "}
set uptimeResult to text item 2 of uptimeResult
set text item delimiters to ","
set uptimeResult to text item 1 of uptimeResult
set text item delimiters to TID
if uptimeResult contains "days" then
	set numberOfDays to word 1 of uptimeResult as integer
	if numberOfDays > 14 then
		display dialog "Your computer has not been restarted for over a week. Please reboot as soon as possible to ensure that all security patches deployed to the machine are applied. This also helps the machine run at optimum performance. "
	end if
end if


Thanks very much this is great i was bashing my brains for ages trying to work it out :smiley:

Now i am going to compile it as an app and create a launch agent with lingon. Package them both up and see how i go


set uptimeResult to do shell script "uptime"
set {TID, text item delimiters} to {text item delimiters, "up  "}
set uptimeResult to text item 1 of uptimeResult
set text item delimiters to ","
set uptimeResult to text item 1 of uptimeResult
set text item delimiters to TID
if uptimeResult contains "days" then
	set numberOfDays to word 1 of uptimeResult as integer
	if numberOfDays > 7 then
		display dialog "Your computer has not been restarted for over a week. Please reboot as soon as possible to ensure that all security patches deployed to the machine are applied. This also helps the machine run at optimum performance. " with title "Uptime Warning"
	end if
end if

compiling as app is not needed. The launchd agent can call a compiled script file with osascript

Of course, silly me. Thanks for all your help