Windows Batch file for checking ssh tunnel alive - windows

Using putty (windows version), I have established a SSH tunnel for accessing MySQL. I can automatically start the session by putty -load "sessionname" -pw 1234
Using the windows task scheduler, I'd like to periodically execute a batch file which checks if the connection is still alive - and if not, the tunnel should be restarted automatically.
Any idea how to achieve that?
brgds, janosh.

Related

Establish SSH Tunnel as background windows service

I would like to create a background service on Windows 11 for a persistent SSH Tunnel to a remote Linux machine using OpenSSH.
I have setup the SSH config file as such that you can run the command
ssh MyRemoteHost
and the connection will be successfully made.
However, when I try to create a service with
PS New-Service -Name "MyRemoteConnection" -BinaryPathName "C:\Windows\system32\OpenSSH\ssh.exe MyRemoteHost"
the service will be created but I canĀ“t start it. I also tried to create a .BAT file with the SSH command and run this as a service with the same result.
Any help with this would be greatly appreciated.

Keeping the processes running even after exiting SSH to a windows machine

I am connecting to a remote machine through SSH client. Both SSH server and client are on windows OS.
I usually run tomcat 7 from such ssh session. But, as soon as I end the session, tomcat server shuts down as well. I run tomcat7.exe directly from its installation folder.
I have used &! at the end of the command to ensure that the process doesn't get attached to the terminal. But, couldn't achieve the desired result.
Kindly suggest how to detach such processes from the ssh client.
tomcat7.exe start and tomcat7.exe stop
these two commands ensure that tomcat starts as a service. Worked like a charm for me.

How to persist Enable-PSRemoting in powershell

I am able to enable remoting using below command
"Enable-PSRemoting -Force".
But after restarting machine, enable remoting is going off and need to enable it again using above command.
Is there any way to persist PSRemoting enable?
Actual my requirement contains
Connecting remote machine
Executing few commands
Restarting remote machine
connect remote machine again
Execute few more commands.
The above all steps needs to be done in single script.
I am not able to connect my remote machine after restart as its settings(Enable-remoting) is going off.

Exec a program on client runs a programm on server

First of all I have spent over 4 hours researching this topic..
So I have a Windows 2008 r2 root server at the moment. I connect to it via Remote Desktop.
Now I want to write a program that runs batch files on the server but the program is at client side, I have tried to setup an SSH server on my Windows server with Freesshd.
That seems to work but the programs are not shown. (In Taskmanager are they)
Is there way (prefer SSH) to let them show normally?
The goal is to restart programs (Gameservers).
My Program will work so: if I press restart server it will connect (if SSH) via Putty to the server to exec the batch file.
Or will start another program with parameters something like this:
Clientprogramm -ip 95.25.115.** -user Administrator -p xxxxxx C:\gameserverdir\start.bat
Simple and fine. I have done that already for Linux and there it isn't that hard.
So if you have an idea that can help me would be nice to know.
Both system are Windows!
If you are using SSH, the tool you need is plink. It's putty for command line.
Or, as indicated in comments, you can use psexec, or powershell, or vbscript, or .... BUT started programs are only "visible" in the same session from where they were started.

"plink.exe" hangs on Windows Server 2008 R2, creates process "conhost.exe"

I am new to the whole Windows world. I have downloaded plink.exe from Putty's website. I am executing a plink command from the Windows Server 2008 R2(64 bit) which would execute a shell script in a Linux box.
The plink command is executed from a .dtsx package which is running as a daemon job on the Windows Server. I have accepted the host key into the registry for the Linux box using Putty and I can see it in the registry.
The command executes when I RDP into the server but does not when I am not logged in. It hangs and creates a "conhost.exe" process which stays there. I can see the "plink.exe" and "conhost.exe" in the task manager on the server.
Here is the kind of command I am running.
plink.exe user#SERVERNAME -pw password ./script_name.sh param_1 param_2 param_3
Has anybody faced/or is facing any problem like this?

Resources