Script file to shut down server at a certain time
-
Gidday - I may be a bit rusty on the fine points, and there are always a number of ways to skin the cat, but here's what I would do .. 1) set up the scheduler - Im going to assume you dont have the newer version, and use the AT command, its a bit basic, but hey, learn how to walk before you can run :-) a) get a dos prompt b) type AT c) if you get the response like 'Schedule service not started', type NET START SCHEDULE 2) a forced shutdown of the system will (should) stop all services, so you dont really have to do this manually for each service. I would use 'shutdown' from the NT Resource Kit, if you dont have the NT Resource Kit, you can probably find a copy of shutdown somewhere, and other companies like Novell have their own version sitting around .. 3) assume you wanted to shutdown the machine every Monday to Friday at 19:00 .. You can use the AT scheduler to do it The hardest thing is you cant assume from an AT event what the environement - eg path etc is, so I find the safest way is to either put the shutdown command in a script, and/or implicitly specify its path .. So assuming Shutdown is in C:\NTReskit, AT 7:00p /Every:Mo,Tu,We,Th,Fr CMD /C "START /DC:\NTReskit Shutdown.exe /L/Y/C" Will run the command shutdown, from C:\NTResKit, with the given parameters.. It is important that for whatever version of shutdown you use, you know what the consequences and parameters are.. In the case I've shown, /L = Local, /C = Force Close, /Y = answer Y to all questions - if you had a program that should save its data, this wouldnt be too bright !!! so do a 'shutdown /?' before you really start something in production, to see what paras are what .... similarly, 'AT /?' shows the options (if not a bit terse) 4) ok, so we can expand on the above .. lets say you create a directory called c:\scripts, and in that, a script called 'shutdown.cmd' in that script, if you had services called business1, business2, and you wanted to stop them first, you could do something like .. (note, 'sleep' also comes from the NT resource kit, and is handy for waiting for events .. you could use /T:60 in the shutdown command to get the same effect ) @echo off rem rem This script created (date & time) by (who) rem rem 1st stop the business1 service net stop business1 rem 2nd stop the business2 service net stop business2 rem wait 60 seconds fo
hi, that was a very good explanation u have given me and i'm very much impressed by it. OK coming to the point when I tried the simple at command with the options it did not work but the job id is assigned 1. I'll write the at job I tried, its similar to the one u wrote to me but mine doesn't seem to be working. At 21:00 /every:M,T,W,T,F,S CMD /C "Start /D C:\Program Files\rksupport shutdown.exe /L /Y /C" The at command was given a job id of 1. I waited until that time but it didn't fire and the job was not showing any error status. When I checked in the Scheduled Tasks. It didnt show any errors either. But the creator is shown as "System" when it should have been "Administrator". What is the probs? and how to resolve this? ANything wrong with the at command? I sincerely appreciate ur valued help. Thanx once again. :) SAI
-
hi, that was a very good explanation u have given me and i'm very much impressed by it. OK coming to the point when I tried the simple at command with the options it did not work but the job id is assigned 1. I'll write the at job I tried, its similar to the one u wrote to me but mine doesn't seem to be working. At 21:00 /every:M,T,W,T,F,S CMD /C "Start /D C:\Program Files\rksupport shutdown.exe /L /Y /C" The at command was given a job id of 1. I waited until that time but it didn't fire and the job was not showing any error status. When I checked in the Scheduled Tasks. It didnt show any errors either. But the creator is shown as "System" when it should have been "Administrator". What is the probs? and how to resolve this? ANything wrong with the at command? I sincerely appreciate ur valued help. Thanx once again. :) SAI
:-( ok, learn to start with smaller pieces of the problem, or break it up into single steps .. take :- Start /D C:\Program Files\rksupport shutdown.exe /L /Y /C First of all, I dont think there should be a space between the '/D' of the Start command, and the Directory (C:\Program Files...), so it should be :- Start /DC:\Program Files\rksupport shutdown.exe /L /Y /C Anyway, try just that bit from the command line, till it works ... Ive just tried the start command on a simple .cmd file and I KNOW the space is wrong) Also sometimes with directories with spaces in them, its easier to 'scrunch the spaces' by going, for example c:\progra~1\rksupport, like its a dos 8.3 file-system - both are understood ... The AT command looks ok - leastwise if AT didnt swear at you or give you an error when you entered it, it didnt find anything wrong with it :-) so when you have the start command working, move up a notch and try the start command AND the AT command together... Second (and last before I take off home for dinner) If you want the Schedule service to run as Administrator, you have to get it to start as Administrator .. Start -> Settings -> Control Panel -> Services -> Schedule Select 'Log On As' and enter the details of an Administrator account, or equivalent (stop and re-start the service, either from the Services Applet, or the command line - NET STOP SCHEDULE NET START SCHEDULE) thus endeth another lesson
-
:-( ok, learn to start with smaller pieces of the problem, or break it up into single steps .. take :- Start /D C:\Program Files\rksupport shutdown.exe /L /Y /C First of all, I dont think there should be a space between the '/D' of the Start command, and the Directory (C:\Program Files...), so it should be :- Start /DC:\Program Files\rksupport shutdown.exe /L /Y /C Anyway, try just that bit from the command line, till it works ... Ive just tried the start command on a simple .cmd file and I KNOW the space is wrong) Also sometimes with directories with spaces in them, its easier to 'scrunch the spaces' by going, for example c:\progra~1\rksupport, like its a dos 8.3 file-system - both are understood ... The AT command looks ok - leastwise if AT didnt swear at you or give you an error when you entered it, it didnt find anything wrong with it :-) so when you have the start command working, move up a notch and try the start command AND the AT command together... Second (and last before I take off home for dinner) If you want the Schedule service to run as Administrator, you have to get it to start as Administrator .. Start -> Settings -> Control Panel -> Services -> Schedule Select 'Log On As' and enter the details of an Administrator account, or equivalent (stop and re-start the service, either from the Services Applet, or the command line - NET STOP SCHEDULE NET START SCHEDULE) thus endeth another lesson
hi, Thanx for replying. I'm trying what u corrected and will let u know the result. In the meantime I wanted to tell u when I goto Start\ControlPanel\Services\TaskScheduler Applet & when I goto startup properties of TaskScheduler then I can see it is set up as automatic and the "Logon As" has 2 options under it: 1. System Account Which is selected and has another checkbox whcih is "Allow Services to interact with desktop" checked. The system account has been selected as default & disabled and doesnt allow me to change to anyother login. 2. "This account" is disabled. Infact when I try to change the login, i'm unable to do so as the system a/c is taken as default and is disabled. So i'm unable to add administrator a/c. The other problem is when I go to "My Computer" and open the "Scheduled Tasks". I try to add a schedule from there with administrator login. Infact I tried the shutdown command at 8pm, but it didnt work there either. When I see the creator for the scheduled task it is showing administrator. But the most unfortunate thing is, it doesnt trigger off at the scheduled time nor anyother time. Other schedules which I tried out like atomic clock are working but not the shutdown.exe. I'm using BackOffice 4.5 server, 1GB RAM, Intel L440GX Server Board, Intel PIII-700, SP4. :) SAI
-
hi, Thanx for replying. I'm trying what u corrected and will let u know the result. In the meantime I wanted to tell u when I goto Start\ControlPanel\Services\TaskScheduler Applet & when I goto startup properties of TaskScheduler then I can see it is set up as automatic and the "Logon As" has 2 options under it: 1. System Account Which is selected and has another checkbox whcih is "Allow Services to interact with desktop" checked. The system account has been selected as default & disabled and doesnt allow me to change to anyother login. 2. "This account" is disabled. Infact when I try to change the login, i'm unable to do so as the system a/c is taken as default and is disabled. So i'm unable to add administrator a/c. The other problem is when I go to "My Computer" and open the "Scheduled Tasks". I try to add a schedule from there with administrator login. Infact I tried the shutdown command at 8pm, but it didnt work there either. When I see the creator for the scheduled task it is showing administrator. But the most unfortunate thing is, it doesnt trigger off at the scheduled time nor anyother time. Other schedules which I tried out like atomic clock are working but not the shutdown.exe. I'm using BackOffice 4.5 server, 1GB RAM, Intel L440GX Server Board, Intel PIII-700, SP4. :) SAI
yeah, well, you didnt correct one of my first assumptions about you using the 'AT' scheduler, did you ?? In fact, you're not really using it, you're using the upgraded version due to the backoffice/IE upgrade - in which case, you could be better off scheduling entries by clicking on 'My Computer' and selecting 'Scheduled Tasks' Under the Advanced options under this newer scheduler, you can then set which account to use for the AT command (which may be why its not running things for you now) ... and this task scheduler service does appear as 'Task Scheduler' in the Services applet, rather than the older 'Schedule' play around with this, I forget the specifics of using it - Microsoft has an article somewhere on their site on using it as opposed to the AT command iteslf..
-
yeah, well, you didnt correct one of my first assumptions about you using the 'AT' scheduler, did you ?? In fact, you're not really using it, you're using the upgraded version due to the backoffice/IE upgrade - in which case, you could be better off scheduling entries by clicking on 'My Computer' and selecting 'Scheduled Tasks' Under the Advanced options under this newer scheduler, you can then set which account to use for the AT command (which may be why its not running things for you now) ... and this task scheduler service does appear as 'Task Scheduler' in the Services applet, rather than the older 'Schedule' play around with this, I forget the specifics of using it - Microsoft has an article somewhere on their site on using it as opposed to the AT command iteslf..
now when I tried the same 'at' command in the command prompt it gave me a jpb id. Believe me it didnt work, ie., it did not shutdown the server. Similarly I tried executing an 'at' job by giving a net send message and it did work. Now I really dont understand why it is not executing when I have given it correctly. I'll write u the same at command which worked and the one which did not work. This one worked: C:\>at xx:xxpm cmd /c "net send server TEST" This didnt work: C:\>at xx:xxpm /every:th cmd /c "Start /dC;\Progr~1\rksupport Shutdown.exe /L /Y /C" When I give the at command then i get a job id but the most unfortunate thing is I cant get it working. I'm losing hope of ever writing scripts. The simple one does not seem to work. As for the Task Scheduler, in the advanced tab I give the administrator u/n and passwd. There also I tried scheduling the shutdown but it does not work either. This new task i've given with administrator a/c only. Infact all the while i'm talking as administrator login only. Whenever I restart the system then I get a msg saying that the system missed a scheduled command, as if its executing when left on. :(( SAI
-
now when I tried the same 'at' command in the command prompt it gave me a jpb id. Believe me it didnt work, ie., it did not shutdown the server. Similarly I tried executing an 'at' job by giving a net send message and it did work. Now I really dont understand why it is not executing when I have given it correctly. I'll write u the same at command which worked and the one which did not work. This one worked: C:\>at xx:xxpm cmd /c "net send server TEST" This didnt work: C:\>at xx:xxpm /every:th cmd /c "Start /dC;\Progr~1\rksupport Shutdown.exe /L /Y /C" When I give the at command then i get a job id but the most unfortunate thing is I cant get it working. I'm losing hope of ever writing scripts. The simple one does not seem to work. As for the Task Scheduler, in the advanced tab I give the administrator u/n and passwd. There also I tried scheduling the shutdown but it does not work either. This new task i've given with administrator a/c only. Infact all the while i'm talking as administrator login only. Whenever I restart the system then I get a msg saying that the system missed a scheduled command, as if its executing when left on. :(( SAI
C:\>at xx:xxpm /every:th cmd /c "Start /dC;\Progr~1\rksupport Shutdown.exe /L /Y /C" ********** are you sure ??? is this bad typing on your or my part - isnt it supposed to be ... C:\Progra~1 ie ';' -> ':', 'Progr~1' -> 'Progra~1' "Start /dC:\Progra~1\rksupport Shutdown.exe /L /Y /C" the event logs should also give an indication of why something like an event hasnt worked ... you didnt reply as to wether the "Start /DC:\Progra~1\rksupport shutdown.exe /L /Y /C" worked on its own either, without using the scheduler, so why not just get that bit working - your machine might not like shutdown.exe for some reason, in which case there are also others, as Uwe suggested on the second posting of your original question... and this is about all the help I can give you if it still doesnt want to go, sorry...
-
C:\>at xx:xxpm /every:th cmd /c "Start /dC;\Progr~1\rksupport Shutdown.exe /L /Y /C" ********** are you sure ??? is this bad typing on your or my part - isnt it supposed to be ... C:\Progra~1 ie ';' -> ':', 'Progr~1' -> 'Progra~1' "Start /dC:\Progra~1\rksupport Shutdown.exe /L /Y /C" the event logs should also give an indication of why something like an event hasnt worked ... you didnt reply as to wether the "Start /DC:\Progra~1\rksupport shutdown.exe /L /Y /C" worked on its own either, without using the scheduler, so why not just get that bit working - your machine might not like shutdown.exe for some reason, in which case there are also others, as Uwe suggested on the second posting of your original question... and this is about all the help I can give you if it still doesnt want to go, sorry...
hi, It was typographical errors on my part. As for the "Start/DC:\Program Files\rksupport Shutdown.exe /L /Y /C". I did not understand ur doubt. U want me try the shutdown.exe command? Infact I alreadt tried using the shutdown command directly at command prompt and it did work. Its not executing/triggering when using within 'at' job schedules. As for the eventvwr, i'll check it out & let u know. I want to try to store the output of the at job schedule. How should I try to capture the output to a file whether its working or not? Even when I tried to schedule the shutdown.exe from My Computer/Scheduled Tasks, it did not work & infact I ensured that administrator login is running the job. After scheduleing the job I see the job in the Scheduler window. But I really dont see it shutting down the server at the prescribed time. I really dont know whether its working or not. In the schedule window its showing without any errors. :(( sai
-
hi, It was typographical errors on my part. As for the "Start/DC:\Program Files\rksupport Shutdown.exe /L /Y /C". I did not understand ur doubt. U want me try the shutdown.exe command? Infact I alreadt tried using the shutdown command directly at command prompt and it did work. Its not executing/triggering when using within 'at' job schedules. As for the eventvwr, i'll check it out & let u know. I want to try to store the output of the at job schedule. How should I try to capture the output to a file whether its working or not? Even when I tried to schedule the shutdown.exe from My Computer/Scheduled Tasks, it did not work & infact I ensured that administrator login is running the job. After scheduleing the job I see the job in the Scheduler window. But I really dont see it shutting down the server at the prescribed time. I really dont know whether its working or not. In the schedule window its showing without any errors. :(( sai
Hmm .. it doesnt seem to be finding the shutdown command .... This is my absolute last try at this ! Set up the at command as :- at xx:xx C:\Progra~1\rksupport\Shutdown.exe /L /Y /C /T:0 /R good luck
-
Hmm .. it doesnt seem to be finding the shutdown command .... This is my absolute last try at this ! Set up the at command as :- at xx:xx C:\Progra~1\rksupport\Shutdown.exe /L /Y /C /T:0 /R good luck
hi, Let me apologise for the delayed response. I tried the last resort what u gave but in vain. Nevertheless I found out one thing, I really dont know whether its going to help me or us in anyway. WHat I noticed is when I gave the at command without any options then it worked. But when I tried to give options then it is not working. Firstly the command what I gave which worked is "At 7:00pm CMD /C "Shutdown.exe /L /Y /C /R"". Secondly when I tried to add options such as "/every:we" then I cant get it work. So this is the present scenario at my end. Anything missing from my end? Any new suggestions?:) I dont know if the above information is anyway useful to u or not?:confused: Just wanted to share my thoughts with u. Cos u have been sincerely trying to help me out.:-D SAI
-
hi, Let me apologise for the delayed response. I tried the last resort what u gave but in vain. Nevertheless I found out one thing, I really dont know whether its going to help me or us in anyway. WHat I noticed is when I gave the at command without any options then it worked. But when I tried to give options then it is not working. Firstly the command what I gave which worked is "At 7:00pm CMD /C "Shutdown.exe /L /Y /C /R"". Secondly when I tried to add options such as "/every:we" then I cant get it work. So this is the present scenario at my end. Anything missing from my end? Any new suggestions?:) I dont know if the above information is anyway useful to u or not?:confused: Just wanted to share my thoughts with u. Cos u have been sincerely trying to help me out.:-D SAI
hi there again,:) I got it worked. I just was lazy to check whether it worked with "/Every:M,T,W,T,F,S". Now it is working fine with the given options. Earlier I gave the "/Every:Mo,Tu,We.." So it didnt work. But whats surprising is that why it doesnt workout with "Start /DC:\Program Files\rksupport\Shutdown.exe /L /Y /C".:confused: Now can u help me how to write a script and execute it? I want to send all the users connected a message 10 minutes and 5 min before shutting down the server. SAI