I made several bat files using task scheduler(custom) and I need to apply these to all of my 70 server computers. Obviously I don't want to repeat the same procedure at every server.
Can I simply copy and paste my bat files to different computers and expect same result?
If so, where are my bat files and where should I paste them?
Simply copy your batch files to different servers.
This post here shows location of task scheduler.
Folder location:
%systemroot%\System32\Tasks
Registry:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\Taskcache\Tasks
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\Taskcache\Tree
You may want to try the xcopy and for command to send your batch file to all servers.
Command syntax:
FOR command can loop through your server names, and XCOPY copys the batch script to the other servers.
for %%G in (serverA
serverB
serverC
...
serverZ) do xcopy [source] [destination] [options]
Note that asterisks does not work as intended, since it works as a wildcard.
Related
On my Windows Server 2008 R2 machine, a batch file is scheduled to run using Task Scheduler. For some reason, only a portion of the commands in the batch file are executed; Some commands are ignored.
Batch file looks like this:
cd s:
cd "S:\Reports\"
sqlcmd -S ipAddress -U login -P password -d dbname -i "S:\query.sql" -o "S:\Folder\Report.txt"
copy /A /Y "S:\Folder\Report.txt" Y:\
When I run the batch file by double-clicking on it, everything runs as intended; But when it is executed from task scheduler, only the sqlcmd portion runs correctly. The copy command does not seem to run. Even when I replace copy command with xcopy or mkdir or any other command, it does not run.
Even if I change the order of commands in the batch file, the commands do not run. But when the batch file is executed by double-clicking, everything runs perfectly.
The Y:\ is a mapped drive under the same login. After typing my question this far, I went back and ran one more test. Interestingly, if I replace mapped drive with local drive, everything seems to be working okay. So, at this point it looks like mapped drive is the problem. Any ideas on resolving this?
Essentially, how to copy or move files to a mapped drive (different machine) using batch file executed from Task Scheduler?
S: and Y: are probably mapped network drives, but those are mapped in the context of a user session. The scheduled task will be run in its own session and won't have those drives mapped.
You should use the UNC path of the share instead (\\server\share) as that should work in either context (as long as the share is accessible to the user the scheduled task is running as).
I appreciate your time so I won't take much of it. Here's what I'm trying to do: I want to create a .bat file that, when executed, will open the Command Prompt program, change directory to a folder (located on the C:), then execute a line of code that will change the file permission status of all files in that folder to Everyone. I intend to create a Windows task that will run this .bat file everyday. I understand how to setup the Windows task, but I can't figure out exactly how the .bat file should be written. Can anyone help?
Here's what I've got so far:
ECHO OFF
[Tab]Start "" C:\Windows\system32\cmd.exe
ECHO OFF
[Tab]Prompt cd cd:\google drive
ECHO OFF
[Tab]Prompt cacls *.* /t /e /g everyone:f
If you're interested, here's why I'm trying to create this .bat file:
I use a single Google Drive account on two file server computers, one in each of two offices. Each office has this file server and about 10 client computers. The client computers access files on the shared Google Drive folder (located on the file server) and occasionally add/edit/delete files. Google Drive does a great job of keeping all files synced between the two offices, but one problem I have is that if office A adds a file, the only computer in office B that can see it is the file server. I have to change the file permission to "Everyone" using the file server in office B before any of the client computers in office B can see the file. Over time, it's become very annoying to manually change the file permission every day and I'm looking for a shortcut. Please let me know if you can think of a better one.
If you got the commands right then this is a batch script with them.
The && will run the following command only if the cd command was successful.
#echo off
cd /d "c:\google drive" && cacls *.* /t /e /g everyone:f
I have some files that are automatically generated by an external sources into a local machine each day.
I have batch script, which moves the data from that source folder into a destination folder.
So i would like to move the files using time and date. But the robocopy command only accepts date.
Please see the script below
robocopy \\IP\f$\EMAILMT\202 C:\IntellinxServices\Queues\SwiftGen\MT202 *.rje /MAXAGE:%NEWDATE%
I have been running a batch file to copy files from one location (my local machine) to multiple servers. Recently we moved into a server for processing files, now the problem is the same batch file is not working when I copy it from one server to another 2 or more servers....
Do I have to change any statements in the batch file pertaining to servers...?
Here is my batch file:
#echo off
echo copying files to multiple servers
copy *.eps* \\server1\adman\in\displ
copy *.eps* \\server2\BasketsIn\TheHindu\AdImport\Ads_SAP))
This will copy a static filemask of files from one server to two other servers.
You need read/write permissions over the lan.
#echo off
echo copying files to multiple servers
set "source_server=\\server0\c\share"
copy "%source_server%\*.eps*" "\\server1\adman\in\displ"
copy "%source_server%\*.eps*" "\\server2\BasketsIn\TheHindu\AdImport\Ads_SAP"
I don't generally write batches, but I currently have a batch that uses forfiles to copy my FLVs from one folder to another. When I run the batch manually it works every time, but from a scheduled task, it throws a (0x1) error.
forfiles -p "C:\Program Files\Adobe\Flash Media Server 4.5\applications\name\streams" -m *.flv -s -d -1 -c "cmd /c copy #file ^0x22C:\Program^ Files\Adobe\Flash^ Media^ Server^ 4.5\applications\name\output\"
Not sure what syntax the scheduled task doesn't like.
Update
Under my scheduled task, Actions I have the following:
Program/script: name.bat
Start in (optional): \\servername\file\to\batch
Hi might be this is helpful,
I also face the same issue.
Just set the startin path like:
Here start in path is the path of batch file:
like you have enter in program script:
"E:\program related files\demo.bat"
then in startin just pass:
E:\program related files & done!
When my Start in (optional): path was a UNC path, it wouldn't work. So I moved my batch on the server and everything worked correctly.
UNC in Windows Batch Files
forfiles with UNC path
On Server 2008 R2 when running the batch file under domain user credentials, with confirmed "log on as a batch job" security in the Local Security Policy>Local Settings>User Rights Assignment,
even then my batch (copying a log file to a network share) would not run as scheduled task, until I selected in tab General the option "Run with highest privileges" (default NOT checked!)
The option Run whether user is logged on or not was also selected, with radio-button, but I guess this is quite standard, when selecting to run the task using a domain user account.
For the tab Actions : specifying the entire batch file name including its path, directly in "Program/script:" works fine (with Server 2008 R2)
Using double quotes inside the batch file causes no problems.
See the screen shot bellow.
You need to change the user to system
Most common reason for such problems is permissions: scheduled tasks does NOT always run with your user credentials. If you want scheduled task to run as you you will have to set it up as you or alternative user.
Besides that I hope that your line of code is a content of your batch file, you are not trying to run this command directly. Or are you?
P.S. What are these ^0x22 and ^ doing in your code?
I know this is an old question, but just wanted to share some info.
The (0x01) error code can also refer to resources that are not found. Therefore:
all files/folders referd from within the batch file should be accessible to the user which account is being used to run that scheduled task;
pay attention when using network locations in combination with "Run whether user is logged on or not" option;
the above-mentioned option can be tricky to use because some resources may be available only after log on.
For .bat files to run inside your scheduled task, you need to specify your .bat file path inside the start option - despite the fact that your .bat file is at the same directory as your .exe. Also, I flagged it to run with highest privilege. After I have done those two things, the task suddenly takes off without any problem!