Putty output trigers vba script action - vba

some context first, Im using vba to automate putty into loging into many host with ssh retrieve info and save it.
I can do that currently, however, each time I execute a command, I have to set some waiting time just so the command is correctly executed and then I can execute next command. Is there any way to feeback from Putty output into vba so vba knows when to send next command? that would reduce execution time
sub retrievinginfo()
Lines to ssh open putty to X host
SendKeys "first command for putty session"
Application.wait Now+Timeserial(0,0,"estimated seconds") '<---- here the problem
SendKeys "second command for putty session"
end

Do not use PuTTY. That's a GUI application, not intended for automation.
Use Plink from PuTTY package. Plink is a console application intended for automation. It uses standard input/output, so that you do not have to hack sending of command by simulating keystokes.
Why do you even execute command this way? Why don't you specify a script file using -m switch?
See Automating command/script execution using PuTTY.

Related

Automated input *through* Putty or SSH, not running or scripting on host

I have a scenario where I need to run a shell command to a unix based appliance frequently from windows (linux could be an option). Because it's an appliance, it doesn't have the full breadth of capabilities that, say, Linux would have. I am using PuTTY to do this (I could use SSH from linux as well) which, I assume will work if I do something like "putty.exe -ssh -2 -l username -pw password -m c:remote.cmd hostname", but that only gets the command started. A user has to manually input the password - it cannot be done through command line, and I'm unaware of the capability to grab input from a file.
Is there a way by which I can automate this through the Putty?. By that I mean, I would like to send the input to the command in Putty like I was there, which would thereby be sent it to the appliance, not run a local script.
Thanks all in advance. Your input is greatly appreciated as we all may learn a little something.
Victor
For automation, use Plink (from PuTTY package). It's a console equivalent of PuTTY. So it supports input redirection:
(
echo password
echo some other input if needed
) | plink username#example.com command

How to run sql queries on backend instead of using nohup on linux.

I am looking for a solution for the problem. I am trying to execute one procedure in sqlplus by logging into linux server by using putty.
is there any possibility to run the procedure back end even if i close the putty session when running(in between) the procedure..? Instead of Nohup mode.
I heard, it is possible, because i heard one procedure ran for six days but it was not kept in nohup mode. They directly executed the procedure in sqlplus prompt and they directly closed the putty session, Still it is executing.
does server will take care of procedure....?
Thanks in advance
Siva
There are 2 ways to execute any script on oracle in background. First create a script name test.sql.
You have to use '&' which will put it in the background.
sqlplus username/password #test.sql &
execute using nohup command
nohup sqlplus username/password #test.sql &
And you can close putty session.

How to input password on command prompt using VBA?

I've created a procedure on VBA (Excel) that restarts services on remote servers calling the command prompt and executing the "runas" command. I need to enter the command on the servers as administrator. So far it works fine but I don't want to have to type my password for each I want to run the command in. I know how I can automate the task using VBA and the Excel. What I don't know is how could I input my password on the command prompt using VBA?
Can anybody help me?
Thanks.
I've had all sorts of issues trying to convince runas to let me specify passwords from a program.
In the end, I tossed it and downloaded psexec from the Microsoft Windows Sysinternals site, which has other good stuff as well.
While many see this as a tool running remote programs, it can also be used quite happily to run local stuff under a different user name while allowing you to specify the password as a command-line argument, such as:
psexec -d -u USER -p PWD -w WORKDIR EXECUTABLE
You should be able to create a textbox control in VBA with the input mask set to password, this will allow you to enter the password in a non-viewable fashion.
Then you can just construct the psexec command and execute it from VBA, without having to worry about injecting the password into the process running runas.

Run a program after ssh session terminates

I am trying to run a long java program on a server via ssh, I tried using:
command &
Which would work fine on my local machine, but when I terminate my local ssh connection, the program also terminates. Is there a way I can run this and have the output go to some text file so I can login and check completion at a later date?
You can use nohup
nohup command &

Remotely control a graphical vb.net program through a command prompt

I have created a VB.NET program using windows forms. The program runs on a remote PC and displays information on a screen. The computer does not even have a mouse or keyboard connected to it. The program shows the information based on the file that is loaded.
I want to be able to change this file remotely to another file that is already on the remote PC. I can't use a graphical remote desktop client as we have very limited bandwidth.
So, my idea is to change the file using the command prompt (I think I'll need something like SSH). I'm not sure how to do this. Should I use something like this and load DosModule first:
Module DOSModule
Public Sub Main()
Console.Write("First, start with Command Prompt processing ...")
Dim myWinForm As New WinForm
Application.Run(myWinForm)
End Sub
End Module
How would I then read commands that is send to the program? I also only want one instance of the program running.
Thanks
You have 2 options. The first is a custom program that WILL require some network programming, like it or not. I would suggest creating either a Command-Line batch file or else a PowerShell script, then creating a program to transfer the script to the remote computer and execute the script.
The second option and the one better suited for you would be to download an SSH server. An SSH server will essentially open a command window and pipe the input and output over to a telnet client running on your machine. If you are running a version of Windows Server, an SSH server comes with Windows Server. Otherwise, you can download one for free here: http://www.freesshd.com/
Once you install the SSH server, you simply use telnet, from a command prompt, to link up with your remote SSH server