Skip to content

xcall distributed command execution script

xcall is a shell script designed to execute commands across a cluster of distributed nodes.^[600-developer__linux__centos7-command.md] By utilizing SSH, the script runs the specified command on the local machine first, and then iterates through a predefined list of remote hosts to execute the same instruction on each node.^[600-developer__linux__centos7-command.md]

This tool is commonly used in cluster management to perform administrative tasks—such as checking process status (jps) or listing files—simultaneously on all nodes without requiring manual login to each server.^[600-developer__linux__centos7-command.md]

Prerequisites

Before using xcall, the environment must be configured to allow passwordless SSH access between the control node and the target nodes.^[600-developer__linux__centos7-command.md] This typically involves generating key pairs and distributing the public key to the authorized_keys file on remote hosts.

Additionally, the script relies on a specific hostname pattern. In the provided source, the script iterates through hosts named hadoop101, hadoop102, and hadoop103.^[600-developer__linux__centos7-command.md]

Usage

The script accepts the command to be executed as input arguments.

  • Syntax: xcall.sh [command]
  • Example: xcall.sh ls^[600-developer__linux__centos7-command.md]
  • Example: xcall.sh /opt/jdk1.8.0_181/bin/jps^[600-developer__linux__centos7-command.md]

Script Logic

The script operates as follows^[600-developer__linux__centos7-command.md]:

  1. Parameter Check: It first checks if any arguments were passed (pcount=$#). If no arguments are provided, it prints "no args" and exits.^[600-developer__linux__centos7-command.md]
  2. Local Execution: It prints a header for localhost and executes the command ($@) on the local machine.^[600-developer__linux__centos7-command.md]
  3. Remote Iteration: It loops through a range of host numbers (e.g., 101 to 103). For each iteration, it constructs the hostname (e.g., hadoop101), prints a header indicating the target host, and uses ssh to execute the command on that remote host.^[600-developer__linux__centos7-command.md]

Sources

  • 600-developer__linux__centos7-command.md