parallel-ssh:
[ you need install pssh for parallel-ssh ]
Following are few of the features:
1. In the following command you are passing user@host:port and the ssh option after -x "for example the ssh key" and later the command. It will run the command on the remote system and put the output on the screen:
$ parallel-ssh -i -H "user@server:port" -x "-i key" "command"
Following is the command example if you have to pass the key, port and user parameter:
$ parallel-ssh -i -h <FileWithServersList> -x "-i key -p port" -l ubuntu "command"
Run a long command without timing out:
pssh -i -h hosts.txt -t 0 sleep 10000
parallel-ssh --help
Usage: parallel-ssh [OPTIONS] command [...]
Options:
--help show this help message and exit
-h HOST_FILE, --hosts=HOST_FILE
hosts file (each line "[user@]host[:port]")
-H HOST_STRING, --host=HOST_STRING
additional host entries ("[user@]host[:port]")
-l USER, --user=USER username (OPTIONAL)
-p PAR, --par=PAR max number of parallel threads (OPTIONAL)
-o OUTDIR, --outdir=OUTDIR
output directory for stdout files (OPTIONAL)
-e ERRDIR, --errdir=ERRDIR
output directory for stderr files (OPTIONAL)
-t TIMEOUT, --timeout=TIMEOUT
timeout (secs) (0 = no timeout) per host (OPTIONAL)
-O OPTION, --option=OPTION
SSH option (OPTIONAL)
-v, --verbose turn on warning and diagnostic messages (OPTIONAL)
-A, --askpass Ask for a password (OPTIONAL)
-x ARGS, --extra-args=ARGS
Extra command-line arguments, with processing for
spaces, quotes, and backslashes
-X ARG, --extra-arg=ARG
Extra command-line argument
-i, --inline inline aggregated output for each server
-I, --send-input read from standard input and send as input to ssh
-P, --print print output as we get it
Example: pssh -h hosts.txt -l irb2 -o /tmp/foo uptime
For timeout issue think of trying the following options:
As per the --help option:
-t TIMEOUT, --timeout=TIMEOUT
timeout (secs) (0 = no timeout) per host (OPTIONAL)
-I, --send-input read from standard input and send as input to ssh
$ cat command1 | parallel-ssh -o Out1 -h prod36AS -x "-i jvxadm-oper-keypair.pem -p 1717" -l ubuntu -I
-t 0
Can also try the following:
parallel-ssh -t -1 [ timeout disable options ]
parallel-ssh -t -1 -h servers list "command"
How about trying with the ssh -o options?:
parallel-ssh -i -h prod36AS -x "-o ConnectTimeout=10 -i key -p 1717" -l ubuntu "sleep 12"
example script:
#!/bin/bash
echo" This command will take the following inputs and run the parallel ssh command"
read -p "Please enter the host file where you have all the host: " HostsFile
read -p "Please enter the key details: " AwsKey
read -p "Please enter the command that you want to run on remote servers: " RemoteCommands
/usr/bin/parallel-ssh -i -h $HostsFile -x "-i $AwsKey -p PORT" -l ubuntu "$RemoteCommands"
You might need to use rsync for quick update along with the backup of the file:
/usr/bin/sudo /usr/bin/rsync -vvrlb --backup-dir=/mnt/rsync-backup/ /source/{dir|file} /dest/{dir|file}
So,
Along with parallel-ssh:
/usr/bin/parallel-ssh -i -h $HostFile -x "-i $AwsKey -p port" -l <user> "
/usr/bin/sudo /usr/bin/rsync -vvrlb --backup-dir=/mnt/rsync-backup/ /source/{dir|file} /dest/{dir|file}"
Few rsync options details again:
-v : copy symlinks as symlinks
-r : copy symlinks as symlinks
-l : copy symlinks as symlinks
-b: make backups (see --suffix & --backup-dir)
--backup-dir=DIR make backups into hierarchy based in DIR
Further help:
$ parallel-ssh --help
$ man parallel-ssh
No comments:
Post a Comment