IT@KMITL Forums

IT@KMITL Knowledge => ไอทีนอกกะลา => Topic started by: thanachit on August 29, 2008, 08:21:21 AM

Title: [Help me!] > Execute Unix shell command as root with Java?
Post by: thanachit on August 29, 2008, 08:21:21 AM
ปัญหาของผม คือ ผมต้องการจะสร้าง java application
คล้าย ssh client คือ มีส่วนของการ authenticate
รับ hostname/ip username passwd port จาก user
แล้ว connect ไปยัง remote unix server

เพื่อ ทำการ manage unix server ผ่าน java application
ยกตัวอย่างเช่น shutdown เครื่อง ด้วย shutdown -h now
manage directory/file (cp , mv , rm )

สิ่งที่ผมต้องการจะถามคือ
1. java application ที่ไม่ได้อยู่บนเครื่อง server จะ connect
ไป unix server เพื่อ execute shell command , shell script ได้ไหม
2. java application จะสามารถเป็น ssh client ได้อย่างไร
ต้องเขียน Program ประเภท socket ไหม? หรือว่ามี Library
ให้เรียกใช้อยู่แล้ว
3. มีวิธีอื่นที่จะ manage unix server แบบที่ต้องทำการ authenticate
ที่ shell ก่อน เช่น บางคำสั่งจะ execute ได้ ต้องใช้ account root
4. runtime.exec(); ใช้ได้เฉพาะในกรณีที่ java application นั่นอยู่บน server หรือเปล่า
และเวลามัน execute shell มันจะ execute ด้วย permission ของใครครับ
ของเจ้าของ java application นั้นหรือเปล่า

ถ้าผมถามแบบงง ๆ ก็ขอโทษด้วยนะครับ
Title: Re: [Help me!] > Execute Unix shell command as root with Java?
Post by: ▒▒▒ Kivi .ılı..ılı. 陳 鋼 石 ▒▒▒ on August 29, 2008, 08:56:40 AM
ไม่รู้ว่าจะตรงกับคำถามที่ต้องการป่าวนะ

http://www.jscape.com/articles/ssh_using_java.html

http://www.javassh.org/space/Installing+as+a+local+Telnet/SSH+Application
Title: Re: [Help me!] > Execute Unix shell command as root with Java?
Post by: thanachit on August 29, 2008, 11:59:19 AM
ขอบคุณมากครับ
เป็นประโยชน์จริงๆๆ
Title: Re: [Help me!] > Execute Unix shell command as root with Java?
Post by: WingGundamZeroCustom.co.th on August 29, 2008, 01:12:47 PM
ถ้าให้คิดหลักการก็คงประมาณใช้ library connect เข้าไปยัง ssh แล้วก็ execute คำสั่งตามที่ต้องการ เหมือนเป็น GUI ครอบตัว command line อีกทีนึงหรือเปล่า
Title: Re: [Help me!] > Execute Unix shell command as root with Java?
Post by: thanachit on August 30, 2008, 01:10:03 AM
ถูกครับ
Title: Re: [Help me!] > Execute Unix shell command as root with Java?
Post by: ^DoppLer 2 SulPhaTe^ on August 30, 2008, 11:06:04 AM
ทำไมผมอ่านแล้วรู้สึกโง่ขึ้นมาทันตา
Title: Re: [Help me!] > Execute Unix shell command as root with Java?
Post by: thanachit on August 30, 2008, 11:15:29 AM
คิดมาก