Java wrapper - help needed
Bob Proulx
bob at proulx.com
Tue Jun 14 04:23:22 EST 2011
Sinkarbabu wrote:
> One more question: Is there any API available in any native language
> that can be used to administer OpenSSH (For example, start/stop and
> may be a notification in case of failed transfer etc.)?
Hi Sinkar, The problem with the specifics of the questions you are
asking are that they really have little to do with ssh or sshd
themselves. Instead they relate to how do you use them *on some
particular operation system*. And there are a very many different
operating systems. Just within the BSD family there are many and
and within Unix more within GNU/Linux many more. I don't think it is
possible to count them because they keep moving around but dozens of
reasonably well used ones and hundreds possibly thousands of others.
In each of those the answer to your questions may be different.
For example on HP-UX the startup scripts for sshd is /sbin/init.d/sshd
but on Debian GNU/Linux it is /etc/init.d/ssh and it is different
elsewhere such as /etc/rc.d/init.d/sshd on RHEL. And each of those
may be somewhat different from each other. None of those are included
in OpenSSH itself but are added by the operating system.
To hide some of those differences and for other reasons it seems that
most GNU/Linux distributions are converging on a 'service' command.
So for a later GNU/Linux system such as Debian or Red Hat the
following will probably be what you need to start and stop the ssh
daemon. But not necessarily. Your system may be different.
service sshd start
service sshd stop
service sshd restart
And then you ask about failed transfers... The exit code of programs
will tell you whether the command executed successfully or not. The
scp command documents this in the man page:
EXIT STATUS
The scp utility exits 0 on success, and >0 if an error occurs.
You should always check the return code for status. For example you
could do this:
#!/bin/sh
if scp localfile foo.example.com:/remote/file; then
# scp will have produced error messages appropriately
exit 1
fi
exit 0
Or some people prefer the use of -e:
#!/bin/sh -e
scp localfile foo.example.com:/remote/file
exit 0
Does that help you? Maybe and maybe not. You say you are using
Java. But OpenSSH is written in C. And I will hazard a guess that
most of the developers are also very familiar with shell scripting.
But Java specifics? Probably less so, don't know.
If you are trying to use Java then I might suggest that a Java
specific mailing list might help. It doesn't really matter that you
are invoking ssh as it could be any program.
Bob
More information about the openssh-unix-dev
mailing list