How can I write a heredoc to a file in Bash script?

前端 未结 9 1096
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 12:33

How can I write a here document to a file in Bash script?

9条回答
  •  耶瑟儿~
    2020-11-22 13:13

    As instance you could use it:

    First(making ssh connection):

    while read pass port user ip files directs; do
        sshpass -p$pass scp -o 'StrictHostKeyChecking no' -P $port $files $user@$ip:$directs
    done <<____HERE
        PASS    PORT    USER    IP    FILES    DIRECTS
          .      .       .       .      .         .
          .      .       .       .      .         .
          .      .       .       .      .         .
        PASS    PORT    USER    IP    FILES    DIRECTS
    ____HERE
    

    Second(executing commands):

    while read pass port user ip; do
        sshpass -p$pass ssh -p $port $user@$ip <

    Third(executing commands):

    Script=$'
    #Your commands
    '
    
    while read pass port user ip; do
        sshpass -p$pass ssh -o 'StrictHostKeyChecking no' -p $port $user@$ip "$Script"
    
    done <<___HERE
    PASS    PORT    USER    IP
      .      .       .       .
      .      .       .       .
      .      .       .       .
    PASS    PORT    USER    IP  
    ___HERE
    

    Forth(using variables):

    while read pass port user ip fileoutput; do
        sshpass -p$pass ssh -o 'StrictHostKeyChecking no' -p $port $user@$ip fileinput=$fileinput 'bash -s'< $fileinput
        #Your command > $fileinput
    ENDSSH1
    done <<____HERE
        PASS    PORT    USER    IP      FILE-OUTPUT
          .      .       .       .          .
          .      .       .       .          .
          .      .       .       .          .
        PASS    PORT    USER    IP      FILE-OUTPUT
    ____HERE
    

提交回复
热议问题