Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Batch file scripting

Posted on 2009-07-02
4
Medium Priority
?
498 Views
Last Modified: 2012-05-07
Hi experts,

I'm trying to write a batch file for sourcing sql files into mysql.
My problem is in the execution of the for loops, it seems to not like external variables set in the batch file.

Below is the exact code i'm using for my batches

The batch is executed from command line

install world characters realmd

upon execution, the first call source runs fine.

When getting to the 1st loop, it fails out
'dbsource_pathsql'

what am i missing?

Code For 'install.bat'
@echo off
cls
 
REM Command line parameters: %1 = world db name, %2 = characters db name , %3 = realmd db name
 
Echo Installing Character Database ...
set db=%2
set source_path=.\tc2\sql
call source %db% %source_path%\characters.sql
 
Echo Installing Character Updates...
set source_path=.\tc2\sql\updates
for %sql in (4105_8030_01_characters_character_spell.sql 4105_8030_02_characters_character_action.sql 4209_characters_TDB.sql 4292_8072_01_characters_characters.sql 4292_8072_02_characters_characters.sql 4346_8098_characters.sql 4351_8104_01_characters.sql) do call source %db% %source_path%\%sql
 
Echo Installing RealmD Database
set source_path=.\tc2\sql
set db=%3
call source %db% %source_path%\realmd.sql
 
rem Echo Installing RealmD Updates...
rem set source_path=.\tc2\sql\updates
rem for %sql in () do call source %db% %source_path%\%sql
 
Echo Installing World Database...
set source_path=.\UDB\trunk\full_db
set db=%1
call source %db% %source_path%\UDB_0.11.5_Core_7681_SD2_1012.sql
 
Echo Installing World Update Packs...
set source_path=.\UDB\trunk\Updates\0.11.5_additions
for %sql in (380_corepatch_mangos_7682_to_7894.sql 380_updatepack_mangos.sql 381_corepatch_mangos_7895_to_8029.sql 381_updatepack_mangos.sql) DO call source %db% %source_path%\%sql
 
Echo Installing World Converter...
set source_path=.\DB\trunk\udb_to_tdb_converter
call source %db% %source_path%\UDB_381_to_TDB_TC2_4067_Converter.sql
 
Echo Installing World Strings...
set source_path=.\tc2\sql\full\
for %sql in (trinityscript_script_texts.sql world_script_waypoints.sql world_scripts_full.sql world_spell_full.sql) DO call source %db% %source_path%\%sql
 
Echo Installing World Updates...
set source_path=.\tc2\sql\updates
for %sql in (4081_world.sql 4105_8030_03_mangos_npc_trainer.sql 4115_world_sd2.sql 4154_world_script.sql 4159_world.sql 4174_world_script.sql 4176_world.sql 4209_world_TDB.sql 4211_world.sql 4216_world.sql 4217_world_spell_proc_event.sql 4222_world.sql 4225_world.sql 4233_world_spell_proc_event.sql 4234_world_spell_bonus_data_TDB.sql 4246_world_script.sql 4258_world_TDB.sql 4276_world_TDB.sql 4283_world_TDB.sql 4307_world_TDB.sql 4308_world_TDB.sql 4320_world_.sql 4321_world.sql 4346_8098_world.sql 4352_spell_bonus_data_full.sql) DO call source %db% %source_path%\%sql
 
Echo Done sourcing!
Echo Showing Errors...
type error_log.txt
pause
 
Code for 'source.bat'
@echo off
echo Sourcing %2
mysql -u<mylogin> -p<mypassword> -h192.168.1.105 %1 < %2 >> error_log.txt 2>&1

Open in new window

0
Comment
Question by:sgaggerj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
sgaggerj earned 0 total points
ID: 24764503
I think i found the answer....
using %sql seemed to be the problem (even %%sql).
I changed it to %%g and it's working.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24764915
Yes it has to be one letter as you found... watch out as it is case sensitive too so %%a is diferent to %%b ... it might be neater to put the list of .sql files in a text file and read them with a for /f loop too as you could run into command line length issues with long lines too... ask if more info. needed .

Steve
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24764926
Yes, as a FOR variable you only can use a single letter, and upper/lower case is honoured. This is because of the special treatment FOR variables get. A normal environment variable can have longer name, and case is ignored.
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 24822880
@dragon-it

yea, I was thinking about moving them to a separate file, temporarily i pulled them all out of the command and used a set file_list= .... instead and then for %%g in (%file_list%).....
i might still do that

@both, thanks for the comments!
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question