Batch Script at Startup not Completing - windows

I have a batch script to pull down the latest revision files from an SVN that runs at Windows startup (configured with local group policy editor).
Here is the code for the script:
#echo off
if "%1"=="" (
set LIBPATH=C:\ALTIUM_WORK\00001_MCHP-CDB\parts\Library
) else (
set LIBPATH=%1
)
svn cleanup %LIBPATH%
set DATETIME=%DATE:~4,2%/%DATE:~7,2%/%DATE:~10,4% %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2%
echo %DATETIME%>mcl_update.log
svn up %LIBPATH%>>mcl_update.log
if ERRORLEVEL 1 goto ERRHANDLER
Exit
:ERRHANDLER
<Insert error message here>
When I run this script by double-clicking the .bat, I get the following output in mcl_update.log:
02/14/2017 16:13:50
Updating 'C:\ALTIUM_WORK\00001_MCHP-CDB\parts\Library':
At revision 5800.
This is what I expect, but when the script runs at startup, the last line is left out. It populates mcl_update.log with this:
02/14/2017 16:16:07
Updating 'C:\ALTIUM_WORK\00001_MCHP-CDB\parts\Library':
The second line is part of the output from svn, so it seems like the command starts, but just never finishes. I'm at a loss for why this is happening. Does anyone have any ideas?
Thanks!
-Sean
A newly-discovered bit of info: After startup, if I try to delete the log file that is generated, Windows throws an error stating that "The action can't be completed because the file is open in cmd.exe".
Is it possible that this could be a domain issue? The connection to my company's network isn't up yet, so the svn command just hangs?

I suspect that the path is not what you are expecting during start-up. Perhaps you should explicitly specify the path for svn because the only report you are apparently logging is a plain echo, not any reponse from svn.

So after following #Magoo's suggestion of piping stderr out to the file, the issue became clear. It turns out it has to do with my server's user authentication. Since the script was running at startup (i.e. before I logged in), the svn command wouldn't work, as user authentication was impossible.
I changed the group policy to start the script at logon, rather than startup, and everything works now.

Related

Group Policy Logon Bat Script

I have a simple .bat script triggered on user login to create a uniform work environment (load items to public desktop) as well as a few other small tasks - all are successful.
At the end of this script, I would like to call an additional .bat script and also open a system root folder if criteria is met. This however never occurs. The script I am calling begins with user prompt, and I notice scripts running as group policy do not always open a cmd window etc.
REM --------------------------------------------------
REM -----Update Newest Box & Scales / Uber Script-----
REM --------------------------------------------------
:BOXSCALE
if exist C:\scalescripts\Scale_Box_v3_Script.bat goto UBER
echo -
echo -
echo Scale_Box script is not up to date, please follow directions
call \\ant\fc\Dept\Photo\SDF8\SDF8_JW\scripts\Scale_Box_Uploader_v3\Scale_Box_v3_Uploader_Installer.bat
:UBER
if exist D:\Uber_Share_v2\Uber_Share_v2.bat goto END
echo -
echo -
echo Uber Share script is not up to date, please run installer as ADMIN
%SystemRoot%\explorer.exe "\\ant\fc\Dept\Photo\SDF8\Studio\Tech\scripts\Uber_Share_v2"
Pause
:END
Exit
The first bit (:BOXSCALE) is intended to launch a secondary script that contains mostly robocopy commands. It does require user interaction at the first bit. The second simply opens a server path in windows explorer for user. I am afraid that the user interaction is the problem as the start up script isn't visible to user when launched via GP Logon.
If I run this script manually, I receive the prompt from the first script and the system root opens as intended, but not if it is run via group policy login. I have also tried inputting the last two commands into a separate script and calling that, which also fails. Any ideas to get these last few items to run?
I found the solution to the problem. As suggested, it was the fact that the .bat script I was calling contained a user prompt. As the GP Logon script runs in the back ground, the user is unable to acknowledge prompt leaving the script hanging.

How to execute batch file as Tortoise SVN hook

I wish to run a batch file either in START commit or PRE commit via TortoiseSVN hook scripts. No tests I have done has worked.
I have created a batch file (svnadd.bat) that just writes a message to a text file for now, so I know it fired. However, the batch file does not appear to run as the message does not get written.
echo YES>C:\Temp\commit.txt
Here is my hook setup.
My process. Right click on a folder which is under svn version control and select SVN Commit. The commit dialog shows, however, the batch file does not execute.
All svn software, repositories and folder/file structure under svn control reside on the same computer/drive.
As per the screen shot, I also tried adding cmd.exe to the front of the command line as
C:\windows\system32\cmd.exe /c C:\Tools\SVN\svnadd.bat
I config it like this. It is successful.
post_commit_hook.bat:
echo Hello World >file.txt
After commit, file.txt will be save to
E:\SVN\XXX\branches\autoCommit
#lazybadger's comment provides the answer in that the "path" needs to be at the highest working copy path. For me, this is C:\Projects.
Once I set C:\Projects as the path, the script hook ran.
You can try and use team city, if you want certain scripts to be executed on SVN events (like SVN Commit). Though TeamCity is mainly used as a build server, I think it can do what you desire.

SVN update using windows task scheduler not working

I want to setup a windows cron job to update svn. I created a batch file with this step:
START TortoiseProc.exe /command:update /path:"C:\svn" /closeonend:0
and setup the task scheduler to run this daily. This svn requires a password which I want to enter each time rather than cache it. The batch file works as expected without any issues.
The task scheduler shows that the job was successfully executed. However, I don't get the GUI to enter the password, neither does the directory get updated. Also, when I tried to manually update the svn directory thereafter, it says that svn is locked.
Why is task scheduler reporting successful?
Why is svn getting locked?
Task scheduler reports success because START seems to return exit code 0. START only starts an application and exits. It doesn't wait until the started application has exited. The task scheduler never sees the exit code of TortoiseProc this way.
You can do this with START WAIT. Enter START /? in a CMD for more information.
You can also do this with CMD /K itself. Enter CMD /? in a CMD for more information.
But I don't think you need START or CMD at all. You can either run TortoiseProc directly or call it via a batch script. In the batch script you can add more debugging like echos and redirected output in files to see what happens.
Do not use TortoiseProc.exe for this task! Use Subversion command-line client (svn.exe). Read the docs:
Remember that TortoiseSVN is a GUI client, and this automation guide
shows you how to make the TortoiseSVN dialogs appear to collect user
input. If you want to write a script which requires no input, you
should use the official Subversion command line client instead.

svn post-commit hook on windows server

i'm trying to set up a svn post-commit hook on a windows server, so that every time a commit is made, it is connected to an issue of an existing project on my bug tracking website.
since there is no pre made post-commit hook for windows (or at least i haven't find one that would fit my needs), i tried to write the batch file for myself.
SET REPOS=%1
SET REV=%2
SET SVNLOOK="C:\Program Files (x86)\VisualSVN Server\bin\svnlook.exe"
SET PROJECT=3
%SVNLOOK% log -r %REV% "%REPOS%" > COMMIT_MSG
SET /p COMMIT_MSG= < COMMIT_MSG
echo %COMMIT_MSG%
C:\curl\bin\curl "http://www.mybugtrackingsite.de/vcs_integration/report/%PROJECT%/?passkey=KEY" --data-urlencode "msg=%COMMIT_MSG%"
when i'm setting REPOS and REV by myself and run the script from the command line it works, but when i make a commit it doesn't work and my COMMIT_MSG only contains "echo is on" instead of the actual message.
i've read, that the svn repository executes hook programs with an empty environment, means that no environment variables are set at all and that could be why my script runs fine by hand and not when run by svn.
but what variables do i have to set and how? my paths are already absolute, so that shouldn't be the problem. i'm not a windows guy and am not really into batch - so any help or ideas how i get this thing to work would be appreciated!
When you redirect the commit message to the file you use a relative path 'COMMIT_MESSAGE'.
%SVNLOOK% log -r %REV% "%REPOS%" > COMMIT_MSG
The working directory which is used by the svn hook may not be the same as yours and the svn process has not the rights to write at this location. You may use an absolute path.
You can also try to redirect STDERR to see if you get an error from svnlook.
Also delete the file at the beginning of the hook script to ensure that you don't use a file from a previous run.
Your are setting both REPOS and REV to %1. One of them should be %2
You should also place #ECHO OFF at the top of the file to avoid unnecessary output on screen

How do I automatically update a Subversion working copy?

Does anybody know how I can automatically run svn update? If anybody has a script or something like that, could you show me an example?
I'm using TortoiseSVN. On the production server I have a scheduled task that runs the following batch file.
CD C:\Program Files\TortoiseSVN\bin\
START TortoiseProc.exe /command:update /path:"C:\www\MyRepo\" /closeonend:0
Hopefully this saves someone else some time!
I use SVN Notifier which sits in the system tray and notifies me every time the repository changes. And I can highly recommend it. It means you only update when there's something to update!
Alternatively you can set up a scheduled task/cron job to run svn update in the appropriate directory every hour/day/whatever.
EDIT: OK, take a look at this Microsoft article on setting up a scheduled task.
You want a batch file called svnUpdate.bat or something which looks like this:
cd C:/path/to/your/working/copy
svn update
Get the scheduled task to run this as often as you like (once an hour seems sensible)
Make sure you have the command line version of svn installed (I use SlikSvn) and available on your PATH (in a command window type svn and ensure it says 'Type svn help...' or similar.
#echo off
cls
echo == Initiating system instance variables...
echo. -- Setting the variables...
:: Here you need to make some changes to suit your system.
set SOURCE=C:\sauce\CURRENT
set SVN=C:\Program Files\TortoiseSVN\bin
:: Unless you want to modify the script, this is enough.
echo. %SOURCE%
echo. %SVN%
echo. ++ Done setting variables.
echo.
echo == Updating source from SVN
echo. -- Running update...
"%SVN%\TortoiseProc.exe" /command:update /path:"%SOURCE%" /closeonend:2
echo. ++ Done.
echo. -- Cleaning up...
set SOURCE=
set SVN=
echo. ++ Done.
If you are using TortoiseSVN then the above batch script will suit fine. Otherwise you can just modify it to use whatever SVN client you are currently using. Just pop this in a .bat file and run it on demand.
You can also download and use Commit-Monitor from http://code.google.com/p/commitmonitor/. It monitors SVN repositories for commits and notifies the user when it happens. It is in GNU GPL, ver 2.
Note: Once I know your operating system, I will be able to give you a more detailed answer.
General Instructions
Never change anything in the local repository.
Read this link on how to use AT to schedule from the command line in windows.
Use the AT command to schedule the following command (assuming you have the command-line version of svn installed):
svn update reporsitory_directory
Profit!

Resources