หลายครั้งที่ผม remote ไปรัน command ที่ server เพราะเป็น process ที่สำคัญจริงยกตัวอย่าง ส่ง enews หมื่นฉบับ, download backup จากอีก server

จ๊าก!…หลังจาก run command ไปแล้วต้องรอจนมันทำงานเสร็จ
ในระหว่างนี้ผมจะต้องนั่งอยู่หน้าจอตลอดเลยหรือนี่ แล้วถ้ามันใช้เวลา 3 ชั่วโมงไม่ต้องหาคนมาเปลี่ยนผลัดเลยเหรอ 555+

เอาน่าทนหน่อย 90% แล้ว…!!เจี๊ยก!!… เครื่องแฮงค์ เน็ตหลุด พี่น้องครับถ้านี่ไม่ใช่แค่การสมมุติผมคงทุบ router ไปแล้วเพราะรอมาพักใหญ่

เทคนิคที่จะ run command โดยไม่ต้องคอยดูจนกว่า process จะจบก็คือการใช้ nohup

nohup คืออะไร ?
เอาแบบไม่ทฤษฎีอะไรมากก็คือ รัน command นี้จนกว่าจะจบนั่นเอง

nohup is a Unix command that is used to run another command while suppressing the action of the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out. It is most often used to run commands in the background as daemons. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected.

วิธีใช้

nohup wget http://www.unzeen.com/xxx.tar.gz &

แค่เพิ่ม nohup เข้าไปข้างหน้า command ที่เราจะ run ครับโดยเพิ่ม & เข้าไปเพื่อให้ run เป็น background
หลังจากใช้ nohup แล้วเราสามารถ logout ได้โดยที่ process จะยังทำงานต่อไปเรื่อยๆจนกว่าจะเสร็จครับ

ปล. เวลาที่เหลือเอาไปทำไรดี :)

This post has No comment. Add your own.

Leave a Reply