Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Secure Shell

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2005, 06:40 AM
matt131 matt131 is offline
Registered User
 
Join Date: Mar 2005
Posts: 21
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.
Reply With Quote
  #2  
Old 08-17-2005, 11:28 AM
res's Avatar
res res is offline
VanDyke Project Manager
 
Join Date: Feb 2004
Location: VanDyke Software
Posts: 12
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
Reply With Quote
  #3  
Old 11-18-2008, 09:57 AM
matt131 matt131 is offline
Registered User
 
Join Date: Mar 2005
Posts: 21
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
Reply With Quote
  #4  
Old 11-18-2008, 05:09 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
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.
It seems like the last bullet point in #1 above is what might be leading to your quotes being stripped by cmd.exe.

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\*.*"
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 11-18-2008, 08:50 PM
matt131 matt131 is offline
Registered User
 
Join Date: Mar 2005
Posts: 21
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:
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.
Here's my original command
vsh -auth publickey -i c:\.ssh\id_dsa ourid@servername cmd /c dir "e:\share1\Data Feeds\AD\PROD\PAYROLL\FTP Pickup\*.*"

Thanks!
Matt
Reply With Quote
  #6  
Old 11-19-2008, 06:01 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
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?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 11-19-2008, 08:53 PM
matt131 matt131 is offline
Registered User
 
Join Date: Mar 2005
Posts: 21
Yes that works. Thanks for the help!
Matt
Reply With Quote
  #8  
Old 11-20-2008, 08:52 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi Matt,

I am glad that we could help you get this working.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 12:01 PM.