Shell Remote Execution command

Source: Internet
Author: User
Tags function definition

SSH Main parameter description

-L Specify Login user

-P Set Port number

-F run in the background, and recommended with the-n parameter

-n redirects standard input to/dev/null to prevent reading standard input

-N Do not execute remote command, only port forwarding

-Q Quiet mode, ignoring all dialogs and error hints

-T disabling pseudo-terminal configuration

# !/bin/sh host_list="host1 host2 host3 host4"ssh_port=2202for in  $HOST _listdo        "executing in $loop:        ""  $"
#ssh-F-P $SSH _port $loop "$" &
Echodone

Call Tar zxvf/root/pat.tar.gz-c/home

Invoking a remote script locally

$ ssh-l Oracle R7  '/tmp/b.sh &'

Note the following points:

& indicates the background execution, also can not add;

Script to have execute permission;

If a file is used in remote script b.sh, the file must be written to the full path, otherwise the default is the home directory of the specified user, not the current directory.

Simulating concurrency with pipelines

#!/usr/bin/ksh#SCRIPT:ptest.sh#author:ray001#date:2008/10/03#rev:2.0#For STUDY##PURPOSE:#enables process concurrency, improves execution efficiency, and records each execution failure of the child process information#define the number of concurrent processesParallel=3#To define a temporary pipe file nametmpfile=$.fifo#define export Profile full path namecmd_cfg= $HOME/cfg/ptest.cfg#defining failed Identity filesfailure_flag=Failure.log####################### function Definition #########################kill child process at breakfunction Trap_exit{kill-90}#General execution FunctionsExec_cmd () {#here is the actual command that needs to be executed, in this case using sleep as an exampleSleep ${1}    if[ $? -NE 0] then echo"Command execution failed"        return1Fi}trap'trap_exit; Exit 2'1 2 3 15#Cleanup failed identity fileRM-F ${failure_flag}#create a corresponding number of placeholders for concurrent processesMkfifo $TMPFILEexec4<>$TMPFILE RM-F $TMPFILE {count=$PARALLEL while[$count-GT 0] do echo let Count= $count-1Done }>&4#get each task in order from the task list seq whileread SEC do read<&4(Exec_cmd ${sec}|| Echo ${sec}>>${failure_flag}; echo >&4) & Done<$CMD _cfgwaitexec4>&-#determine if all succeeds after the concurrent process finishesif[ -F ${failure_flag}]then exit1ElseExit 0fi

Shell Remote Execution command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.