Putty trough command line problem

Where Penguins and Daemons chill together in the warmth of the Sun.

Moderators: SecretSquirrel, notfred

Putty trough command line problem

Postposted on Mon Jun 13, 2011 8:50 am

Hi there,

At my work, I usually use a simple command trough Putty to restart a server for several reasons :

sudo /sbin/allowed user kill servername

This command basically calls the command "kill servername" from another user.


Now the problem is, I want run Putty trough a windows command line to be able to run a remote task by Hudson, that will call a .bat file etc...

So after some reading, I realised Putty offers a program called "Plink", that allows to use Putty directly into the command line. So i did a .bat file that

does this :

C:
cd C:\programs\Putty
plink -l userHERE -pw passwordHERE -m commands.txt server


This command is really simple, it uses the cmd.exe to connect trough Putty, on "server", with the user "userHERE" and the password "passwordHERE".

This part works great, I actually see the Putty interface built in the cmd.exe, but the "-m commands.txt" means that I wanna run all the commands in

the file trough Putty.


This my the content of commands.txt

sudo /sbin/allowed user kill servername


Problem is :

"kill servername" ask for a confirmation if I really wanna kill the server, I see the question pop in the command line, but i can't type nothing !

Even if I do it directly with Putty instead of Plink, the program will run in a new Putty window, but I am not able to answer to confirmation, even If

I add the command "yes" in commands.txt, it won't reads any commands after the "sudo /sbin/allowed user kill servername" command...Even if I just

try a standart "echo test", nothing will happen since it's jammed on the confirmation....


Anyone can help ?

Thanks,

Simon.
Identity461
Gerbil In Training
 
Posts: 2
Joined: Mon Jun 13, 2011 8:36 am

Re: Putty trough command line problem

Postposted on Mon Jun 13, 2011 8:59 am

What program is producing the prompt? Is it PuTTY, kill, sudo, or something else (the 'allowed', maybe, whatever that is)?

Find that out, and then find out whether that program has a '-f' or '-y' or similar option to make it proceed without prompting. It probably does.

The most likely candidate is kill, but my version of kill doesn't produce any prompts, and certainly doesn't have any such option.

The next most likely candidate is probably sudo, but I don't know much about that since I prefer 'su -c' anyway.
Core i7 990X 3.47GHz | 24GB RAM | 512GB SSD (256GB RAID-1) + 8TB (6TB RAID-5) | Radeon HD 6870 | Dell 3008WFP | Obsidian 800D
The Wanderer
Gerbil
 
Posts: 91
Joined: Tue Apr 22, 2003 12:20 pm
Location: Southern Maryland

Re: Putty trough command line problem

Postposted on Mon Jun 13, 2011 9:16 am

Thank you for the answer but I found out by luck !

I "think" that the prompt was coming from the "kill" command.

However, I read somewhere to add "-ssh -t" to avoid the "no ptty allocation", a problem that I saw before, while working with

my script. So i started by adding the "-t" argument, that disable the ptty allocation, and found out that I was actually able to

type the confirmation manually!


BUT, i could still not script an automatic confirmation by writing something like "echo yes"...

So I added the "-ssh" argument, and everything works!

The "echo yes" is executed automaticly after the sudo command and the confirmation works.


I am not 100% sure of what I did exactly haha but whatever...

Thanks for the quick answer!
Identity461
Gerbil In Training
 
Posts: 2
Joined: Mon Jun 13, 2011 8:36 am

Re: Putty trough command line problem

Postposted on Mon Jun 13, 2011 9:20 am

I would imagine the confirmation prompt is coming from the service you're restarting. Have you tried "kill −9 servername" instead?
kyboshed
Gerbil
Gold subscriber
 
 
Posts: 68
Joined: Wed Aug 21, 2002 5:48 am
Location: Newcastle


Return to Linux, Unix, and Assorted Madness

Who is online

Users browsing this forum: No registered users and 2 guests