run Java commands through a Shell script - java

I'm trying to code a shell script to start/stop torrents using vuze's console UI through SSH:
https://wiki.vuze.com/w/Console_UI
I've downloaded vuze and everything works fine until I type this command:
java -jar Azureus2.jar --ui=console
After that, no command in my script works unless I quit that console.
Any solutions please? And if it's not feasible using shell scripts, any suggestions please?
Thanks.

Basically, the moment you run that command, your java program runs 'in the foreground', which means the rest of your script stops executing until your program exits.
If you want to keep on running the rest of your script while your java program executes you have to run your program in the background. One way to do that is as #Alp suggests:
java -jar Azureus2.jar --ui=console &

Related

Php exec is not running properly when called from Java on localhost

I have a problem running the exec command from within a php script.
here's the detailed scenario:
I have an executable my_exe which runs from command line. This executable uses an environment variable, so I prepend the command with MY_VARIABLE='value' (works fine).
I use the exec command to run this executable from a Php script. ex: exec("MY_VARIABLE='value' my_exe"); (works fine too, tested in a browser)
The problem is in this part. When I call the php script from a Java program using HttpUrlConnection, I have two cases: if I run the Java program from outside the server (using public IP address) I get the good results, but when I run it from the server (using local IP, form command line ex. "java -jar /path/to/my/jar"), the Php works but the exec doesn't seem to be working properly. The environment variable is not being set in this case, so the executable runs but without the right values, so I get no results.
Any help is appreciated. I'm really stuck here. My guess is that there is a problem with Php or Java permissions, but I can't figure it out.
Strange command exec("MY_VARIABLE='value' my_exe");... it will work only on linux machine and will not on windows.
As a first step, try to rewrite you php code like this:
putenv("MY_VARIABLE=value");
exec("my_exe");
and see what happen.

Listen to serial port at STARTUP using java with arguments on Debian(Rasbian)

I've been stuck two weeks trying to figure out how to run this at startup.
I use the following chain of commands on the terminal:
1. source ~/.bashrc
2. source ~/.tinyos.sh
3. java net.tinyos.tools.Listen -comm serial#/dev/ttyUSB0:telosb | python demo.py`
The third command uses java to listen to the serial port and pipes it to a python script which cleans, converts and uploads to mysql localhost.
This works fine on ssh terminal. But ive tried using nohup+update-rc.d, upstart, systemd, crontab to make it run on startup and it just wont work! When I reboot and check logs / database, its as if the command never happened. I need this to run like a daemon and continue running until shutdown.
Thanks a lot.
How are you trying to execute the program ? Are there are permission issues accessing / executing the script ?
Which version of debian are you running - look at upstart scripts if you are running Jesse+
I'd put those three lines in a bash script and use upstart scripts to trigger them on start. Another option is to use supervisord to make sure that your scripts run and restart if for any reason the program crashes.

Commands in Java Console

I'm trying to automate creating torrents/starting downloads/limiting Bandwidth... etc using Vuze.
So far I've written a shell script to send Vuze and the torrent to all the clients. However when it comes to creating torrents, after executing this command : java -jar Azureus2-XXX.jar --ui=console or java -jar Azureus2-XXX.jar --ui=console &, the console looks like this and no command after that works unless I quit the Java program.
Any help would be much appreciated. Thanks!

How to run matlab on the background?

I'm currently using an external editor of Matlab .m files, with a custom build system that calls Matlab from the command line to run the Matlab script (with the -nosplash and -nodesktop). However this creates two problems:
1) Matlab closes right after running the script: any windows or plots I call in the script are closed right after running the script, which obviously happens in a matter of seconds.
2) There is a slight delay every time I run the script because Matlab is effectively being started from scratch.
So I was wondering if would be possible to have Matlab running in the background, and just running the scripts whenever I want?
I'm running Linux 64bits, Matlab 2013a, and Sublime Text 3.
EDIT: I've testing the setup with a basic script:
a=5;
figure
plot(a);
EDIT2: I'm calling Matlab through a Sublime Text build system that runs:
matlab -nosplash -nodesktop <[script].m
There is no way to have Matlab running in the background and "just running the scripts whenever you want" without having an interactive session open somewhere.
Suppose that your system has a custom wrapper matlab-wrapper that is used to submit scripts in the background. You would call your script like this:
$ matlab-wrapper myscript.m
Likely, matlab-wrapper is doing something like this:
#!/bin/bash
/apps/matlab14a/bin/matlab -nodesktop -nosplash -r run\ "$1",exit
Or even more, submitting the above script to a scheduler via qsub or some other command.
The key would be modify the wrapper script to find the part where the Matlab binary is actually invoked. If your system allows, you could copy the wrapper script and modify it. (Either by simply removing the -r run\ "$1" text or something more complicated.) Then, you should be able to launch an interactive version of Matlab per the custom configuration on your system, and call your scripts from the Matlab command window.

Java JAR file does not execute in startup script in Ubuntu 14.04

The following process normally works for my startup scripts. However, when I introduce a command to execute a JAR file, it does not work. This script works while I am logged in. However, it does not work as a startup script.
In /etc/init.d I create a bash script (test.sh) with the following contents:
#!/bin/bash
pw=$(curl http://169.254.169.254/latest/meta-data/instance-id)
pwh=$(/usr/bin/java -jar PWH.jar $pw &)
echo $pwh > test.txt
Make script executable
In /etc/rc.local, I add the following line:
sh /etc/init.d/test.sh
Notes:
I make a reference to the script in /etc/rc.local, because this script needs to run last after all services have started.
Please do not ask me to change the process (i.e., create script in /etc/init.d/ and reference it from /etc/rc.local), because it works for my other startup scripts.
I have tried adding nohup in front of java command, and it still did not work.
Thanks
As written, there is insufficient information to say what is going wrong. There are too many possibilities to enumerate.
Try running those commands one at a time in an interactive shell. The java command is probably writing something to standard error, and that will give you some clues.

Categories