Lansweeper logo
Home Download Features Demo Buy now Help Support forum
 
    Most requested support articles:
  Lansweeper troubleshooting guide.
  The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
  WMI Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
  How to configure the windows firewall using group policies.
  Support:  
 support@lansweeper.com  
Skype: Lansweeper  
  Mo-Fri 9h-17h CET  
Welcome Guest Search | Active Topics | Log In | Register

2 Pages12>
Untag as favorite
Schedule Reboot using AT and psshutdown with time input
Jono
#1 Posted : Tuesday, January 03, 2012 10:40:33 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
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
#2 Posted : Wednesday, January 04, 2012 3:46:06 PM

Rank: Premium user

Groups: Premium Users, Member
Posts: 45
Location: Ohio, USA
nice contribution.
you could probably use a batch file with the "choice" command and have that feed a second batch file.
ejensen
#3 Posted : Wednesday, January 04, 2012 4:45:57 PM

Rank: Premium user

Groups: Premium Users, Member
Posts: 45
Location: Ohio, USA
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
#4 Posted : Wednesday, January 04, 2012 4:59:38 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
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
#5 Posted : Thursday, January 05, 2012 3:50:28 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
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
#6 Posted : Wednesday, January 11, 2012 5:10:33 PM

Rank: Premium user

Groups: Premium Users, Member
Posts: 45
Location: Ohio, USA
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
#7 Posted : Wednesday, January 11, 2012 6:50:11 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
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
#8 Posted : Thursday, January 12, 2012 3:57:21 PM

Rank: Premium user

Groups: Premium Users, Member
Posts: 45
Location: Ohio, USA
Nice work Jono! Thanks for contributing to the community too!
dteague
#9 Posted : Friday, January 13, 2012 7:12:18 PM

Rank: Premium user

Groups: Premium Users
Posts: 64
Location: Greensburg, IN
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
#10 Posted : Thursday, January 19, 2012 5:30:22 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
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
#11 Posted : Thursday, January 19, 2012 8:53:44 PM

Rank: Premium user

Groups: Premium Users
Posts: 64
Location: Greensburg, IN
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
#12 Posted : Thursday, January 19, 2012 8:59:25 PM

Rank: Premium user

Groups: Premium Users
Posts: 64
Location: Greensburg, IN
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
#13 Posted : Thursday, January 19, 2012 10:34:56 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
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
#14 Posted : Friday, February 10, 2012 5:16:54 PM

Rank: Premium user

Groups: Premium Users, Member
Posts: 32
Location: Montreal
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
#15 Posted : Tuesday, February 21, 2012 10:42:54 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
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
Users browsing this topic
Guest
2 Pages12>
Untag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Contact: E-mail Lansweeper - Skype : Lansweeper
Copyright 2004 - 2011 © Hemoco bvba