
구성 파일이 있습니다prosody.config
다음 데이터를 사용합니다.
VirtualHost "pubsub.subdomain.domain.com"
admins = { "node1.subdomain.domain.com", "node2.subdomain.domain.com" }
autocreate_on_subscribe = true
autocreate_on_publish = true
modules_enabled = {
"pubsub";
}
VirtualHost "subdomain.domain.com"
authentication = "anonymous"
modules_enabled = {
"bosh";
}
c2s_require_encryption = false
VirtualHost "auth.subdomain.domain.com"
authentication = "internal_plain"
admins = { "[email protected]" }
Component "node1.subdomain.domain.com"
component_secret = "password"
Component "node2.subdomain.domain.com"
component_secret = "password"
Component "conference.subdomain.domain.com" "muc"
Component "focus.subdomain.domain.com"
component_secret = "password"
node2.subdomain.domain.com
이 경우 번호 다음에 사용 가능한 첫 번째 번호를 찾아서 3
다음과 같은 동일한 구성에 다시 표시해야 합니다.echo -e "Component \"node3.subdomain.domain.com\"\n component_secret = \"password\"" >> prosody.config
최종 콘텐츠는 다음과 같아야 합니다.
VirtualHost "pubsub.subdomain.domain.com"
admins = { "node1.subdomain.domain.com", "node2.subdomain.domain.com" }
autocreate_on_subscribe = true
autocreate_on_publish = true
modules_enabled = {
"pubsub";
}
VirtualHost "subdomain.domain.com"
authentication = "anonymous"
modules_enabled = {
"bosh";
}
c2s_require_encryption = false
VirtualHost "auth.subdomain.domain.com"
authentication = "internal_plain"
admins = { "[email protected]" }
Component "node1.subdomain.domain.com"
component_secret = "password"
Component "node2.subdomain.domain.com"
component_secret = "password"
Component "conference.subdomain.domain.com" "muc"
Component "focus.subdomain.domain.com"
component_secret = "password"
Component "node3.subdomain.domain.com"
component_secret = "password"
Component "node4.subdomain.domain.com"
component_secret = "password"
스크립트를 실행할 때마다 이 경우 가장 큰 숫자부터 숫자가 1씩 증가합니다."node4.subdomain.domain.com"
감사해요 !
답변1
짧은둔한 사람해결책:
awk -v FPAT="[0-9]+" 'END{print "node"$1+1}' xyz.config
출력:
node4
FPAT="[0-9]+"
- 필드 구분 기호와 일치하는 대신 필드와 일치하는 정규 표현식END{...}
- 파일의 마지막 줄만 고려
답변2
< xyz.config tail -n 1 | awk 'match($0, /[0-9]+$/) {
print substr($0, 1, RSTART-1) substr($0, RSTART)+1}'
파일의 마지막 줄을 얻으려면 줄 끝의 숫자를 추출하고 숫자 앞의 내용과 그 숫자를 구성하는 숫자를 1씩 증가시켜 인쇄합니다.
에서 모든 작업을 수행할 수도 있지만 awk
이는 전체 파일을 완전히 읽는다는 의미입니다.
< xyz.config awk 'END {if(match($0, /[0-9]+$/))
print substr($0, 1, RSTART-1) substr($0, RSTART)+1}'
연산자 사용 sh
:
< xyz.config tail -n1 | (
IFS= read -r line || exit
num=${line##*[!0-9]}
printf '%s\n' "${line%"$num"}$((num + 1))")