如何使用sudo访问运行远程脚本

时间:2016-05-17 07:25:07

标签: expect

我正在尝试运行一个需要以sudo身份运行的远程脚本,但它无法以sudo身份运行脚本。我的方法是正确的做sudo?请帮忙..谢谢。

from kombu import Connection, Exchange, Queue

media_exchange = Exchange('media', type='topic', durable=False)
video_queue = Queue('video2', exchange=media_exchange, routing_key='video')

def process_media(body, message):
    print(body)
    #message.ack()

with Connection('amqp://guest:guest@localhost//') as conn:
    with conn.Consumer(video_queue, callbacks=[process_media]) as consumer:
        # Process messages and handle events on all channels
        while True:
            conn.drain_events()

1 个答案:

答案 0 :(得分:0)

试试这个: -

#!/usr/bin/expect
set timeout -1
spawn -noecho bash -c "ssh user@host \"sudo su -c 'your_command' - sudo_user\""

expect {
    -re ".*assword:"{
        send "password\r"
        exp_continue
    } eof {
        wait
    }
}

希望它有所帮助。!!!