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

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Unable to execute the unix commands using putty ssh connection


    Hi All,

    I'm trying to execute few unix commands from my script and i'm facing issue when i tried to use putty ssh connection.

    After making a connection, i tried to run set of commands in my Command.cmd file, i'm able to login into the putty server, but the commands are not getting executed. It immediately closes the session.

    Code to connect to putty and execute Command.cmd

    Set objShell = CreateObject( "WScript.Shell" )
    objShell.Run("C:\Softwares\Putty\putty.exe -ssh user@server -pw Password")
    objShell.Run("C:\Users\sg0210523\Desktop\Command.cmd")
    Set objShell = Nothing



    Even i tried to execute the command with -m in connection string, but same issue.

    objShell.Run("C:\Softwares\Putty\putty.exe -ssh user@server -pw qaz123wsx -m C:\Users\sg0210523\Desktop\Command.cmd")

    Command.cmd has following commands.
    cd /tmp
    rm abcd.txt
    put "C:\Users\su234533\Desktop\abcd.txt"
    cd /apps/inventory/int/deploy/invt-web/invt-tomcat-instance-invt-5.06.004-web-ELISA-int/logs
    tail ssci-tomcat-instance.log -n 1000
    PATHU=$(ps -ef|grep -E web-EY | sed -n "s@.*\(/apps.*logs/\).*@\1@p")
    cd $PATHU


    I tried with WinSCP also, but WiSCP doesn't support tail commands and in Command.cmd i have ps command also.

    I have searched and found there is option using plink.exe, but is there anyway i can execute the command through putty itself.

    Even option to execute each line through script is also fine.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,451
    Rep Power
    1751
    Not sure about WSH, but would not the Set objShell = Nothing cause the object (your shell session) to be 'destroyed', hence the 'immediate' close of the session.

    Anyway, a quick look at the putty help file suggests that what you want to be using may well be the plink command.
    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
    Jan 2014
    Posts
    5
    Rep Power
    0
    Simon,

    Thanks for your reply.

    objShell = Nothing is not causing the application to close. Initially I have the following code with just login option and command.cmd parameter, that time it was not closing the session.

    Set objShell = CreateObject( "WScript.Shell" )
    objShell.Run("C:\Softwares\Putty\putty.exe -D 22 -ssh user@server -pw password")
    Set objShell = Nothing


    I tried a different parameter in calling the command and now its working.

    Set objShell = CreateObject( "WScript.Shell" )
    objShell.Run("C:\Softwares\Putty\putty.exe -ssh -2 -l username-pw password -m C:\Users\username\Desktop\CommandOne.txt servername")
    Set objShell = Nothing


    I got this way of parameter from a website, still not sure whats the difference from my old method.

    Thanks,
    Ramkumar

    Originally Posted by SimonJM
    Not sure about WSH, but would not the Set objShell = Nothing cause the object (your shell session) to be 'destroyed', hence the 'immediate' close of the session.

    Anyway, a quick look at the putty help file suggests that what you want to be using may well be the plink command.

IMN logo majestic logo threadwatch logo seochat tools logo