How do I pass SSH automation

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.
LVL 2
seesaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lanboyoCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
arober11Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SSH / Telnet Software

From novice to tech pro — start learning today.