Showing posts with label plink. Show all posts
Showing posts with label plink. Show all posts

Sunday, November 7, 2010

How to run an application on resume from standby

or sleep mode...

Should work for Vista or Windows 7:
click the Start menu
type in Task Scheduler and run it
On the right, Create Task
Give it a name
(Run only when user is logged in is good and important)
click Triggers
Begin the task On an event
Log: System
Source: Power-Troubleshooter
Event ID: 1

if it's network related, you may want to
[x] Delay Task for 30 seconds

click Actions
add the parameters that will run your application on resume

click Conditions
If you're on a laptop/notebook, you may wish to uncheck
[x] Start the task only if the computer is on AC power

If it's network related, you'll want to check
[x] Start only if the following network connection is available

click Settings
if it's network related, you may want to check the "if task fails", restart every 1 minute up to 3 times.

click ok.
Test it

What would you want to use this for?

I'd use it to reconnect my ssh link if my laptop went to sleep, especially if I'm using it for tunneling.

Friday, May 7, 2010

Vista, Windows 7 doesn't have telnet - so get PuTTY

Get PuTTY
Here's how to use plink to test a port, like port 25:
plink -telnet your.domain.com -P 25
(Ctrl-C to quit)
or for interaction, PuTTY, in telnet mode.

Tuesday, March 9, 2010

Tunneling with plink (PuTTY)

This establishes a putty/ssh/plink connection from windows so a nonsecure application can be tunneled through it and then can be closed cleanly.

What is plink?
It's a command line version of PuTTY

What does tunneling mean?
In the case being presented here, any activity that will go to a port on the localhost will do what it should do on the remote site, but do it securely.

No, really, what does that mean?
Let's say you hear that telnet or mysql or ftp isn't that secure, because passwords are flying over the Internet in clear text. That is bad because that password or data isn't encrypted. Yes, I know about sftp, psftp, advanced mysql configuration, ssh, etc. Calm down a bit. If an application doesn't support secure communication, this is what ssh tunneling is about -- providing the secure "tunnel" to do those things.

How do I do it?
1) Make the link
open a command prompt
plink -ssh -L 21:localhost:21 remoteusername@remotedomain

2) use the link
open another command prompt
ftp localhost
and do what you want.

This only works if the remote site is running an ftp server on localhost. (huh?) It means, it only works if the site you want to connect to is listening for ftp connections on 127.0.0.1 (localhost). If it's listening for ftp connections on a local IP address, change localhost in the Plink connection to the local IP address of the REMOTE server. You will still on the local side connect to localhost.

plink -ssh -L 3306:localhost:3306 remoteusername@remotedomain (for use with mysql running on the remote domain. Again, if mysql is listening on a specific IP address, change localhost to the IP address that is configured for mysql.)

Don't forget... this is intended for the *client* applications connecting to the port on the local machine. It will be transparent to the application, but connect to the remote server. Oh, btw, this now establishes the connection securely.

Why would you do this in plink? Frankly, I don't know, except plink was designed for scripting. Most of the examples you'll find on the Internet say, "Usually Plink is not invoked directly by a user, but run automatically by another process. Therefore you typically do not want Plink to prompt you for a user name or a password." Plink is designed to run interactively with things like scp. You should check the furnished manual about that, especially how to put plink in the path, and I strongly suggest you create, save and use all the options (putty session) to minimize the interactivity.

Here's a fun script, though: WARNING! This creates and deletes a file called goawaynow on the remote server!

FIRST sample batch (scheduled?) to connect:
plink puttysessionname rm goawaynow
plink puttysessionname until (test -e goawaynow); do true; done; exit


SECOND run a command like this in another batch (scheduled) after you do the first:
mysqldump -h localhost dbname > dump.sql
plink puttysessionname touch goawaynow



(What does it do?)
First, understand that there is a lot of different customization that can be made to establish the plink connection. Don't be afraid to make changes. But you should necessarily run the two batches separately. The first connect batch removes the goawaynow file. The next line establishes the port forwarding and keeps the link open. The configuration is within the putty session, but you still need to append the until stuff. It basically says, "until goawaynow exists, do nothing, and after goawaynow exists, exit."

The second batch does whatever it needs with the connection, then the next line is supposed to create the goawaynow file, which closes the connection (because the infinite loop above is testing for it).

I'd also like to point to http://thinkhole.org/wp/2006/05/10/howto-secure-firefox-and-im-with-putty/ which has really good comments to make what I said above better. (-qTfNnL?)

Blog Archive