2

Am trying to connect to Linux server using VBA shell command. Am not able to execute multiple commands in it.

I have the below code in my VBA script, and the command file which has the list of commands

Private Sub main_function()

    cmd = "C:\putty.exe -t -ssh [email protected] -pw password -P 22 -m c:\cmd.txt"
    retval = Shell(cmd, vbMaximizedFocus)

End Sub

sudo to user
cat > filename.txt
sh shellfile.sh

I want to execute all the listed commands in the cmd.txt file but am not able to execute any command from the cmd.txt file, the code just logs in to the linux and exits.

4
  • Does that putty command line work if run directly in cmd ? Commented May 1, 2019 at 16:14
  • Indeed, your command-line won't work even standalone. This is not a Excel/VBA question. Commented May 1, 2019 at 16:39
  • Also, don't use PuTTY to automate commands. Use Plink (part of PuTTY package). Commented May 1, 2019 at 16:39
  • And then see, Executing (sudo) subcommands using Plink. Commented May 1, 2019 at 16:40

1 Answer 1

1

Create a batch file that works without using VBA then use the code you have above to simply call the batch file. Your issue is currently not related to VBA.

See this post on how to make a batch file to login to a server w/ Putty.

https://superuser.com/questions/1278434/create-a-batch-file-or-shortcut-to-putty-ssh-that-opens-a-session-and-runs-a-c

Eg: I just test and this worked fine

Private Sub main_function()

    cmd = "C:\test.cmd"
    retval = Shell(cmd, vbMaximizedFocus)

End Sub

Make sure your batch works when you double click it, then call via VBA.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.