Vidhyasaghar
Vidhyasaghar

Reputation: 45

How to pass multiple commands to Shell function in VBA using putty?

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.

Upvotes: 2

Views: 1538

Answers (1)

FreeSoftwareServers
FreeSoftwareServers

Reputation: 2801

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.

Upvotes: 1

Related Questions