Relatively new to this but, I was planning to write a simple android application which can run and execute simple terminal commads like ssh, change directories etc. But i want to create buttons for each command. so (cd..) command will be a button, (mkdir) will be another. The main idea is to connect to a Linux server and then execute these commands on them, I would also use some commands which start services or kill services.
I want to know if there is any class in Android which allows me to run these commands programmatically?.
Thanks in advance.
I want to know if there is any class in Android which allows me to run these commands programmatically?.
No, unless you count Socket.
Instead, you would need to find an SSH client library for Android, or perhaps for ordinary Java (and hope that it runs unmodified on Android).
Related
Is it possible to create for only one process two different CLI (CommandLineInterface)?
I would like to have one CLI with my real program, and another CLI for a chat, so that i can send command to my program and send messages in the chat at the same time, and obviously have different views for the program and the chat.
(edit)
the program is a game and the chat is to make communication between all player, but when i start my program in eclipse, that program strat with only a console and here i would like to have two console in one there is the game with its action and state and in the other one i would like to have all the messages in the chat.
I know that i can build another process from zero and integrate it with process builder, but i would like to have all in one process.
If I assume that by CLI you mean the main terminal from where you execute your program, the answer is NO, regardless the OS.
There are couple of options to implement additional CLI interfaces in the same process:
listening on socket and waiting for client(s) to connect by e.g. telnet
opening a window that implements the CLI
under UNIX you can spawn e.g. a xterm and process its IO in your process
Under Linux or OSX, just open a new terminal window, and you will have an additional CLI to work with, and yes, you can try your program from those two different environments simultaneously and independently.
Under Windows, I couldn't say. You're probably using cygwin or something like that, so you should probably try to be a bit more specific in your question to get more attention.
I want to write a program which connects to remote machines via ssh and install predefined software. Also I wanna make process of installing clear for users by make all it visible to users. I have faced some problems: how to open terminal from java and send commands to it?(OutputStream doesn't work) How to execute command in this terminal when I already ssh? I want to run local scripts on the remote machine and allow user? to interact with terminal, when script is running (for example accept licence of software and so on).
I was trying something like this but it is not working.
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("x-terminal-emulator -e ./script.sh");
In theory it is possible. You'll need a java library, such as JSch, to interact directly with a terminal via ssh, and then make use of the screen utility to share a single terminal screen between your java prog and a user.
From your java prog:
screen -d -m -S shared
screen -rx shared
<type your installation commands>
From the remote user:
screen -rx shared
Of course the remote user must wait until the java prog initializes the screen in order to attach to it.
Please note that all kinds of things can go wrong when you let users interact with the screen. Your program must be smart enough to handle it.
I want to develop a program for ubuntu platform, That listens to DialUp modem and get Calls and send them to my php program that's running on my localhost.
for example when somebody calls my phone line, my listener program give the number and run this query:
http://127.0.0.1:80/listen.php?caller=ThePhoneNumber
How can I do that? is there any classes in java for that?
I think you'd need native tools for that. You can make pppd answer the call and run a custom script or program. But I have not fiddled with that for a long time. See linux modem howto. There should be plenty of information.
I developed a java desktop application where the user can manually load a file and press a button to start a simulation process. I want to automate the above two steps so that an external program can iteratively call this desktop application multiple times and run the simulation process without any human intervention every time. Any thoughts on how I can go about doing this?
It depends on which OS you do it.
If OS X, use automator, for Windows you can use winautomation and for Linux use google and search (for example) kde automation.
I know this is an old question. But there is a new solution now,
JAuto: a JVMTI agent that runs in Java VM and expose UI widget attributes such as class names, screen coordinates. You talk to JAuto by sending a command to a named pipe. It responds by writing a file. It lets you control a Java program via bash scripts.
Using an input simulator such as xdotool, you can achieve automation under the Linux X11 settings.
Disclaimer: I'm the author of JAuto.
I ruby there is great https://github.com/vcr/vcr gem, but works only with ruby HTTP libraries. Is there tool that can be used to record and play network traffic, but from system level, or at least in java?? If not, could you give me proof of concept how to create such tool (only for linux)?
You can use TCPRelay to play network packets captured in libpcap format.
If you are using a protocol like sip, you can use Sipp, other option is to use mts-project.
Checkout betamax. It's a port of VCR for the JVM.
I use wireshark... which has a command line version called tshark. you can install that on centos via yum install wireshark-gnome (wireshark will install the gui, but wireshark-gnome ads it to your /bin and gives you tshark.)
I use Jenkins CI to run all my tests... for example, I work with VOIP/SIP testing a lot... so I have a jenkins job that when run:
starts SIPP load to a server
starts tshark recording to a file
I use a command line param to keep thsark to running for a duration - however you can use a signal to stop tshark as well.
you can set tshark to do a packet capture and pick up everything, or filter just certain layers, like RTP only or SIP only, etc.
If you dont want to use Jenkins to manage this, you can call tshark programatically via Ruby or any scripting language... Just use Ruby to open and run the application... like: Running command line commands within Ruby script
for Java. try anystub. you could record/playback any invocation in your project