Ssh@host: "" ssh switch to other machines to execute more than one command; Pseudo-terminal won't be allocated because stdin are not a terminal.

Source: Internet
Author: User
Tags stdin ssh
1. Background: The shell script executes the Kafka Start command on the main machine, and the other machines will also take this process. The previous script appears stuck every time it executes and cannot be returned to the command line.

Solution: The first type

#/bin/bash
kafka_home=/opt/kafka
source/opt/wyl/cfg.config
su-hadoop <<eof for
mm in ${ip[*] ;d o
    echo "===>" \${mm}: 
    ssh hadoop@\${mm} "CD/OPT/KAFKA; Nohup./bin/kafka-server-start.sh ${kafka_home}/config/server.properties >/opt/kafka/kafka.log & [$-eq 0] &am p;& Echo ' Kafka is start ... ' "
done
EOF

Where IP is the list of all machines that need to be executed.
SSH hadoop@${mm} must be followed by double quotes
Where semicolons are the function of separating commands
/opt/kafka/kafka.log is to print the log to this place the second type:

SSH Root@ip << remotessh
First to ssh up, SSH configuration can look at my previous article, note here << remotessh
From here on, the command is executed on the remote machine.
cd/tmp/test/
Rm-f Test.txt
Cat Test.log | grep ' Test ' >> test.txt
echo "finished!" Execution Completed

Exit # # # #不要忘记退出远程机器
REMOTESSH # # #还有这里的结尾哦, don't forget

#!/bin/bash
  2 Kafka_home=/opt/kafka
  3 source/opt/wyl/cfg.config
  4 su-hadoop <<eof
  5 for MM in ${ Ip[*]};d o
  6 echo "===>" \${mm}:
  7 ssh-tq hadoop@\${mm} << remotessh
  8 Cd/opt/kafka
  9 nohup./bi n/kafka-server-start.sh ${kafka_home}/config/server.properties >/opt/kafka/kafka.log &
 Ten [$-eq 0] & & Echo ' Kafka is start ... ' one 
 exit  
 remotessh
 

After this method executes the script, it prints out the

Pseudo-terminal won't be allocated because stdin are not a terminal.

The literal meaning is that the pseudo terminal will not be allocated because the standard input is not a terminal.
People with obsessive-compulsive disorder must feel annoyed.
This time we can add parameters to solve this problem.
Therefore, additional-TT parameters are required to force pseudo terminal allocation, even if the standard input is not a terminal.
Or add-TQ this parameter also can.

Plus-tt run Result: Ssh-tt hadoop@ ' xxxx '
Each terminal prints out the commands that are executed

Plus-TQ Run results ssh-tq hadoop@ ' xxxx '

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.