Results 1 to 6 of 6

Thread: How to convert .bat-syntax to .sh-syntax?

  1. #1
    Join Date
    Jan 2007
    Location
    Amsterdam, Nederland
    Beans
    814
    Distro
    Ubuntu Development Release

    Question How to convert .bat-syntax to .sh-syntax?

    Hello,

    I've been using Ubuntu for years now, and I love it. I now have a small java application which is supposedly cross-platform. I need to edit a file (.bat) which should start the application. In the readme of the program it says "Linux users should have no difficulty adapting the sample command files to the appropriate command syntax.". Apparently people still think that all Linux users are hardcore hackers..

    I do know a little bit about Linux though . As far as I know I should convert the .bat file to an .sh file. So I simply changed the extension of the file to .sh . This didn't help, since the command line tells me that the file contains all kinds of things that it doesn't know, like ":::", and "Syntax error near unexpected symbol '('".

    Could anyone help me with some tips to convert the following lines to Linux-compatible syntax?
    Code:
    set IBCDIR=/home/kram/IBController/
    set TWSCP=jts.jar;hsqldb.jar;jcommon-1.0.12.jar;jfreechart-1.0.9.jar;jhall.jar;other.jar;rss.jar
    set JAVAOPTS=-Dsun.java2d.noddraw=true -Xmx512M -XX:MaxPermSize=128M
    pushd %TWSDIR%
    java.exe -cp  %TWSCP%;%IBCDIR%\IBController.jar %JAVAOPTS% ibcontroller.IBController %IBCINI% %TWSUSERID% %TWSPASSWORD%
    popd
    All tips, hints and lessons are welcome!

  2. #2
    Join Date
    Dec 2008
    Location
    UK
    Beans
    434
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: How to convert .bat-syntax to .sh-syntax?

    Hi,

    Here's my initial go at the conversion:

    Code:
    set IBCDIR=/home/kram/IBController/
    set TWSCP="jts.jar:hsqldb.jar:jcommon-1.0.12.jar:jfreechart-1.0.9.jar:jhall.jar:other.jar:rss.jar"
    set JAVAOPTS=-Dsun.java2d.noddraw=true -Xmx512M -XX:MaxPermSize=128M
    pushd $TWSDIR
    java -cp  $TWSCP:$IBCDIR/IBController.jar $JAVAOPTS ibcontroller.IBController $IBCINI $TWSUSERID $TWSPASSWORD
    popd
    The path separator under Linux is the ':' character and variables in the script change from %TWSCP% to $TWSCP
    Last edited by Azdour; September 21st, 2011 at 10:09 AM.

  3. #3
    Join Date
    Apr 2005
    Location
    Finland/UK
    Beans
    Hidden!
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How to convert .bat-syntax to .sh-syntax?

    Something like this, perhaps:
    Code:
    #!/bin/bash
    
    IBCDIR="/home/kram/IBController"
    TWSCP="jts.jar:hsqldb.jar:jcommon-1.0.12.jar:jfreechart-1.0.9.jar:jhall.jar:other.jar:rss.jar"
    JAVAOPTS="-Dsun.java2d.noddraw=true -Xmx512M -XX:MaxPermSize=128M"
    
    pushd "$TWSDIR"
    java -cp  "$TWSCP":"$IBCDIR"/IBController.jar "$JAVAOPTS" ibcontroller.IBController "$IBCINI" "$TWSUSERID" "$TWSPASSWORD"
    popd
    ...however the script seems to contain a couple of variables that are not defined in the script ($TWSDIR, $IBCINI, $TWSUSERID and $TWSPASSWORD). Make sure they are defined and properly exported somewhere.

  4. #4
    Join Date
    Jan 2007
    Location
    Amsterdam, Nederland
    Beans
    814
    Distro
    Ubuntu Development Release

    Re: How to convert .bat-syntax to .sh-syntax?

    Quote Originally Posted by mcduck View Post
    ...however the script seems to contain a couple of variables that are not defined in the script ($TWSDIR, $IBCINI, $TWSUSERID and $TWSPASSWORD). Make sure they are defined and properly exported somewhere.

    That's true. I took a couple variables out since I presumed that once I knew how to set variables correctly I could just replicate the trick to all the variables. So that's what I did.

    Thanks to you guys I get a bit further now (seriously, thank you!! ). The program seems to do something, but then I get the following:

    Code:
    09:09:29:191 IBController: ini file is /home/kram/GT/IBControllerV2-9-0/IBController.kram.ini
    09:09:29:196 IBController: IBControllerServer is started.
    09:09:29:205 IBController: IBControllerServer listening on address: kram-desktop/127.0.1.1 port: 7462
    Exception in thread "main" java.lang.NoClassDefFoundError: jclient/LoginFrame
    	at ibcontroller.IBController.startTws(IBController.java:418)
    	at ibcontroller.IBController.startTwsOrGateway(IBController.java:425)
    	at ibcontroller.IBController.load(IBController.java:188)
    	at ibcontroller.IBController.main(IBController.java:168)
    Caused by: java.lang.ClassNotFoundException: jclient.LoginFrame
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    	... 4 more
    I guess this is beyond your knowledge, since it concerns the contents of the program specifically. But if you have any clue of what I can do I would be very very grateful!

  5. #5
    Join Date
    Jan 2007
    Location
    Amsterdam, Nederland
    Beans
    814
    Distro
    Ubuntu Development Release

    Re: How to convert .bat-syntax to .sh-syntax?

    NEVERMIND!!

    I forgot two times to remove the "SET" before the variables. I removed them and it all works like a charm now. From now on I can sit back, relax and let my computer trade when I'm on holiday. (which means I'm probably broke once I get home.. but whatever.. )

  6. #6
    Join Date
    Feb 2011
    Beans
    2

    Re: How to convert .bat-syntax to .sh-syntax?

    I made the changes requested to the script, but I am only able to start TWS running it as a super user: $ sudo ./starttws.sh
    When it comes to scheduling it in cron it just doesn't start up which makes me think I should set up some environment variables to make it work. Can you please let me know what's your crontab line?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •