Connecting Tech Pros Worldwide Help | Site Map

PLEASE HELP Trying to use SSH programmatically to run program on remote host

cpptutor2000@yahoo.com
Guest
 
Posts: n/a
#1: Feb 20 '06
Could some C guru help me please? I am using the following program to
open a SSH connection to a remote host and eventually run a program on
that remote host.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]){
char command[50];

if(argc < 4){
printf("user name and/or remote host name and/or");
printf(" directory name not supplied\n");
printf("usage: ./argtest <username> <hostname> <remote directory
name>\n");
exit(0);
}

sprintf(command, "ssh %s@%s \"cd %s;\"", argv[1], argv[2], argv[3]);
/* printf("%s\n", command); */
system(command);

return 0;
}

After compilation, I use the command line arguments as follows:
../argtest dixit linux02.phy.utexas.edu
/home/phy/students/dixit/txtfiles
I get the following response:

Warning: the RSA host key for 'linux02.phy.utexas.edu' differs from the
key for the IP address '128.83.59.122'
Offending key for IP in /home/phy/students/dixit/.ssh/known_hosts:1
Matching host key in /home/phy/students/dixit/.ssh/known_hosts:5
Are you sure you want to continue connecting (yes/no)? yes
dixit@linux02.phy.utexas.edu's password:
Memory fault(coredump)

Could someone please point out what the problem is, that is causing the
coredump, and how to
fix it? I mean, if I just login to the remote machine, then there is no
problem at all, but if I attempt
to go some particular directory, I get this stupid core dump.

Moreover, if I can get into the remote machine and type in 'hostname
-v' I get the name of the local host, NOT the remote machine.

Thanks in advance for your help.

Bill Latvin
Guest
 
Posts: n/a
#2: Feb 21 '06

re: PLEASE HELP Trying to use SSH programmatically to run program on remote host


On 20 Feb 2006 14:57:09 -0800, "cpptutor2000@yahoo.com"
<cpptutor2000@yahoo.com> wrote:
[color=blue]
>Could some C guru help me please? I am using the following program to
>open a SSH connection to a remote host and eventually run a program on
>that remote host.
>
>#include <stdio.h>
>#include <stdlib.h>
>
>int main(int argc, char* argv[]){
> char command[50];
>
> if(argc < 4){
> printf("user name and/or remote host name and/or");
> printf(" directory name not supplied\n");
> printf("usage: ./argtest <username> <hostname> <remote directory
>name>\n");
> exit(0);
> }
>
> sprintf(command, "ssh %s@%s \"cd %s;\"", argv[1], argv[2], argv[3]);
> /* printf("%s\n", command); */
> system(command);
>
> return 0;
>}
>
>After compilation, I use the command line arguments as follows:
>./argtest dixit linux02.phy.utexas.edu
>/home/phy/students/dixit/txtfiles
>I get the following response:
>
>Warning: the RSA host key for 'linux02.phy.utexas.edu' differs from the
>key for the IP address '128.83.59.122'
>Offending key for IP in /home/phy/students/dixit/.ssh/known_hosts:1
>Matching host key in /home/phy/students/dixit/.ssh/known_hosts:5
>Are you sure you want to continue connecting (yes/no)? yes
>dixit@linux02.phy.utexas.edu's password:
>Memory fault(coredump)
>
>Could someone please point out what the problem is, that is causing the
>coredump, and how to
>fix it? I mean, if I just login to the remote machine, then there is no
>problem at all, but if I attempt
>to go some particular directory, I get this stupid core dump.
>
>Moreover, if I can get into the remote machine and type in 'hostname
>-v' I get the name of the local host, NOT the remote machine.
>
>Thanks in advance for your help.
>[/color]

It looks like sprintf will be trying to place more characters in
"command" than sizeof(command).

Also, it sounds like you are not aware that if you specify a command
as an argument of ssh (cd in this case), ssh will end the remote
session after running the command. It sounds like you expect it to
stay connected in a shell session. If you have a questions about ssh,
this is not the appropriate newsgroup.

Bill Latvin
Why Tea
Guest
 
Posts: n/a
#3: Feb 21 '06

re: PLEASE HELP Trying to use SSH programmatically to run program on remote host


Perhaps you should try Expect scripts rather than write your own tool
using C.

/Why Tea

thisisnee@gmail.com
Guest
 
Posts: n/a
#4: Feb 21 '06

re: PLEASE HELP Trying to use SSH programmatically to run program on remote host


Hi
edit file /home/phy/students/dixit/.ssh/known_hosts
remove everything from it ,
then it will work ,

bye

Keith Thompson
Guest
 
Posts: n/a
#5: Feb 21 '06

re: PLEASE HELP Trying to use SSH programmatically to run program on remote host


"thisisnee@gmail.com" <thisisnee@gmail.com> writes:[color=blue]
> edit file /home/phy/students/dixit/.ssh/known_hosts
> remove everything from it ,
> then it will work ,[/color]

Since you didn't provide any context, we can't necessarily tell what
you're talking about. Please read <http://cfaj.freeshell.org/google/>.

I happen to know that your suggested solution will not necessarily
work, depending on some details of the configuration. I won't go into
details here, since they're off-topic. This is why we try to
discourage off-topic discussions here; it's far too easy for
misinformation to go uncorrected.

If you want to discuss ssh, please post to comp.security.ssh, not here.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Closed Thread