Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a .BAT file with a robocopy line in it. The .BAT file resides on a network server directory. I use a client/monitor application on my workstation to send out a run command to several headless machines to tell them to each run the .BAT file.

The problem I've had is that a couple times when I've tried to copy and paste the command line to send to the remote machines, I inadvertently executed the command on my own workstation!

Is there some way that I could modify the .BAT file or do something elegant that would make it so the .BAT file couldn't accidentally operate on a workstation with a currently active logged in human or something to that effect? I just need to make it so I don't accidentally run the silly thing on my machine when I'm working with it.

share|improve this question
add comment

4 Answers

up vote 3 down vote accepted

Maybe just throw a short wait command at the beginning, say 10 seconds with a prompt that says "Waiting 10 seconds..."

That would give you enough time to cancel it on your workstation if you accidentally executed it on your own workstation.

Follow this guy's advice on how to create the "timer" if you'd like, or come up with your own parameters/script:

Better way to wait a few seconds in a bat file?

share|improve this answer
    
Good idea, but please be sure to sleep the right way ;) serverfault.com/questions/432322/how-to-sleep-in-a-batch-file –  Massimo Oct 23 '13 at 14:12
    
@Massimo - you realize that the link I provided had you and the same answer, right? ;) –  TheCleaner Oct 23 '13 at 14:23
add comment

Or (assuming it's only a limited pool of these machines that you'd ever want to run it on) get the batch file to check the name of the machine that it's running on, and compare it to a list of the right machines before doing the robocopy:

@echo off
FOR %%A IN (MACHINE1 MACHINE2 MACHINE3) DO IF %computername%==%%A goto :RUNTHEBATCHFILE

ECHO Not running on this PC
goto :THEEND

:RUNTHEBATCHFILE
REM Run something
ECHO Hello
goto THEEND

:THEEND
share|improve this answer
    
I was going to suggest this one. –  mfinni Oct 23 '13 at 18:32
add comment

Set the security permissions so your user account has read, but not read & execute permissions?

Or actively deny yourself "Read & Execute" permissions to it.

share|improve this answer
add comment

If you have a script on your computer, and you want it to run on another computer...

Use PSExec in another batch file, to copy the script to the desired computer and run it there?

RunOtherBat.bat:

@Echo Off

psexec \\SomeServer  -c test.bat
psexec \\SomeServer1 -c -u Domain\Admin -p SuperSecret!23$ test.bat
psexec \\SomeServer2 -c test.bat

OR

Create an Environment Variable (user or system), and check for that variable? If variable exists - don't run (or do run).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.