English 中文(简体)
编组档案中一个章节的内容
原标题:Move contents of one section above another section in a configuration file
  • 时间:2023-07-28 16:50:31
  •  标签:
  • bash
  • unix

我要求将我的仪表组合文件中的[我的舱面]部分移至我的板块组合文件上的另一节,标题是<编号>#SAFE#;在移到该节之后,各科之间应当有空间。

使用的代码:

#!/bin/bash
for server in `cat /home/servers.txt `
username=$1
password=$2
do
sshpass-p $PWD ssh -o stricthostchecking=no $USERNAME@$server "ed -s /home/my.cnf << EOF 
/^[已婚]$/;/^[.*/ -1m$
?[已婚]?i

.
w
EOF"
done

a. 实际:

[已婚]

disable-log-bin = 1

skip-name-resolve = 1
performance-schema = 0
local-infile = 0
mysqlx = 0
open_files_limit = 200000
max_allowed_packet = 256M
sql_mode="NO_ENGINE_SUBSTITUTION"

#the below are password related of [已婚]
 validate password=1

innodb_dedicated_server = 1
innodb_buffer_pool_instances = 48

[myisamck]
a=3
b=4

[sst]
d=3
c=4

# SAFE #
d=0
f=0

要求:[已婚] section and its section should be pasted above # RSE # ( section in very small cases section is given as #SAFE## or #SAFE# or # RSE # in small of my.cnf file),Please support.

预期产出:

[myisamck]
a=3
b=4

[sst]
d=3
c=4

[已婚]

disable-log-bin = 1

skip-name-resolve = 1
performance-schema = 0
local-infile = 0
mysqlx = 0
open_files_limit = 200000
max_allowed_packet = 256M
sql_mode="NO_ENGINE_SUBSTITUTION"

#the below are password related of [已婚]
 validate password=1

innodb_dedicated_server = 1
innodb_buffer_pool_instances = 48

# SAFE #
d=0
f=0
问题回答

我不使用<代码>sshpass,但便携式编码<>ssh,其中关键内容如下:

#!/usr/bin/env bash

servers=(
  server1
  server2
  server3
  ...
)

for server in "${servers[@]}"; do
  ssh -t "jetchise@$server"  ed -s ~/my.cnf <<EOF
  /#[[:space:]]*SAFE[[:space:]]*#/kx
  /^[mysqld]$/;/^[.*/-1m   x-1
  ,p
  Q
EOF 
done

为将<代码>/home/servers.txt的内容添加到一个阵列中,一种办法是使用mapfile aka readarray。 它是双面4+特征。

mapfile -t servers < /home/servers.txt

  • 在<代码>、p的行文后面加上w

  • 删除<代码>,p以保持产出不变。





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签