#1
|
|||
|
|||
Problem running commands with ssh
OK probably an easy one for you :-)
I am having trouble running the dir command with ssh on Windows servers running vShell (VShell_2_3_1_151) and using OpenSSH (OpenSSH_4.1p1) for the client. I have also tried to use vsh (VSH version 5.0.0 (build 62) starting. (Using SSH2Core version 3.1.0.545.). If I make a simple .bat file on the remote server to issue the dir command then execute that with ssh it works. Is there a problem running shell built in commands? This is what I get [ 7:25][C:\work]>ssh -p 22 -i c:/.ssh/id_dsa user@server dir 00007: Could not start program (dir): The system cannot find the file specified. Does this really not work or am I just overlooking something? Thanks in advance for you help. |
#2
|
||||
|
||||
Many windows DOS commands such as 'DEL' and 'DIR' are built-in commands that is only available within the command shell 'cmd.exe'. Remote execution within VShell for windows does not include running the client-specified command within a command shell. Therefore, the command shell must be run as part of the remote execution as specified from the client's side. Remote execution of 'cmd /C <command>' should work successfully.
In your particular case, this should work: Code:
ssh -p 22 -i c:/.ssh/id_dsa user@server cmd /c dir
__________________
Robert Stehwien VanDyke Software Software Developer |
#3
|
|||
|
|||
What about spaces in the remote path
Thanks for the information. That has been working now for some time. We now have come across a problem issuing a command to delete a file or do a directory list where the remote path contains spaces in it, I've enclosed the command in double quotes and it's still not working. I can do it interactively, but not when it's passed to ssh or vsh on the command line.
I'm connecting to a windows server running vshell. Our ID has both Remote execution and Shell enabled in the Access control section of the vshell config. We are connecting from another Windows server using either ssh or vsh to send the commands. Here's an example vsh -auth publickey -i c:\.ssh\id_dsa ourid@servername cmd /c dir "e:\share1\Data Feeds\AD\PROD\PAYROLL\FTP Pickup\*.*" vcp has no problems pulling or pushing the file to/from this same location. What am I missing? Thanks! Matt |
#4
|
|||
|
|||
Hi matt131,
Are you saying that if the remote path doesn't have spaces there is no problem? According to the cmd.exe help message, the following behavior applies to the use of quote characters in combination with the /C command line parameter: Code:
If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters: 1. If all of the following conditions are met, then quote characters on the command line are preserved: - no /S switch - exactly two quote characters - no special characters between the two quote characters, where special is one of: &<>()@^| - there are one or more whitespace characters between the the two quote characters - the string between the two quote characters is the name of an executable file. 2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character. Does the command work if you specify the "tilde" naming convention? For example: vsh -auth publickey -i c:\.ssh\id_dsa ourid@servername cmd /c dir "e:\share1\Data Feeds\AD\PROD\PAYROLL\FTPPic~1\*.*" |
#5
|
|||
|
|||
Hi Todd, thanks for the info, I was able to get the command to work using the short names for the folders like this.
vsh -auth publickey -i c:\.ssh\id_dsa ourid@servername cmd /c dir "E:\share1\DATAFE~1\AD\PROD\PAYROLL\FTPPIC~1\*.*" I don't have the name of an executable in between the quotes, and I think the command I was using met all the criteria defined in the text you posted, so I'm still not sure why it wont work with the long names including the spaces. Maybe I'm misunderstanding how this should work? Quote:
vsh -auth publickey -i c:\.ssh\id_dsa ourid@servername cmd /c dir "e:\share1\Data Feeds\AD\PROD\PAYROLL\FTP Pickup\*.*" Thanks! Matt |
#6
|
|||
|
|||
Hi Matt,
Our suspicion was because you didn't have the name of an executable between the quote characters, they were being stripped. We interpreted bullet point #5 in the first section of the cmd.exe documentation to mean that to keep the quote characters one would have to have the name of an executable within the quote characters. In further testing we found that 2 additional quotes at the beginning of the string and 1 additional quote to the end resolved the problem as well. For example: vsh -auth publickey -i c:\.ssh\id_dsa ourid@servername cmd /c dir """e:\share1\Data Feeds\AD\PROD\PAYROLL\FTP Pickup\*.*"" Does this technique work for you as well? |
#7
|
|||
|
|||
Yes that works. Thanks for the help!
Matt |
#8
|
|||
|
|||
Hi Matt,
I am glad that we could help you get this working. |
![]() |
Thread Tools | |
Display Modes | |
|
|