Cant run automation code from bat file but can from com line
Hi,
I'm taking a crack at some automation using winscp.exe. I'm running Windows XP on a Mac with parallels 8. If I run the folowing from the command line, my code works but if I run it as a bat file (see below --- line) all I see is a blinking terminal window and nothing uploads. We have tried to get some out put to a log file, but that only works when I run the code from the terminal directly. I've had another developer run it from a pure XP machine and it works. Go figure. Any help / advice would be greatly appreciated.
"C:\winscp.exe" /console /log=winscp-log.log /script=script.txt /parameter upload-10-23-58.zip 184.106.113.73 testuser testuser /home/testuser/autoscript /home/testuser/autoscript/SVNTEST /home/testuser/autoscript/SVNTEST/dev-stuff/database-backup-test.sql testdbuser testdbuser testdb
------------------------------------------------------------------------
rem repository settings
set LOCAL_COPY=C:\SVN\LOCO
set DB_DUMP_FILE=%LOCAL_COPY%\dev-stuff\database-backup-test.sql
set DB_HOST=localhost
set DB_NAME=testdb
set DB_USER=testdbuser
set DB_PASS=testdbuser
rem executable settings
set SVN="C:\Program Files\TortoiseSVN\bin\svn.exe"
set ZIP="C:\Program Files\7-Zip\7z.exe"
set WINSCP="C:\winscp.exe"
set DUMP="C:\xampp\mysql\bin\mysqldump.exe"
set DUMP_OPTIONS=--add-drop-table --routines
rem SSH login
set SSH_HOST=184.106.113.73
set SSH_USER=testuser
set SSH_PWD=testuser
rem upload ZIP to the folder
set SSH_FOLDER=/home/testuser/autoscript
set UNZIP_FOLDER=%SSH_FOLDER%/SVNTEST
rem the database dump path on the server
set SERVER_DB_DUMP_FILE=%UNZIP_FOLDER%/dev-stuff/database-backup-test.sql
rem database user login
set SERVER_DB_USER=testdbuser
set SERVER_DB_PASS=testdbuser
set SERVER_DB_NAME=testdb
rem comment for SVN commit
set COMMIT_COMMENT=Test Comment
rem generate unique ZIP filename based on timestamp
set DATETIME=%time:~0,2%-%time:~3,2%-%time:~6,2%
set ZIP_FILE=upload-%DATETIME%.zip
set SUCCESS=0
echo .
rem 1. prepare dump
%DUMP% -h %DB_HOST% -u %DB_USER% -p"%DB_PASS%" %DUMP_OPTIONS% %DB_NAME% >%DB_DUMP_FILE%
if NOT %ERRORLEVEL% == %SUCCESS% (
rem on failure restore original dump and exit
echo "***" Error doing DB backup
echo Restoring original dump file...
%SVN% revert %DB_DUMP_FILE%
echo done.
echo backing up \"%DB_NAME%\" database using login/passwd [%DB_USER%/********] failed.
echo After issue resolved please rerun this script. Original DB dump was restored.
echo Commiting changes was not done.
echo bye!
exit
echo failure
)
echo DB dump successfully created.
rem 2. do commit
echo Enter submission comment (just FYI, most SVN servers do not allow empty/stupid comments)
cd %LOCAL_COPY%
echo cd %LOCAL_COPY%
rem start commit
%SVN% commit . --message "%COMMIT_COMMENT%"
cd ..
echo create ZIP package to upload
%ZIP% a -r %ZIP_FILE% %LOCAL_COPY%
echo upload and unzip the ZIP package in server, and import database from %SERVER_DB_DUMP_FILE%
%WINSCP% /console /log=winscp-log.log /script=script.txt /parameter %ZIP_FILE% %SSH_HOST% %SSH_USER% %SSH_PWD% %SSH_FOLDER% %UNZIP_FOLDER% %SERVER_DB_DUMP_FILE% %SERVER_DB_USER% %SERVER_DB_PASS% %SERVER_DB_NAME%
echo remove the created ZIP package from local
echo done!
I'm taking a crack at some automation using winscp.exe. I'm running Windows XP on a Mac with parallels 8. If I run the folowing from the command line, my code works but if I run it as a bat file (see below --- line) all I see is a blinking terminal window and nothing uploads. We have tried to get some out put to a log file, but that only works when I run the code from the terminal directly. I've had another developer run it from a pure XP machine and it works. Go figure. Any help / advice would be greatly appreciated.
"C:\winscp.exe" /console /log=winscp-log.log /script=script.txt /parameter upload-10-23-58.zip 184.106.113.73 testuser testuser /home/testuser/autoscript /home/testuser/autoscript/SVNTEST /home/testuser/autoscript/SVNTEST/dev-stuff/database-backup-test.sql testdbuser testdbuser testdb
------------------------------------------------------------------------
rem repository settings
set LOCAL_COPY=C:\SVN\LOCO
set DB_DUMP_FILE=%LOCAL_COPY%\dev-stuff\database-backup-test.sql
set DB_HOST=localhost
set DB_NAME=testdb
set DB_USER=testdbuser
set DB_PASS=testdbuser
rem executable settings
set SVN="C:\Program Files\TortoiseSVN\bin\svn.exe"
set ZIP="C:\Program Files\7-Zip\7z.exe"
set WINSCP="C:\winscp.exe"
set DUMP="C:\xampp\mysql\bin\mysqldump.exe"
set DUMP_OPTIONS=--add-drop-table --routines
rem SSH login
set SSH_HOST=184.106.113.73
set SSH_USER=testuser
set SSH_PWD=testuser
rem upload ZIP to the folder
set SSH_FOLDER=/home/testuser/autoscript
set UNZIP_FOLDER=%SSH_FOLDER%/SVNTEST
rem the database dump path on the server
set SERVER_DB_DUMP_FILE=%UNZIP_FOLDER%/dev-stuff/database-backup-test.sql
rem database user login
set SERVER_DB_USER=testdbuser
set SERVER_DB_PASS=testdbuser
set SERVER_DB_NAME=testdb
rem comment for SVN commit
set COMMIT_COMMENT=Test Comment
rem generate unique ZIP filename based on timestamp
set DATETIME=%time:~0,2%-%time:~3,2%-%time:~6,2%
set ZIP_FILE=upload-%DATETIME%.zip
set SUCCESS=0
echo .
rem 1. prepare dump
%DUMP% -h %DB_HOST% -u %DB_USER% -p"%DB_PASS%" %DUMP_OPTIONS% %DB_NAME% >%DB_DUMP_FILE%
if NOT %ERRORLEVEL% == %SUCCESS% (
rem on failure restore original dump and exit
echo "***" Error doing DB backup
echo Restoring original dump file...
%SVN% revert %DB_DUMP_FILE%
echo done.
echo backing up \"%DB_NAME%\" database using login/passwd [%DB_USER%/********] failed.
echo After issue resolved please rerun this script. Original DB dump was restored.
echo Commiting changes was not done.
echo bye!
exit
echo failure
)
echo DB dump successfully created.
rem 2. do commit
echo Enter submission comment (just FYI, most SVN servers do not allow empty/stupid comments)
cd %LOCAL_COPY%
echo cd %LOCAL_COPY%
rem start commit
%SVN% commit . --message "%COMMIT_COMMENT%"
cd ..
echo create ZIP package to upload
%ZIP% a -r %ZIP_FILE% %LOCAL_COPY%
echo upload and unzip the ZIP package in server, and import database from %SERVER_DB_DUMP_FILE%
%WINSCP% /console /log=winscp-log.log /script=script.txt /parameter %ZIP_FILE% %SSH_HOST% %SSH_USER% %SSH_PWD% %SSH_FOLDER% %UNZIP_FOLDER% %SERVER_DB_DUMP_FILE% %SERVER_DB_USER% %SERVER_DB_PASS% %SERVER_DB_NAME%
echo remove the created ZIP package from local
echo done!