Solved

How do I pass SSH automation

Posted on 2009-07-14
3
1,058 Views
Last Modified: 2012-05-07
I am a newbie to scripting and so any help would be appreciated.

I am required to run a windows batch file which would open a putty session on a Linux box and run couple of script files.

Not really sure how to pass Linux commands through a Windows batch file

Any help appreciated.
0
Comment
Question by:seesa
3 Comments
 
LVL 10

Accepted Solution

by:
lanboyo earned 25 total points
ID: 24873802
You will have difficulty making a very complex script using putty in windows, just because putty does not have its own scripting language interface.

You could install cygwin on your workstation, and install and configure the expect scripting language. This wasily supports the automation of applications like secure shell, and it does so with much more reliability and power. You would be writing an expect script, which is much like a shell script that would call the cygwin ssh program and do what ever you need done.

Here is a pretty good example of someone using expect to call ssh. Keep in mind that you dont need to be running linux/unix, the free cygwin application tools can install aunix like environment on your workstation that will be suitable for your needs.

To do it in the way you have asked is possible however...

You would need to configure putty to log into all the devices without a password...

http://www.howtoforge.com/ssh_key_based_logins_putty

Then you would need to build a session for each server, and put the commands that you want to run in the  Remote command box in the ssh category. Separate multiple commands with semicolons. If you need the output, configure a log file for each session. then call the sessions from your batch file, specifying the individual sessions like this:

putty.exe -load "session name"

http://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter3.html

I recommend installing expect  though.









0
 
LVL 26

Assisted Solution

by:arober11
arober11 earned 25 total points
ID: 24998651
Hi

If it's the odd command havel a look at the Putty "plink" command, read the Putty Help.

If you want to go further / have a more secure mechanism them, work out what commands you require to be executed on the remote machine, generate a set of public / private DSA or RSA key pairs for each command to be run e.g. Use PuTTYgen, and note / copy the displayed public key into a text editor, and save the private key with a suitable name e.g.  server1_run_cmd1.ppk (The pass phrase is optional).

Next prefix each public key with the single command / set of commands you wish run on connection e.g.

command="/usr/local/some-dir/..../somecommand.sh xxxxxxxxx",no-pty,no-port-forwarding ssh-rsa AAAA..xxxxxxxxxxxxxxxxxxxx.yQ== Run_Command_1
command="//usr/local/some-dir/..../somecommand.sh xxxxxxxxx",no-pty,no-port-forwarding ssh-rsa AAAA..yyyyyyyyyyyyyyyyyyyy..xQ== Run_Command_2

Open an ssh connection to the server, as a users with sufficient privileged to perform the commands. Then append your new public keys to the $HOME./ssh/authorized_keys file.

Back on the PC create a series of ssh sessions, to the host, using the privileged user and the applicable new private key file.  Save with a suitable name, including the user, server name and command.

Then each time you open the applicable saved session, either in putty, or by a command line plink call e.g. "C:\Progra~1\Putty\plink.exe myUser_server1_run1"   the specified command will be executed on the remote server, and you will revieve the output you can do whatever you want with in a batch script.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

We all know how boring and exhausting it is to transfer huge web projects developed locally to a webserver simply via FTP. The File Transfer Protocol is a really nice solution if you need to transfer small amounts of files, but if you're plannin…
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now