#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Ssh to remote server through windows batch file


    Hi,
    I've created a batch file that logs into a remote unix server using plink.
    plink -ssh -pw xxx user @ server1 -m cmd.txt

    From the server1 I have to ssh into another unix server. Now I believe that the SSH Public Key Based Authentication is already setup because whenever I login manually I just give the ssh server command and I'm able to login to server 2 without the need for any password. So I wrote a script in server1 that basically just contains the ssh command for server 2. But when I tried executing the script through my .bat(through the cmd.txt file mentioned above) file I got the error "Pseudo-terminal will not be allocated because stdin is not a terminal."
    Instead of the above script I tried running some dummy script on server1 and it worked. Can anyone please help me out here.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    Try adding the -n parameter to your ssh call in the sctipt on Server1.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0
    It's working after I added the -t parameter to the ssh call. I'm now facing a new issue though. I get (^H) when backspace is pressed and can see some strange special characters in place of blank space in a few places. Somewhere I read using [ -t 0 ] && stty erase ^H would solve my problem but it didn't. Not sure if I'm using it correctly.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    I have to admit to not being sure what the [-t 0 ] means (ok, just looked and it is testing if stdin (fd 0) is open and is a terminal).
    So, what we are doing is checking to see if we are on a terminal and if so setting the the erase key sequence to Ctrl-H (^H) - this sort of thing is usually done in the .profile file. Not sure why you'd be having this problem when running a script ... surely no key-pressing is going on?
    Usually whenever I have done this I have set the backspace key to do the 'erase function' (using stty erase ^? or stty erase <backspace key>) as I find that easier. It's been a while but it was usually required due to either the shell default or the ssh/telnet client intercepting the backspace key and converting it to Ctrl-H.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo