Updating SVN remotely via batch file - batch-file

I tried searching relevant threads, it didn't worked. So here are the detailed question / situation, where I am looking for help.
I have 30 client nodes where I have setup SVN and checked out two folders (which needs to be updated) exactly when I want (forcefully).. e.g : "d:\gbv\textures" and "d:\gbv\characters"
then I put svnUpdate.bat file in main d: drive with relevant command e.g: "svn update blabla"
if I run this bat file by double clicking, it works fine ( it updates )
now I thought, I should create a batch file, where I type all 30 nodes IP, and set of commands, to run that batch file from local d: and it should work.
PROBLEM: I am unable to do this.
because I am unable to do this, from my cmd panel.
because I am not sure, how I can access network pc and tell it to run "d:\svnUpdate.bat" from its drive from dos prompt. ( obviously, I can do this via win explorer visually ).
Hopefully the question will make sense.

You can execute files on remote machines in a network using PsExec. I use it to execute batch files and pass parameters to them.
You'll probably need the -w option to set the working directory.
Of course this is a lot easier with powershell remoting, but since you already set it up with batch, PsExec works fine.

Related

Delete file from C:\Windows folder

I'm working with an application that was poorly designed. When installed, it creates a .INI file (remember those?) in the C:\Windows folder. In order to get things working correctly in our environment, I don't use that .INI file. Instead, I have separate .INI files in a different location where I can properly management them within the framework of the application. The problem I'm running in to is users not running the application correctly so it picks up this default .INI file that doesn't work in our environment (remember I said the application is poorly designed).
To make sure that my users are running the correct configuration, I need to delete this pesky .INI from the C:\Windows folder. I have .BAT files that manage application launch and updates so I tried to just issue a delete in the .BAT file but it isn't working. When I try to run just the delete command in a command window, I get "Access Denied". I can't rename it or move it either. I would just go touch each computer but don't have the time to get to them all.
I have just spent the last two hours googling to find a solution and the only solutions are to use Windows Explorer which isn't an option. I know it has to be something simple that I haven't been able to find. Ideas?
for /f "usebackq delims=" %A in ("%userprofile%\Desktop\ComputerName.txt") do echo Del \\%A\C$\Windows\file.ini
Computername.txt is one computer per line, names or addresses.
127.0.0.1

Start batch after restart

I'm trying to make a batch start after a restart. Will this work?
This doupdate.bat is stored at a USB drive and is going to be used in many computers.
REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /V 1 /D "%~d0\cmd\DoUpdate.bat
So you want it start on startup? Since you cant use Autorun.inf since that needs to be manually clicked to start it up and ever since Win7 it doesnt allow you to change what file it opens on USB, it sounds like your only option is the startup folder. You could write a second batch script to copy the file into the computers startup folder. Here is the code to copy the file into the startup folder as a bat:
C:
copy doupdate.bat "C:\Users\%USERNMAE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\doupdate.bat"
(Note: Thats assuming the bat to move the file is on the USB, and also replace the 'C:' in the code with whatever drive it will be moving to, you cant simply have it move directly to the C drive or CD to it, you have the enter the name since interacting between different drives on batch it tricky, so you have to cd to them a special way first)
But that would only have the file auto-open on restart only on the user that you were currently using when you ran the file.
Also that method requires you to have the file installed to the users computer.
And if you dont want the file to stay on the users computer after its already done its job, simply add this code at the end of "doupdate.bat" for it to delete itself:
del "C:\Users\%USERNMAE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\doupdate.bat"
its as simple as that, that way when it gets run from the Startup folder, as soon as its done with all of its purpose, it will remove itself, and then to re-add it, simply re-run the bat to move the file.
I hope my info helped, and if any of the methods here wont work for your specific bat file just tell me and ill try to find a different method to do it and will edit this post to include that method.
This should work:
copy "doupdate.bat" "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"
Note: Make sure to use this in Windows 10. I am not sure if this will work in Windows 8, 7 but it should also work

scheduled batch file fail moving file to google drive

i'm trying to move file from 1 server to an other with schedule batch file, for that i use google drive as a third part where i store my files. i have made some script
#echo "executed %date:~-10,2%%date:~-7,2%%date:~-4,4%" >> Logs.txt
copy /y "C:\backup\Portal2%date:~-10,2%%date:~-7,2%%date:~-4,4%.bak" "c:\users\administrator\google drive\"
this script move a file from a directory to an other, it works fine if i click it,but if i try to schedule it doesn't work.
I tried to change path to a random path in my computer and scheduled it, it worked perfectly.
its like my computer doesn't recognize google drive at all.
When copying over a network you need to use credentials in the scheduled task that have access to the network resource.
This is probably a bit late for you but might be helpful to others who follow in your footsteps. I had this problem and it came down to security. When you run something in batch it doesn't have the correct permissions. I can't remember the exact solution but you need to set the batch task to run with your username.

Batch file not working when running in the background - issue with substituted drive

I'll try to keep this short, without all the details of this batch file procedure.
OS: Windows XP
Action: Scheduled Task (background, I can't find a way to run it in the foreground)
Problem: files not created on mapped drive. When the batch file is ran directly, it works.
It does the following (or at least tries to):
clean a directory: works
create executables based on a substituted location
We use the following to map a local folder to the K: drive:
subst K: /D
subst K: D:\Development\SVN
The executables are built from source code that is located on (for example) K:\Sources to K:\Executables.
This fails, for a reason I did not yet discover. As mentioned above, if the batch file is ran directly it doesn't fail. If I substitute K:\ by C:\Development\SVN the issues seem to be resolved but still, this doesn't solve the fact that I can't run it when using K:.
I hope anyone here has an idea, I tried Googling for a long time + scanning SO but to no avail.
Thanks in advance!
substed drives are local to session, and your scheduled task is run in another session then your login session.
It seems to be possible to schedule task for user login session with schtasks.exe command line, but then the task runs only if the user is logged in. It might not be what you want, so using a full non-substed path might be the best solution after all.

Automate cygwin via batch file

Long story short... we have multiple servers which we run perflog monitoring on every night. My job is to convert these logs to .csv format and send them to my e-mail.
This bit it already automated via a .sh script an ex-employee wrote.
What I want automated is to run a batch job after the perfmon logging to look at a specific folder and find the latest .blg file and run the sh script on it (the script is called upload) so that I don't have to log in to each server and do it manually.
e.g.
upload myInitials cd /cygdrive/someLocation/logs/$latestFile$.blg
myInitials and the location can be hard-coded... I just wouldn't know how to find the latest file in the folder and automate it all via a batch file.
Any pointers would be very helpful!
# Jeremy:
Sorry, I probably should have mentioned in my question that the servers are running 2003 and 2008.
I don't think it would be absolutely necessary to register a change notification on the folder - If the log runs from noon till 7 in the morning, the script will run immediately after (you can set a script to run after a perfmon log has finished in log properties) so the log will almost definitely be the latest file in the folder anyway.
Like I said, I already have a .sh file in place to convert to csv and send to my e-mail, I just need to incorporate it into a batch file so that instead of me going to each of the servers and opening up cygwin and typing upload xx /cygdrive/location/logs/xyz.blg, I can have it automated to run straight after the log has finished without me having to RDC into it.
Thanks for the input!
If you have a Shell script and you job is to call the shell script from a windows batch file then this will work.This assumes the cygwin is installed in C:
Contents of start_cyg.bat
#echo off
set PATH=%PATH%:"C:\Cygwin\bin"
rem bash --login -i
bash "/cygdrive/d/cyg.sh"
Contents of cyg.sh
#!/bin/bash
TAIL=`ls -lrt | tail -1`
echo "TAIL:$TAIL"
If you call start_cyg.bat from windows command prompt you can get the output of the cyg.sh in the console
for getting newest file in a directory, ls -1tr | tail -1 should work.
First, I don't know if it would meet your requirements, but the Windows Task Scheduler 2 in Vista+ is very robust and can trigger an event even based on log entries. However, extraction and parsing of that log entry may require some scripting, and might have concurrency issues, even if that log entry did indicate the last used process. Chances are none of this is helpful, but just throwing it out there.
Programatically, it would be simple as you can register a change notification on a folder. When a change occurs, you go find the latest file. Then launch the batch file to launch your shell script, or whatever your desired sequence may be.
I think cygwin may even support change notification events via scripting, though I'm unsure. I believe there are linux extensions for this, but I may be wrong.
If it were me, I'd just write a little C++ app to do whatever I wanted.. but for you maybe any (or more likely none) of the above helps ;o.

Resources