Skip to content

Execute Command#

Execute Command node ใช้สำหรับรัน shell command บนเครื่องที่รัน n8n อยู่

Which shell runs the command?

node นี้จะรัน command ใน shell หลักของเครื่องที่รัน n8n เช่น cmd บน Windows หรือ zsh บน macOS

ถ้าคุณรัน n8n ด้วย Docker command จะถูกรันใน container ของ n8n ไม่ใช่บน Docker host

Not available on Cloud

node นี้ไม่สามารถใช้ได้บน n8n Cloud

Node parameters#

ตั้งค่า node นี้ด้วย parameter ต่อไปนี้

Execute Once#

เลือกว่าจะให้ node นี้รันแค่ครั้งเดียว (เปิด) หรือรันตามจำนวน item ที่รับเข้ามา (ปิด)

Command#

ใส่ command ที่ต้องการรันบนเครื่องที่รัน n8n ดูตัวอย่างการรัน multiple commands และ cURL commands ด้านล่าง

Run multiple commands#

มี 2 วิธีในการรันหลาย command ใน Execute Command node เดียว:

  • ใส่แต่ละ command ในบรรทัดเดียวกันโดยคั่นด้วย && เช่น จะเปลี่ยน directory (cd) แล้ว list ไฟล์ (ls) ก็ใช้ && ได้

    1
    cd bin && ls
    
  • ใส่แต่ละ command ในบรรทัดใหม่ เช่น เขียน ls ต่อจาก cd ในบรรทัดถัดไป

    1
    2
    cd bin
    ls
    

Run cURL command#

คุณสามารถใช้ HTTP Request node เพื่อส่ง cURL request ได้เช่นกัน

ถ้าต้องการรัน curl command ใน Execute Command node ต้อง build Docker image ใหม่จาก image n8n เดิม โดย image n8n ปกติใช้ Alpine Linux ต้องติดตั้ง curl เพิ่ม

  1. สร้างไฟล์ชื่อ Dockerfile
  2. ใส่โค้ดนี้ใน Dockerfile

    1
    2
    3
    4
    FROM docker.n8n.io/n8nio/n8n
    USER root
    RUN apk --update add curl
    USER node
    
  3. ในโฟลเดอร์เดียวกัน ให้รันคำสั่งนี้เพื่อ build Docker image

    1
    docker build -t n8n-curl
    
  4. เปลี่ยน Docker image ที่ใช้รัน n8n เดิม เช่น จาก docker.n8n.io/n8nio/n8n เป็น n8n-curl

  5. รัน Docker image ใหม่ที่สร้างไว้ จะสามารถใช้ ssh ผ่าน Execute Command Node ได้แล้ว

Templates and examples#

Scrape and store data from multiple website pages

by Miquel Colomer

View template details
Git backup of workflows and credentials

by Allan Daemon

View template details
Track changes of product prices

by sthosstudio

View template details
Browse Execute Command integration templates, or search all templates

Common issues#

สำหรับคำถามหรือปัญหาที่เจอบ่อยและแนวทางแก้ไข ดูที่ Common Issues