Shell robot


Posted in:

เคยบ้างมั้ยที่ต้องใช้ shell ทำอะไรหลายๆ อย่าง
เคยบ้างมั้ยที่ แต่ละอย่าง ที่จะให้ shell ทำต้องกรอกอะไรบางอย่าง
นี่แหละปัญหาของผม แต่ที่ผมจะให้ shell ทำเป็นแค่คำสั่ง scp ที่ส่ง password ไปยัง server ซึ่งถ้าปกติไม่อยากพิมพ์ password บ่อยๆ ก็สามารถ gen key แล้วส่ง public key ไปยัง server ได้ แต่เมื่อย้าย server ที ก็ต้อง gen key ใหม่ ส่ง key ใหม่ โอ้ อะไรมันช่างยุ่งยากฉะนี้ สุดท้ายก็เลยถามพี่ที่ทำงานซะเลยว่ามีวิธีมั้ย แล้วก็ได้ตัวอย่าง shell script เล็กๆ มาอันนึง ตาม code ด้านล่าง


#!/usr/bin/expect

set password "password"

spawn scp user@host:~/dir/file .

expect "password:"
send "$password\r"

spawn scp user@host2:~/dir/file .

expect "password:"
send "$password\r"

spawn scp user@host3:~/dir/file .

expect "password:"
send "$password\r"

ปอลอ. จริงๆ เขียนไว้ในบล๊อกไปรอบแล้ว แต่ไม่รู้จะเอา feed ตาม tag มายังไง เลยอาศัยวิธี copy แปะเอาละกัน ง่ายดี แหะๆ

thanks

thanks หลาย ไอ้น้อง love

เฮ้ย

เฮ้ย ไอ้น้องลองดูแล้วทำไมมันไม่กรอก password ให้ฟะเนี่ย ไอ้ตรง set password เนี่ย ไอ้ข้างใน "" ให้กรอก password จริงๆลงไปใช่ป่ะ หรือว่าไม่ใช่อ่ะ

ไช่แล้ว

ไช่แล้ว แต่บน ubuntu น่าจะเป็น export "password" แทนแฮะ แหะๆ พอดีตอนใช้ ใช้บน freebsd อ่ะ

ชอบโอเพ่น

ชอบโอเพ่นซอสต์ แต่ ...ผม ทำไม่ค่อยเป็น อยากเป็นจังเลย

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <i> <center> <span> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <br> <dt> <dd> <object> <embed> <hr> <img> <blockquote> <b> <u> <del> <div> <p> <table> <tr> <td> <font>

More information about formatting options