Notification

Icon
Error

Schedule Reboot using AT and psshutdown with time input

Posted: Tuesday, January 3, 2012 11:40:33 PM(UTC)
Jono

Jono

Member Original PosterPosts: 111
2
Like
Hello - I have a custom computer action that schedules a reboot for 2am the following morning. It looks lke this:
Code:
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.
ejensen
#1ejensen Member Posts: 47  
posted: 1/4/2012 4:46:06 PM(UTC)
nice contribution.
you could probably use a batch file with the "choice" command and have that feed a second batch file.
ejensen
#2ejensen Member Posts: 47  
posted: 1/4/2012 5:45:57 PM(UTC)
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:
Code:
-t Specifies countdown in seconds until shutdown (default is 20) or
the time of shutdown (in 24 hour notation)
Jono
#3Jono Member Original PosterPosts: 111  
posted: 1/4/2012 5:59:38 PM(UTC)
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:
Code:
-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.
Jono
#4Jono Member Original PosterPosts: 111  
posted: 1/5/2012 4:50:28 PM(UTC)
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:
Code:
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
#5ejensen Member Posts: 47  
posted: 1/11/2012 6:10:33 PM(UTC)
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
#6Jono Member Original PosterPosts: 111  
posted: 1/11/2012 7:50:11 PM(UTC)
Thanks ejensen! Here's what I came up with; it was simpler than I thought.

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


This is the SchedReboot.bat file
Code:
@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
#7ejensen Member Posts: 47  
posted: 1/12/2012 4:57:21 PM(UTC)
Nice work Jono! Thanks for contributing to the community too!
dteague
#8dteague Member Posts: 79  
posted: 1/13/2012 8:12:18 PM(UTC)
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
#9Jono Member Original PosterPosts: 111  
posted: 1/19/2012 6:30:22 PM(UTC)
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:
Code:
"\\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:
Code:
"AT {time} shutdown..."
This is the desired result.

I hope that helps.

Jono
dteague
#10dteague Member Posts: 79  
posted: 1/19/2012 9:53:44 PM(UTC)
Odd...
Code:
at \\%1 %sdtime% shutdown -r -t 00 -f


works fine for me, and does it on the right machine (CHQAUDT078 in this example)

Code:
What time? 14:00

Time entered: 14:00
Added a new job with job ID = 3

Current box
Status ID Day Time Command Line
-------------------------------------------------------------------------------
1 Each M 3:00 AM "D:\Update Dell\UpdateDellWarrantyInfo.exe"

CHQAUDT078
Status ID Day Time Command Line
-------------------------------------------------------------------------------
3 Tomorrow 2:00 PM shutdown -r -t 00 -f
Press any key to close this window...
dteague
#11dteague Member Posts: 79  
posted: 1/19/2012 9:59:25 PM(UTC)
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
#12Jono Member Original PosterPosts: 111  
posted: 1/19/2012 11:34:56 PM(UTC)
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
danielm
#13danielm Member Posts: 165  
posted: 2/10/2012 6:16:54 PM(UTC)
I've just expanded this Idea to have it
show current time and schedule on remote pc
ask to DELETE schedule
ask to delete again :)
and then ask to add a time for it to reboot. allowing for ENTER to skip.

I went the way of AT \\pcname instead of psexec.

ok..a bit messy but here's the idea...

**just added CHKDSK scheduling and removal :)

Code:
{actionpath}SchedReboot.bat {computer}





Code:


@echo off
if %1.==. GOTO END


:CHKDSK1
ECHO.
set /p chkdsk1=Schedule C Chkdsk? [1= /F 2= /R 3=StopCheck enter=skip]
if {%chkdsk1%}=={1} psexec -d \\%1 -s cmd /c "echo y|chkdsk c: /f"
if {%chkdsk1%}=={2} psexec -d \\%1 -s cmd /c "echo y|chkdsk c: /f /r"
if {%chkdsk1%}=={3} psexec -d \\%1 -s chkntfs c: /x

:STARTOFDELETE
ECHO.
NET TIME \\%1
ECHO Current AT Schedule is
at \\%1
REM Clearing variables
set chkdsk1=
set delsched=
set idnum=
set delagain=
set sdtime=
ECHO.
set /p delsched=Do you wish to delete a schedule (n/y) [enter=skip]?
if {%delsched%}=={y} goto yesdel
if {%delsched%}=={n} goto nodel
if %delsched%.==. goto nodel
goto nodel
:yesdel
set /p idnum=Enter number only of ID to delete [# or SPACE for All]?
at \\%1 %idnum% /delete

set /p delagain=Do you wish to delete another (n/y) [enter=skip]?
if {%delagain%}=={y} goto STARTOFDELETE
if {%delagain%}=={n} goto noagaindel
:noagaindel

:nodel

ECHO.
set /p sdtime=Time on Target Computers Local Time (2:00am , 02:00) [enter=skip]?
if %sdtime%.==. GOTO BLANK

ECHO.

ECHO Time entered: %sdtime%
at \\%1 %sdtime% shutdown -r -t 60 -f
Echo Reboot setup at time select with 60 second delay.
ECHO.
ECHO Press any key to close this window...
pause>nul

GOTO END

:BLANK
:END

Jono
#14Jono Member Original PosterPosts: 111  
posted: 2/21/2012 11:42:54 PM(UTC)
Thanks danielm, I love it! You have several commands in there that I'm not familiar with regarding syntax, etc. so I'm glad you put that together.

It makes sense that you may want to do a CHKDSK when rebooting.

I edited it slightly just for readability. I also saved it again as SchedShutdown.bat for shutdown. For that one I removed the CHKDSK section and edited the shutdown command, of course.

Thanks again!

Jono
danielm
#15danielm Member Posts: 165  
posted: 3/2/2012 12:18:19 AM(UTC)
Glad it can help someone.
I kept it all in one batch file to have one simple all inclusive click command:)
sullivane
#16sullivane Member Posts: 190  
posted: 2/16/2015 11:36:39 PM(UTC)
I know I am replying to an old thread but I am hoping someone is still subscribed to it.

How do you add something so that it's scheduled? Add a custom action that runs on a schedule?
Bert.D
#17Bert.D Member Lansweeper Developer Administration Posts: 103  
posted: 2/17/2015 2:55:44 PM(UTC)
It's not an action, but you could use the deployment feature to get what you want.
Ex. Deploy a script that creates a schedule, deploy a command,...
sullivane
#18sullivane Member Posts: 190  
posted: 2/17/2015 3:00:10 PM(UTC)
Awesome, thanks!
IFIT
#19IFIT Member Posts: 23  
posted: 3/3/2015 6:18:47 PM(UTC)
This works wonderfully!!! Thanks!
spatchE
#20spatchE Member Posts: 1  
posted: 5/21/2019 5:35:46 PM(UTC)
How do I get this to work as a new lansweeper customer? I do not understand what you guys mean by AT.

Active Discussions

Action Powershell script for WOL on VLAN
by  psmail   Go to last post Go to first unread
Last post: 5/30/2019 12:00:43 AM(UTC)
Lansweeper Fonts
by  TKinnie  
Go to last post Go to first unread
Last post: 5/23/2019 4:00:40 PM(UTC)
Action Schedule Reboot using AT and psshutdown with time input
by  spatchE   Go to last post Go to first unread
Last post: 5/21/2019 5:35:46 PM(UTC)
Action Open users local Temp directory
by  studerje  
Go to last post Go to first unread
Last post: 5/14/2019 7:24:24 PM(UTC)
Lansweeper CMD- CFI MS Update remover 2
by  Rodney Stowell  
Go to last post Go to first unread
Last post: 4/18/2019 6:55:01 PM(UTC)
Action Skype User
by  cctech   Go to last post Go to first unread
Last post: 4/18/2019 4:14:54 PM(UTC)
Action Email user
by  cctech  
Go to last post Go to first unread
Last post: 4/18/2019 3:48:50 PM(UTC)