This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes Need Unix/ssh help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Need Unix/ssh help" Watch "Need Unix/ssh help" New topic
Author

Need Unix/ssh help

Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

I am having this sttange problem now -

We have 2 live servers
(1) X ==> A normal 32 bit machine running Linux
(2) Y ==> A new AMD 64 bit machine running almost same config as X

I have a third party C application "ABC" that we have compiled and running on server X. It runs fine and our server code (Java) interacts with application and gets some results.

This C application ABC is giving "segmenation fault" on the new 64 bit machine, and being a third party application we are not going to fix it.

A solution that has been suggested is this -

Server Y runs application ABC (it's a C executable, and not a service running on server at specific port as such) on server X via a shell script available on Y that in turn does SSH to run ABC on X and gets the results, and ths script gives those results to server code running on Y.

How do I do this??? Has someone done sth similar? Any idea how I can do this between X and Y? An example would be GREAT!!!

This is sort of urgent, so would grealy appreciate help from Unix gurus!!!

Thanks,
- Manish
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
Originally posted by Manish Hatwalne:
We have 2 live servers
(1) X ==> A normal 32 bit machine running Linux
(2) Y ==> A new AMD 64 bit machine running almost same config as X

Server Y runs application ABC (it's a C executable, and not a service running on server at specific port as such) on server X via a shell script available on Y that in turn does SSH to run ABC on X and gets the results, and ths script gives those results to server code running on Y.

How do I do this??? Has someone done sth similar? Any idea how I can do this between X and Y? An example would be GREAT!!!


i do this sort of thing every day.

first you have to ensure that server X has the ssh daemon (sshd) installed and running by default. it will listen on port 22/TCP, so you'll have to ensure that port is reachable through any firewalls or network security you may have installed.

client Y needs to have the ssh client program installed and runnable by whoever wants to use application ABC. this person doesn't necessarily have to have a username and password to log in to server X, but it helps for getting started.

the simplest, most straight-forward way to use ssh is simply to log in to your client machine, Y, and say "ssh X", using X's full hostname. you'll be prompted for your password - unless you specify otherwise, ssh will assume for simplicity that your username on X is the same as your username on Y and try to log in with that. (to use a different username, read ssh's man page and note the "-l" parameter.) once you're logged in on machine X, you can run any program you wish there - including graphical programs, if you have X-Windows started on machine Y first. once you're done, just type "exit" at the shell prompt on X and your SSH session to X will end.

there is a way to bypass the password prompting, by using RSA authentication instead of password authentication. it's a bit more advanced subject, though; it involves creating a ".ssh" subdirectory in your home directory (on both machines!) and creating some specific files in those directories; it's a somewhat involved process, but it generally only needs doing once. the best way to learn this is probably to buy the O'Reilly book on SSH (this book) and read the chapters on public-key authentication.

when you first get SSH RSA authentication running, you may be confused that SSH still asks you for a password - even though that's what you were trying to avoid. yes, it does ask for a password, this being the password to the RSA key in your ~/.ssh directory; to get around this, you need to have ssh-agent running as well. if you have ssh-agent running, you'll be asked for the password to your RSA key only once, when you first log in; after that, you'll be able to just SSH over with no questions asked. a lot of Linux distributions will automatically start ssh-agent when you log in, if you have the right files set up in your ~/.ssh directory. if yours doesn't do this, try reading that book i linked to, and/or investigate getting gentoo keychain to run on your machine. (it runs on mine, and does a great job.)
[ February 08, 2005: Message edited by: M Beck ]
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

I need to automate all this in a script, the authentication problem wil be taken care of. How do I do this in the script now -

ssh X ABC <parameters for ABC>
return results returned by ABC running on X

TIA,
- Manish
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
you do it exactly the way you just wrote it - "ssh X ABC". if this doesn't work for you, how does it fail?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The first command line argument in ssh after the remote machine name is a command to be executed on the remote machine. The results from the execution of that command can be piped into any program on the local machine.

As an example, I'll SSH into a machine named remote (names changed to protect the innocent) and run the ls command on it. I'll then pipe the results of the ls command on the remote machine into the sort (with the -r option so I can see that it did something) command on my local machine:

I'm not using password files so I'll have to authenticate at the command line:




Once you get your password files all set up, you can do this from a script.
[ February 08, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Unix/ssh help
 
Similar Threads
how to know that a particular ip is being accessed.
Problem wit UIL ??
Access unix machine to read and save a file
Passed 700,701 and 340 last Thursday
Display variable on unix