Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am totally new to scripting in linux...so i want to port some simple window bat files to ubuntu.

First file is easy

  setenv.bat
    set ANT_HOME=c:\ant\apache-ant-1.7.1
    set JAVA_HOME=c:\java

in linux i did this and it seems ok

  setenv.sh
      #!/bin/bash
    JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24/
    ANT_HOME=/usr/share/ant
    echo $JAVA_HOME
    echo $ANT_HOME

but now i want to port this bat file: startserver.bat

call ../config/setenv

call %ANT_HOME%/bin/ant -f ../config/common.xml start_db
call %ANT_HOME%/bin/ant -f ../config/common.xml start_server


pause

but i have no clue how can i do this in linux call ../config/setenv

thank you for any help , direction given.

share|improve this question
1  
    
ok thanks ...will start reading this docs. –  Cris Jun 24 '11 at 22:38

4 Answers 4

up vote 5 down vote accepted

It would be:

#!/bin/sh
source ../config/setenv.sh
${ANT_HOME}/bin/ant -f ../config/common.xml start_db
${ANT_HOME}/bin/ant -f ../config/common.xml start_server

source will make the variables which are set in setenv.sh available to your current script.
${ANT_HOME}/bin/ant will execute the ant binary.
The pause will just wait so that the cmd.exe window doesn't close, I'd suggest not to port that.

Anyway, this is all really basic stuff, take a look at some basic shell scripting tutorials like:
https://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/unixscripting/unixscripting.html

share|improve this answer
3  
.//usr/share/ant/bin/ant is a nonsense path, there shouldn't be a ./ before the variable –  DerfK Jun 24 '11 at 22:30
    
You are of course correct, edited. Thanks. –  faker Jun 24 '11 at 22:37
 #!/bin/bash
 cd /path/to/working/directory
 source ../config/setenv
 $ANT_HOME/bin/ant -f ../config/common.xml start_db
 $ANT_HOME/bin/ant -f ../config/common.xml start_server
 sleep 10

Once you're in a script you can call scripts directly - however the problem with this is that all the calls are relative. That's fine if you can be sure of that - so what you can do is add a command to make sure of that - cd /path/to/working/directory

share|improve this answer
    
Does this actually work? the script doesn't export the variables and you're not sourcing the script –  ptman Jun 24 '11 at 22:29
    
Correct I should have sourced setenv –  BZ. Jun 24 '11 at 22:34

if you want to pull in those environment variables use the keyword "source" (aka '.') instead of call

for starting the programs you don't need to prefix "call"

additionally variables are referenced by $variablename instead of %variablename%

share|improve this answer

And another example:

#!/bin/bash

export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24/
export ANT_HOME=/usr/share/ant

$ANT_HOME/bin/ant -f ../config/common.xml start_db
$ANT_HOME/bin/ant -f ../config/common.xml start_server
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.