Solved

How do I pass SSH automation

Posted on 2009-07-14
3
1,115 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Secure Shell (SSH) is a network protocol for secure data communication, mainly used to administer remote Unix / Linux servers via command line. But it also allows the user to open a secure tunnel between a client and a server where he can send any k…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 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