Cant run automation code from bat file but can from com line

Advertisement

danielc
Joined:
Posts:
3

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!

Reply with quote

Advertisement

danielc
Joined:
Posts:
3

Hi thanks for the reply. I tried using winscp.com vs. winscp.exe but I'm getting the same results, no second terminal like if I run the code directly through the command line. I've attached the script file we are using. Thanks so much for taking a look at this. Very grateful for the debugging help.


-----------------------------------
open sftp://%3%:%4%@%2%
cd %5%

option transfer binary
put %1%

call rm -r %6%

call unzip %5%/%1%



call mysql -u %8% -p"%9%" %10% < %7%

close
exit

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

danielc wrote:

but I'm getting the same results, no second terminal like if I run the code directly through the command line.
I'm getting lost. That was a purpose of replacing the .com with .exe. To get the output into your primary terminal, not into the secondary terminal that is disappearing. So what do you see in your primary terminal now, after the .bat finishes?

Reply with quote

danielc
Joined:
Posts:
3

Hi Thanks - So now its working - i think there might have been a directory path error. If you don't mind, I'd like to keep the post open since we are now into the hook part.

C:\SVN\LOCO>set ZIP="C:\Program Files\7-Zip\7z.exe"

C:\SVN\LOCO>set WINSCP="C:\winscp513-2\winSCP.com"

C:\SVN\LOCO>set DUMP="C:\xampp\mysql\bin\mysqldump.exe"

C:\SVN\LOCO>set DUMP_OPTIONS=--add-drop-table --routines

C:\SVN\LOCO>rem SSH login

C:\SVN\LOCO>set SSH_HOST=184.106.113.73

C:\SVN\LOCO>set SSH_USER=testuser

C:\SVN\LOCO>set SSH_PWD=testuser

C:\SVN\LOCO>rem upload ZIP to the folder

C:\SVN\LOCO>set SSH_FOLDER=/home/testuser/autoscript

C:\SVN\LOCO>set UNZIP_FOLDER=/home/testuser/autoscript/SVNTEST

C:\SVN\LOCO>rem the database dump path on the server

C:\SVN\LOCO>set SERVER_DB_DUMP_FILE=/home/testuser/autoscript/SVNTEST/dev-stuff/
database-backup-test.sql

C:\SVN\LOCO>rem database user login

C:\SVN\LOCO>set SERVER_DB_USER=testdbuser

C:\SVN\LOCO>set SERVER_DB_PASS=testdbuser

C:\SVN\LOCO>set SERVER_DB_NAME=testdb

C:\SVN\LOCO>rem comment for SVN commit

C:\SVN\LOCO>set COMMIT_COMMENT=Test Comment

C:\SVN\LOCO>rem generate unique ZIP filename based on timestamp

C:\SVN\LOCO>set DATETIME=16-17-28

C:\SVN\LOCO>set ZIP_FILE=upload-16-17-28.zip

C:\SVN\LOCO>set SUCCESS=0

C:\SVN\LOCO>echo .
.

C:\SVN\LOCO>rem 1. prepare dump

C:\SVN\LOCO>"C:\xampp\mysql\bin\mysqldump.exe" -h localhost -u testdbuser -p"tes
tdbuser" --add-drop-table --routines testdb 1>C:\SVN\LOCO\dev-stuff\database-ba
ckup-test.sql

C:\SVN\LOCO>if NOT 0 == 0 (
rem on failure restore original dump and exit
echo "***" Error doing DB backup
echo Restoring original dump file...
"C:\Program Files\TortoiseSVN\bin\svn.exe" revert C:\SVN\LOCO\dev-stuff\databas
e-backup-test.sql
echo done.
echo backing up \"testdb\" database using login/passwd [testdbuser/********] fa
iled.
echo After issue resolved please rerun this script. Original DB dump was restor
ed.
echo Commiting changes was not done.
echo bye!
exit
echo failure
)

C:\SVN\LOCO>echo DB dump successfully created.
DB dump successfully created.

C:\SVN\LOCO>rem 2. do commit


C:\SVN\LOCO>echo Enter submission comment (just FYI, most SVN servers do not all
ow empty/stupid comments)
Enter submission comment (just FYI, most SVN servers do not allow empty/stupid c
omments)

C:\SVN\LOCO>cd C:\SVN\LOCO

C:\SVN\LOCO>echo cd C:\SVN\LOCO
cd C:\SVN\LOCO

C:\SVN\LOCO>rem start commit

C:\SVN\LOCO>"C:\Program Files\TortoiseSVN\bin\svn.exe" commit . --message "Test
Comment"
Sending dev-stuff\database-backup-test.sql
Transmitting file data .
Committed revision 1327.

C:\SVN\LOCO>cd ..

C:\SVN>echo create ZIP package to upload
create ZIP package to upload

C:\SVN>"C:\Program Files\7-Zip\7z.exe" a -r upload-16-17-28.zip C:\SVN\LOCO

7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Scanning

Creating archive upload-16-17-28.zip

Compressing LOCO\.svn\entries
Compressing LOCO\.svn\format
Compressing LOCO\.svn\pristine\00\007e7c102c33c4146f9ad7b3762a91dae98de112.svn-
base
Compressing LOCO\.svn\pristine\02\0221cec0cbeebfd427e8dc47439d0873e75f373f.svn-
base
Compressing LOCO\.svn\pristine\02\02f61bfcdfbad0775162de2a215216ff11674000.svn-
base
Compressing LOCO\.svn\pristine\0a\0a3e3b5f6cfa5c16f06c2ca8735a23a6e2a79873.svn-
base
Compressing LOCO\.svn\pristine\0f\0f4b641f92a877b300c33d0c424ba3bd2e4c0a76.svn-
base
Compressing LOCO\.svn\pristine\18\18535bd09be9056418dbbbffaf73c25035a01136.svn-
base
Compressing LOCO\.svn\pristine\18\188da43e2cba863ccd5e96102775a4319d62ed6e.svn-
base
Compressing LOCO\.svn\pristine\1b\1b51943dfa4625a99e8a33e945ecb9e6f4fa34d9.svn-
base
Compressing LOCO\.svn\pristine\22\2286e2c636abef65f009f903b2e4436e55f9eed1.svn-
base
Compressing LOCO\.svn\pristine\26\26e0dae729e936c504ea2c4b4e7c62b65aed469b.svn-
base
Compressing LOCO\.svn\pristine\27\2715bd8dd0c04961a1d1615dbb11be149030bc43.svn-
base
Compressing LOCO\.svn\pristine\28\2822389132cdcc3c11d4fbcdd00ed76f55e54e8c.svn-
base
Compressing LOCO\.svn\pristine\28\2847e7c2a9cdb98c0cc28d20c3cd90af8db83d7f.svn-
base
Compressing LOCO\.svn\pristine\29\29c91fb5b22ce267751c38b08cde72cc431fdf00.svn-
base
Compressing LOCO\.svn\pristine\2b\2b58b6c609d8f582585b22004b5488d3c3490bbd.svn-
base
Compressing LOCO\.svn\pristine\30\30c90437bfe7b788745a6f6b6e78d6901fe272ec.svn-
base
Compressing LOCO\.svn\pristine\3a\3a237ce98ab4da3c7f5179fe702908049e3222f0.svn-
base
Compressing LOCO\.svn\pristine\3b\3b9f333a6632db32eadcb5d661033a6617a0bb16.svn-
base
Compressing LOCO\.svn\pristine\3d\3d9a26e08b81656a92db80a93ae51855d717d816.svn-
base
Compressing LOCO\.svn\pristine\3d\3ddd063a38030f15b073c82bf0d3ea38e1d57e91.svn-
base
Compressing LOCO\.svn\pristine\3f\3f10df12e0848c8b664315018918e9d37680982a.svn-
base
Compressing LOCO\.svn\pristine\3f\3f665f0e8aa8edcd4bb436a6595f535076238a67.svn-
base
Compressing LOCO\.svn\pristine\44\4490bd0a4ffa95868b984041fc71604a506b7ec8.svn-
base
Compressing LOCO\.svn\pristine\48\482a09300f9589dee6f4e8935b1c49bad659421f.svn-
base
Compressing LOCO\.svn\pristine\4f\4f6cfa4cf5b21b89e355d0389192de7e69466249.svn-
base
Compressing LOCO\.svn\pristine\51\516a0d1b9a8a734820f0c4d3820cadd277a9d1ff.svn-
base
Compressing LOCO\.svn\pristine\54\54dbcf82eba94221f6a16c16c619fbad11eecc7d.svn-
base
Compressing LOCO\.svn\pristine\56\56e1b51fc1df1b45091937713496a615e05ae444.svn-
base
Compressing LOCO\.svn\pristine\59\594a2d86ca31e3dccd547d18441b8ea5a3401014.svn-
base
Compressing LOCO\.svn\pristine\5d\5d3e42fafc0d78b987705a6b60a805b855964cde.svn-
base
Compressing LOCO\.svn\pristine\5d\5df6928824ec86e074bdfedeb110c17c5368d94b.svn-
base
Compressing LOCO\.svn\pristine\6a\6a20a2d3c028cf7b5052d09e91be2d8bc2a6375d.svn-
base
Compressing LOCO\.svn\pristine\6a\6a5dc467a7ea57794a5efe8f82318beec22f533a.svn-
base
Compressing LOCO\.svn\pristine\6c\6cd235245578817c34ad6a26ebe41be5daa7615d.svn-
base
Compressing LOCO\.svn\pristine\75\758841d9cbed8e4c42261d3b2ad0f82b4fdcaf56.svn-
base
Compressing LOCO\.svn\pristine\79\79c78ec905b04548e55eda592c6a2d90821b1291.svn-
base
Compressing LOCO\.svn\pristine\7d\7d2cefd04b9c80b6df619067d60b332caab02fa2.svn-
base
Compressing LOCO\.svn\pristine\89\89ed9b9cedbfc36d938ca90e6e47cadc1df7e801.svn-
base
Compressing LOCO\.svn\pristine\8a\8a7762ac73647116228ae5f8c8820da8b9338508.svn-
base
Compressing LOCO\.svn\pristine\8b\8bf52f66b4755dc30c31f39783448232de57407c.svn-
base
Compressing LOCO\.svn\pristine\98\983772307243559fd7adea6b676caedf1f951430.svn-
base
Compressing LOCO\.svn\pristine\9b\9bc3f99bea3e85fabf178fe80d6179ecf9d65a3a.svn-
base
Compressing LOCO\.svn\pristine\a3\a32a872d44d2c55edb672cae40e45180fdf98519.svn-
base
Compressing LOCO\.svn\pristine\a4\a4897c1d05226b2e7244432f26ebdda56e16e3fa.svn-
base
Compressing LOCO\.svn\pristine\af\af4703a58df210c5e192be67a271ee66c27af0ea.svn-
base
Compressing LOCO\.svn\pristine\b7\b7b836ac5a327b38044bb829934fe8ff74d32927.svn-
base
Compressing LOCO\.svn\pristine\b8\b85155f3a2374be48467d3a070b8fef44fb73abb.svn-
base
Compressing LOCO\.svn\pristine\c3\c323e6a427fa2740958721e613932d16f9810ea5.svn-
base
Compressing LOCO\.svn\pristine\ce\ce2c2ac03f813965b4c0f32b88830ba821ea0572.svn-
base
Compressing LOCO\.svn\pristine\d1\d12e2d03be521783267f7acb5dac1caa30c42e05.svn-
base
Compressing LOCO\.svn\pristine\d4\d4992ef9c7dc2536bfe78db3e38e722e6be129a2.svn-
base
Compressing LOCO\.svn\pristine\db\db28ab0c52aa23d5f6b7889ed101fd744aafb6e7.svn-
base
Compressing LOCO\.svn\pristine\df\dfbe6e1412af8c7fc0d1ce2bcd6b73f2acf32361.svn-
base
Compressing LOCO\.svn\pristine\e2\e2a0544a20ab5493f382408dc2a6ead5d8fe12bb.svn-
base
Compressing LOCO\.svn\pristine\e4\e419dfa911167cc3786bae27159e347468bcc955.svn-
base
Compressing LOCO\.svn\pristine\ea\ea6b2c108906c707b42b7f306b8937ef8b6e8218.svn-
base
Compressing LOCO\.svn\pristine\eb\eb7b5e6d680b9bdc9dd44331275c37c2848993cf.svn-
base
Compressing LOCO\.svn\pristine\ec\ecfe0b04400844ac4835c30bdc4d8a85a0fed010.svn-
base
Compressing LOCO\.svn\pristine\f0\f0b1d4d3691ebd8a739aa90ef9cca5e9ae370b29.svn-
base
Compressing LOCO\.svn\pristine\f2\f2908f369f896ad2e000f44b8e01103da7ac933a.svn-
base
Compressing LOCO\.svn\wc.db
Compressing LOCO\dev-stuff\.htaccess
Compressing LOCO\dev-stuff\.properties
Compressing LOCO\dev-stuff\database-backup-test.sql
Compressing LOCO\output.txt
Compressing LOCO\script.txt
Compressing LOCO\svn-commit.cmd
Compressing LOCO\temp.txt
Compressing LOCO\test.bat
Compressing LOCO\winscp.exe

Everything is Ok

C:\SVN>echo upload and unzip the ZIP package in server, and import database from
/home/testuser/autoscript/SVNTEST/dev-stuff/database-backup-test.sql
upload and unzip the ZIP package in server, and import database from /home/testu
ser/autoscript/SVNTEST/dev-stuff/database-backup-test.sql

C:\SVN>"C:\winscp513-2\winSCP.com" /console /log=winscp-log.log /script=script.t
xt /parameter upload-16-17-28.zip 184.106.113.73 testuser testuser /home/testuse
r/autoscript /home/testuser/autoscript/SVNTEST /home/testuser/autoscript/SVNTEST
/dev-stuff/database-backup-test.sql testdbuser testdbuser testdb
Searching for host...
Connecting to host...
Authenticating...
Using username "testuser".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] testuser@184.106.113.73
/home/testuser/autoscript
transfer binary
upload-16-17-28.zip | 3269 KiB | 452.4 KiB/s | binary | 100%
Searching for host...
Connecting to host...
Authenticating...
Using username "testuser".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
rm: cannot remove `/home/testuser/autoscript/SVNTEST': No such file or directory

Command 'rm -r /home/testuser/autoscript/SVNTEST'
failed with return code 1 and error message
rm: cannot remove `/home/testuser/autoscript/SVNTEST': No such file or directory
.
Archive: /home/testuser/autoscript/upload-16-17-28.zip
Host is not communicating for more than 15 seconds. Still waiting...
Note: If the problem repeats, try turning off 'Optimize connection buffer size'.

Warning: Aborting this operation will close connection!
(A)bort (43 s): Abort
Terminated by user.
Session 'testuser@184.106.113.73' closed.
No session.
No session.
No session.

C:\SVN>echo remove the created ZIP package from local
remove the created ZIP package from local

C:\SVN>echo done!
done!

C:\SVN>

Reply with quote

Advertisement

You can post new topics in this forum