473,396 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
di***@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.

Feb 20 '06 #1
4 3874
On 20 Feb 2006 14:57:09 -0800, "cp**********@yahoo.com"
<cp**********@yahoo.com> wrote:
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
di***@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.


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
Feb 21 '06 #2
Perhaps you should try Expect scripts rather than write your own tool
using C.

/Why Tea

Feb 21 '06 #3
Hi
edit file /home/phy/students/dixit/.ssh/known_hosts
remove everything from it ,
then it will work ,

bye

Feb 21 '06 #4
"th*******@gmail.com" <th*******@gmail.com> writes:
edit file /home/phy/students/dixit/.ssh/known_hosts
remove everything from it ,
then it will work ,


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) ks***@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.
Feb 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Bennett | last post by:
Does the .NET framework (using VB.NET) support the ability to programmatically STOP a device prior to its removal from the system? I have need to move data from a computer on one network to a...
1
by: A Hirsi | last post by:
I have created a vb .net program as a service that is using a simple ftpclient to connect to a remote server and check the status of a file for subsequent downloading if there have been changes to...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
by: maz01 | last post by:
Hello All, I am developing an application in visual basic 2005 that will run continuously in the background on a users workstation. This application will automatically transfer files from the...
5
by: ranishobha21 | last post by:
Dear all, i want to send some unix commands to remote unix machine in france through php.i am using socket communication in php, i have written a socket communication program so that it...
1
by: Brad Isaacs | last post by:
I am working with ASP.NET 2.0 and using an SQL Server 2000 database. I am using Visual Studio 2005 and developing on my Local machine. I am working with Login controls ASP.Configuration, I...
1
by: danfolkes | last post by:
Hey Everyone, I am trying to send repeated messages from a "Node" to a "Server". It works the first time I send the from the Node to Server, but after that it either errors, or does not do...
6
by: tmallen | last post by:
Here's the code: http://pastebin.com/m21dfcc19 What could be improved? The script feels clumsy, and I have no experience refactoring Python code. This will eventually be a GUI FTP client. I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.