Hey all, Ive been using a new SHH library to send commands to a unix server and its been working great for me. It sends normal commands just fine and recives the proper responses. However, I seem to be running into an issue when I try to use it to run a custom script (not a shell script, but a file that contains another command and has arguments)
Ive tried several ways to get this to work.
On the unix server itself the following commands work perfectly and do what they are intended:
- cd script; script.oi someArg someArg – WORKS
- csh -c “cd script; script.oi someArg someArg” – ALSO WORKS
- cd /users/bin/script; script.oi someArg1 someArg 2 – WORKS
- csh -c “cd /users/bin/script; script.oi someArg1 someArg 2” – WORKS
- /users/bin/script/script.oi someArg1 someArg2 – WORKS
However, in the code I have tried the following:
string command = string.Format("csh -c \"cd script; script.oi {0} {1}\"", arg1, arg2); - DOES NOT WORK
string command = string.Format("cd script; script.oi {0} {1}", arg1, arg2); - DOES NOT WORK
string command = string.Format("cd /users/bin/script; script.oi {0} {1}", arg1, arg2); - DOES NOT WORK
string command = string.Format("csh -c \"cd /users/bin/script; script.oi {0} {1}\"", arg1, arg2); - DOES NOT WORK
string command = string.Format("/users/bin/script/script.oi {0} {1}", arg1, arg2); - DOES NOT WORK
So to me it seems like something else is going on. I did try the following:
string command = string.Format("csh -c \"ls\"", arg1, arg2);` - WORKS
string command = string.Format("ls", arg1, arg2);` - WORKS
It looks like it has to do with the fact that Im trying to run a custom script, or maybe some silly setting I’ve forgotten. Let me know if you need anymore details.
EDIT: By DOES NOT WORK, I mean that the result that is returned to the C# is supposed to say some stuff, but the result is blank. Additionaly, the script sends a TIBCO Rendevous message which eventually adds an entry to a DB, which is not showing up. When I say WORKS, I mean that the entry is showing up in the DB.
Well, I figured it out. Turns out the script was running a command that is known to the unix server via being added to the unix eviroment variables. When just using the standard way to send commands in SSH.NET, the enviroment variables are not imported (which is why you are able to send normal commands like ls, grep, cat, ect, but not this one).
The fix was to use the libraries SSH shell functionality because it does import the enviroment variables, therefore it knows what that command in the script is and is able to run it. For those using this great library (which is still be activily developed, always a plus) I have included below example SSH.NET Shell code.