| | |
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
![]() |
•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Solved Threads: 0
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:
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
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
>>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.
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.
•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
>>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.
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
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- This Should be Easy for You Guys! (Linux Servers and Apache)
- Homepage has been changed to about:blank (Viruses, Spyware and other Nasties)
Other Threads in the C# Forum
- Previous Thread: Can anyone help me with composing of frames into a video?
- Next Thread: Convert an XML file into a Binary Format File
| Thread Tools | Search this Thread |
.net access algorithm animation array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom customactiondata database datagrid datagridview dataset datastructure date/time datetime datetimepicker degrees development dll draganddrop drawing encryption enum event excel file filename files form format forms function gdi+ gis gtk hash image index input install java label list listbox mandelbrot math mouseclick mysql operator outlook2003 path photoshop picturebox pixelinversion pixelminversion post programming radians regex remoting richtextbox server sleep snooze socket sql statistics stream string table tables tcp text textbox thread time timer update usercontrol usercontrols validation visualstudio webbrowser webcam wia windows winforms wpf xml






