batch file help

SephStormSephStorm Member Posts: 1,731 ■■■■■■■□□□
I have a batch file that is supposed to shut down a remote server. The command is shutdown /s /f /t 0 /m \\SERVERNAME

Now if I post this in a cmd window it functions properly, but I cant get the batch file containing only this string to execute by clicking on it. It repeats on the screen and never shuts off the server. Any idea how to get this to work properly? I'm thinking I need to have some sort of stop command to end the script without running again, but i'm not sure.

Comments

  • techfiendtechfiend Member Posts: 1,481 ■■■■□□□□□□
    @echo off
    shutdown /s /f /t 0 /m \\SERVERNAME
    exit

    Works fine here, does it work there? @echo off shouldn't be needed in this case but it's pretty much the header of all batch scripts, to quiet it down a bit. Exit should automatically be invoked at EOF, it also shouldn't be needed.
    2018 AWS Solutions Architect - Associate (Apr) 2017 VCAP6-DCV Deploy (Oct) 2016 Storage+ (Jan)
    2015 Start WGU (Feb) Net+ (Feb) Sec+ (Mar) Project+ (Apr) Other WGU (Jun) CCENT (Jul) CCNA (Aug) CCNA Security (Aug) MCP 2012 (Sep) MCSA 2012 (Oct) Linux+ (Nov) Capstone/BS (Nov) VCP6-DCV (Dec) ITILF (Dec)
  • SephStormSephStorm Member Posts: 1,731 ■■■■■■■□□□
  • tecketecke Member Posts: 52 ■■□□□□□□□□
    What did you name the bat file?
  • Adam BAdam B Member Posts: 108 ■■□□□□□□□□
    The file is probably not executable. I'm guessing it's maybe a .txt? Change the file type to .bat.
    2015 Goals: CCNP SWITCH [] SEC+ [ ] CCNP ROUTE [ ] CCNP TSHOOT [ ]

  • tecketecke Member Posts: 52 ■■□□□□□□□□
    I believe that this^ is your problem. Shutdown.bat is calling itself over and over again and not calling the expected shutdown command... Try renaming the bat file.
  • SephStormSephStorm Member Posts: 1,731 ■■■■■■■□□□
    Strangely enough that works, however now it causes what I can only assume is an unexpected shutdown. The PC reboots when it shutsdown. Thoughts?
  • PJ_SneakersPJ_Sneakers Member Posts: 884 ■■■■■■□□□□
    The batch file was calling itself. You weren't specifying shutdown.EXE (or a path to the executable), so shutdown.bat was launching itself over and over again. When you call a command it will look first in the current folder and execute what's there before it looks for it in the PATH variable.

    Are you saying that the PC you're running the BAT on is rebooting? Or the server?
  • PJ_SneakersPJ_Sneakers Member Posts: 884 ■■■■■■□□□□
    That's weird. Double check to make sure there's not a /R in the batch file. Check the server's BIOS settings and see if it has a section related to power loss (like power on, stay powered off). Sounds like a weird hardware/BIOS thing. Check for an updated BIOS that possibly fixes power issues maybe?
  • olaHaloolaHalo Member Posts: 748 ■■■■□□□□□□
    I remember having this same issue lol.
    Really frustrating
    You cant name the bat the same name as a command.
  • SephStormSephStorm Member Posts: 1,731 ■■■■■■■□□□
    FYI, the reboot must have been a random event, it does shutdown properly since then.
Sign In or Register to comment.