I am new to .bat files but have been working on a process for two days. It is very simple and works fine on my desktop (thanks for a code snippet found on the internet), but when I try to run it through a shared drive on our file server, the processing does not occur.
#echo off
REM Batch file to process daily flat file and replace " with empty space for upload into Access/SQL Server
ren C:\Users\Desktop\filejuly17.txt filequotes.txt
for /f "tokens=* delims= " %%a in (C:\Users\Desktop\filequotes.txt) do (
set S=%%a
set S=!S:"=!
>> C:\Users\Desktop\finalfile.txt echo.!S!
)
I have had to switch the ren to a copy on the file server, but have verified that I can copy the one file to another using that process. So am assured that I have the path correctly. However, no matter which options I have tried, I am unable to have this batch file strip out the double quotes that are randomly in the file from user entry. We need to strip these out and replace them with empty spaces in order to have a data migration process then load this flat file into our database.
Thank you for any guidance.
If it helps, my laptop is running on Windows 7, the server I remote connect is running on Windows Server 2008.
Related
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.
I am trying to execute a batch file from SQL Server Agent (as it needs to be done before some SSIS-packages are run).
When I execute the job it fails in a few seconds saying "Access denied".
The account under which SQL Server Agent runs has full control on the folder that contains the batch file. The result of the batch would be deleting some files in a folder, calling a webservice and get those same files back from the webservice.
I can run the batch file when I start it with my own (admin) account.
I googled and found several other questions and answers but none of those were covering my problem. I hope you can point to other options.
Thanks for your help.
Johan
Batch file contents:
echo Removing txt files of last run
del Employees.txt
del HrDepFun.txt
del HrEmpActual.txt
echo Files removed
echo Starting getconnectors
{Call Webservice} -> cannot disclose this on stackoverflow
echo Getconnectors done
Batch file execution statement from SQL Server Agent job (type Operating System (CmdExec)):
cmd.exe /c "c:\Program Files (x86)\AFAS\AFASRemote_Call_GetConnectors.bat" > connectorlog.txt 2> connectorerrorlog.txt
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 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 need to check a file status (existing? or last modified date) on multiple remote Windows servers (in LAN). The files are accessible via UNC path. The remote PCs need a user name and password. It's best to be some sort of script.
I am not system admin, but asked to do this by my boss because each of these PCs are host of SQL Server and the file is a backup of database. I am a SQL Server database developer. I was trying to do it using T-SQL, but just found it not geared to do this (although maybe doable).
Create a batch file like (say check.bat):
#echo off
set list=server1 server2 server3 server4 serverN
for %%s in (%list%) do (
echo Logging in to %%s
net use \\%%s\shared /user:mydomain\myuser password
echo Checking file existence on %%s
if exist \\%%s\shared\file.txt (
echo File exist on %%s
) else (
echo File does NOT exist on %%s
)
echo Logging out
net use \\%%s\shared /delete
)
For details on the net use commands, see the accepted answer for question Mapping a network drive without hardcoding a drive letter in a batch file.