cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Jono
Champion Sweeper II

Hello - I have a custom computer action that schedules a reboot for 2am the following morning. It looks lke this:

cmd.exe /C psexec \\{computer} at 2:00am psshutdown -r -f -c -t 10 /accepteula


This works fine (see below), but I would like to be able to have LS ask me what time to schedule the reboot. I'm sure this would require a script. I can write a script that asks for data (InputBox?), but I don't know how to write a script that would then insert this information as a parameter for the AT command. Do any of you master script writers know how to do this?

Thanks,
Jono

Solutions:
See post #7 where, with the assistance of other posters, I was able to come up with a valid way to do this.
See also post #14 where danielm greatly improved upon this, expanding it to include other options for CHKDSK and handling scheduled tasks.

20 REPLIES 20
dteague
Engaged Sweeper III
Stupid question...

Just wondering why you are using PSEXEC and not just AT since you can pass the computer name on it and it does the same thing.

Just wondering.
Jono
Champion Sweeper II
dteague wrote:
Just wondering why you are using PSEXEC and not just AT since you can pass the computer name on it and it does the same thing.

Hi dteague,

If I use "AT %sdtime% \\%1 shutdown..." in the batch file it schedules this task on my computer:
"\\computer shutdown..."
This would require my computer to be on the network and turned on at the scheduled time. In most cases, the target computer is a server that I'd want to reboot in the middle of the night. My computer would be with me at home and shutdown at that time.

If I use "psexec \\%1 AT %sdtime% shutdown..." it schedules this task on the target computer:
"AT {time} shutdown..."
This is the desired result.

I hope that helps.

Jono
dteague
Engaged Sweeper III
I see what it is, you were putting the time in the wrong place. It has to be after the server name for it to schedule it on that machine. I am supprised that it scheduled it on your machine, and not just errored and given you the AT help dump.
Jono
Champion Sweeper II
dteague wrote:
I see what it is, you were putting the time in the wrong place. It has to be after the server name for it to schedule it on that machine. I am supprised that it scheduled it on your machine, and not just errored and given you the AT help dump.

Good call dteague; my mistake. I suppose it works either way, though yours is a bit simpler.

Thanks,
Jono
ejensen
Engaged Sweeper III
Nice work Jono! Thanks for contributing to the community too!
Jono
Champion Sweeper II
Thanks ejensen! Here's what I came up with; it was simpler than I thought.

This is the action in LS config
{actionpath}SchedReboot.bat {computer}


This is the SchedReboot.bat file
@echo off
ECHO.
set /p sdtime=What time?
ECHO.
ECHO Time entered: %sdtime%
psexec \\%1 at %sdtime% shutdown -r -f
ECHO.
ECHO Press any key to close this window...
pause>nul

This asks for a time to assign to the sdtime variable, echos back what it now sees as the sdtime variable, and then uses psexec and builds the AT command with the sdtime variable on the chosen computer.

I created another one (named SchedShutdown.bat) that's identical except for the "-r" in the shutdown command is "-s" for shutdown instead of reboot.

I just tested it and it works great. I hope others might find this useful. I suppose this same idea could be used to schedule any command to run at a certain time.

Thanks again for your help, ejensen.
ejensen
Engaged Sweeper III
Jono,

I ran across this and figured it would help you come up with a solution. If you have problems doing this just let me know and I will help build something for you.
http://www.robvanderwoude.com/userinput.php
Jono
Champion Sweeper II
I was never able to get the psshutdown to work correctly as a scheduled task, but the native shutdown command combined with the AT command worked very well.

My custom action for a scheduled reboot now looks like this:
cmd.exe /K psexec \\{computer} at 2:00am shutdown -r -f

I also have a custom action to schedule a shutdown which is the same as the reboot, only replacing the -r for reboot with -s for shutdown.

I still haven't been able to find the time to work on the 2-batch-files solution to having LS ask me for a time. Once I have that done, I'll post it here for anyone who may be interested in the same thing.
ejensen
Engaged Sweeper III
Actually Jono, after thinking about it a few minutes... just use the psshutdown utility form sysinternals (same guys that make psexec).

there is a command line switch to specify the time of the shutdown or reboot:
-t          Specifies countdown in seconds until shutdown (default is 20) or
the time of shutdown (in 24 hour notation)
Jono
Champion Sweeper II
ejensen wrote:
Actually Jono, after thinking about it a few minutes... just use the psshutdown utility form sysinternals (same guys that make psexec).

there is a command line switch to specify the time of the shutdown or reboot:
-t          Specifies countdown in seconds until shutdown (default is 20) or
the time of shutdown (in 24 hour notation)

Hi ejensen - Thanks for the reply. I'm actually already using psshutdown and I could specify the time there rather than the AT command, but I want to be able to choose a time for the reboot each time I execute the command.

I'd like to be able to click the custom action, enter a time, and have that time be entered into the -t argument in the command. This would be a lot easier than having to edit the command in LS Config each time.

I'll spend some time today working on the dual batch file option you mentioned earlier.

By the way, in my original post, I spoke too soon. The scheduled task actually doesn't work, but I'm not sure why. It runs if I run it at a cmd prompt, but not when it's scheduled. This morning I reset the command to use the -t argument to schedule the time rather than the AT command.

I'll post results here.

New to Lansweeper?

Try Lansweeper For Free

Experience Lansweeper with your own data.
Sign up now for a 14-day free trial.

Try Now