How would I send a remote command to a UNIX box from a PC using C#?

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 2
Reputation: dalebert is an unknown quantity at this point 
Solved Threads: 0
dalebert dalebert is offline Offline
Newbie Poster

How would I send a remote command to a UNIX box from a PC using C#?

 
0
  #1
Jan 3rd, 2008
I have a simple function that I wish to perform in a .NET program. I am currently working in C# with .NET version 1.1, but any .NET language help would be useful. I want to be able to send a remote command to a UNIX or VxWorks computer form a Windows PC. From VxWorks to UNIX this would require only a single line of code - a call to the function "rcmd", as in this example that gets the time on the UNIX box:

int getHostDate
(
char *unixHost,
char *userId,
char *userPassword,
char *returnDate,
char returnErrorMsg[30],
int  outFormat	/* 0 = default 1 = numeric */
)

{
int rshdSockFd;
char userName[20];
char dateCmdStr[30];
char buf [BUFSIZE];
int nRead;


if (unixHost == NULL)
	{
	sprintf (returnErrorMsg,"Invalid host name\0");
	return (ERROR);
	}

if (outFormat == 1) {
	sprintf(dateCmdStr,
	       "date '+%%Y %%m %%d %%w %%H %%M %%S'");
	}
else	{
	sprintf(dateCmdStr,"date");
	}



   if ((rshdSockFd = rcmd (unixHost, RSH_PORT, userId, userPassword, dateCmdStr, 0)) == ERROR)
	{
	sprintf (returnErrorMsg,"Remote Command Failed\0");
	return (ERROR);
	}


if ((nRead = read(rshdSockFd, buf, BUFSIZE)) == ERROR)
	{
	sprintf (returnErrorMsg,"Read from Socket Failed\0");
	close (rshdSockFd);
	return (ERROR);
	}
else
	{
	buf [nRead - 1] = '\0';
	sprintf (returnDate,"%s", buf);
	close (rshdSockFd);
	return(nRead);
	}
}

I have searched the web to see what others do, and the usual answer is to write a new server on the UNIX side. This seems like severe overkill, as the ability to receive remote commands already exists in UNIX, as evidenced by the working code above. This action can be accomplished manually by simply bringing up a telnet window and typing in the appropriate commands. Is it really so difficult to do in .NET that it is better to change the UNIX server itself (a suggestion I wouldn't even think of making)?

Thanks,
Dale
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,342
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How would I send a remote command to a UNIX box from a PC using C#?

 
0
  #2
Jan 3rd, 2008
>>This action can be accomplished manually by simply bringing up a telnet window and typing in the appropriate commands
When you bring up that telenet program doesn't it require you to log into the *nix box before you can do anything? Yes, then at that point there is a server program running on the *nix and your telenet session is nothing more than another terminal type to the *nix login shell. I don't think that is the same type session that you have in mind for your C# program.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2
Reputation: dalebert is an unknown quantity at this point 
Solved Threads: 0
dalebert dalebert is offline Offline
Newbie Poster

Re: How would I send a remote command to a UNIX box from a PC using C#?

 
0
  #3
Jan 4th, 2008
Originally Posted by Ancient Dragon View Post
>>This action can be accomplished manually by simply bringing up a telnet window and typing in the appropriate commands
When you bring up that telenet program doesn't it require you to log into the *nix box before you can do anything? Yes, then at that point there is a server program running on the *nix and your telenet session is nothing more than another terminal type to the *nix login shell. I don't think that is the same type session that you have in mind for your C# program.
Thanks for the quick response. I admit I am not enough of an expert to know if the 'rcmd' function utilizes telnet protocol, but if you look at the function in the code I posted, it contains parameters for the user ID and password so, yes, in a sense, it looks like it is logging you in every time it is called. In the same way, you can log in from any UNIX station to any other UNIX station that you have an account on, use FTP protocol to transfer files, or mount a disk from another machine if it is configured to allow this. I had thought that .NET was intended to expand interoperability across platforms, so I hoped it would have some functionality to handle these types of operations. I understand that .NET 2.0 and above does support FTP protocol for moving files. I don't know if Telnet protocol is ever going to be supported for remote commands.

I definitely don't want to write my own telnet protocol code. Hyperterminal is loaded on my PC, but it does not seem to support scripting or a way to support return values to a program. There may another third party program I can use, but I haven't found it yet.

Thanks again,
Dale
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC