Solved

plink => su: must be run from a terminal

Posted on 2013-06-05
8
3,360 Views
Last Modified: 2013-06-06
Hello,

I need to reboot a linux server from Windows.

My script doesn't work.

reboot.bat
echo n | putty -ssh -t -noagent  %LOGIN%@%IP% -pw %PASSWORD% -m localshell.sh

Open in new window

localshell.sh

#!/bin/bash 
echo 123456 | su - reboot
ping 127.0.0.1

Open in new window


I can't change linux parameters.
PermitRootLogin No
My user isn't sudoers

i have root password & user password

Thanks for your help !
0
Comment
Question by:PepperRed
[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
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39225245
It's

su -  -c reboot

ping ... in your script is useless, it will not be processed after "reboot"

What should these "echo n"  and "echo 123456" be good for?

Finally. I assume you meant to write "plink" instead of "putty" in the code you posted?
0
 
LVL 21

Expert Comment

by:Mazdajai
ID: 39225721
I don't think you can pass in plain text for password with su.

Any reason why you are not using sudoer? You can pass in a password argument with plink if you have sudoer setup. One line in batch. For example -

plink -pw bad user@server sudo /usr/bin/reboot
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39227257
I assume that the "echo 123456" in localshell.sh is for the root password.  Couple of problems with that - su doesn't read the password from stdin, and it can't be run in a pipeline like that.

You need to use expect:
expect <<EOF
spawn su - -c reboot
expect sword
send "123456\r"
expect eof
EOF

Open in new window

0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:PepperRed
ID: 39227282
ping command is just to see the error "su: must be run from a terminal"

With plink or putty in my script, the error is the same.

Don't use sudoer is my company policy.

I try su - -c reboot but : "su: must be run from a terminal"

As Mazdajai say it, i think i can't pass in plain text for password with su.

Do you know an other method to reboot a linux from Windows with my constraints

Thanks
0
 
LVL 21

Expert Comment

by:Mazdajai
ID: 39227325
Passing plaintext password with su is the problem. I don't see this is possibile with your contriant.
0
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 200 total points
ID: 39227358
This is the classic problem that expect was designed to solve. There is a version of expect for Windows, but it's not free and I don't remember the URL - Google will find it.
However - and this is free - expect is supported under Cygwin.
So if you install Cygwin and be sure to include expect (not part of the minimal install) then you can write an expect script to do what you want. Post back if you need help in writing the script.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39227395
Back to the original issue ("su: must be run from a terminal"):

The "-t" flag of plink (not putty!) should take care of allocating a pseudo tty.

Apart from all the other good suggestions above: "su - -c ..." should work and ask you for a password if you really used "plink" and its "-t" flag.
Try without "echo 123456 | "  (If you're still interested, that is).
0
 

Author Comment

by:PepperRed
ID: 39227803
I try yours differents solutions with no success and finally i have success with expect script.

My expect script which i launch from a batch :

RebootLinux.exp

expect <<EOF
spawn "C:\\Program Files\\PuTTY\\plink.exe" -ssh -t -noagent  test@192.168.12.345 -pw password

expect sword
send "su -\r"
       expect {
           "Password: " {send "123456\r"}
       }
expect sword
send "reboot\r"

expect eof

Open in new window


Thanks all
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

695 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