• Print

Author Topic: Automatically execute console command at specific system time (on a schedule)  (Read 5162 times)

0 Members and 1 Guest are viewing this topic.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
I've looked into Auto-Shutdown/ restart solutions in the past when it comes to SteamCMD servers, but haven't found anything that works and is scalable. At the moment, I just set my windows machine to restart in the middle of the night, automatically sign in, and execute the ServerDoc Start All .exe. If you haven't figured it out yet, I host locally on a semi-dedicated windows machine.

Does anyone know a command or script that will run a command through the console when the computer/system time hits a specific time? EX: at 4:00 AM the console executes the command 'sv_shutdown 1' OR at 12:00AM January 1st of any year the server executes the command: 'ulx csay HAPPY NEW YEAR'

I imagine there are many other uses/solutions that this mechanic could be very useful for. I just don't have enough know-how when it comes to things like console commands or the lua language to do much about it. That's why I'm here to see if anyone with that know-how is willing to share their insight on the subject of automatically executing console commands based on system time (or similar).

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Google a program called ServerChecker. It's a great program I've used for years to run my servers. It checks process IDs to make sure the server isn't crashed and I believe you can schedule regular restarts through that program as well.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
But to answer your actual question. You can use os.Date (http://wiki.garrysmod.com/page/os/date) to get the date/time of the system in string format that you can then check against whatever you want...


for example:

Code: Lua
  1. local timestamp = os.date( "%d-%m-%H-%M-%S" , os.time() )
  2.  
  3. if timestamp == "01-01-00-00-01" then
  4.         game.ConsoleCommand( "ulx csay HAPPY NEW YEAR\n" )
  5. end
  6.  

You would just have to include that check in a timer or think hook that checked every second.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Thank you <3
I have the wiki page bookmarked, but wasn't expecting stuff like that to be in there (I don't know why I didn't think of it)
I'll be sure to check there first next time.

  • Print