AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-392596

Ashar's questions

Martin Hope
Ashar
Asked: 2024-01-29 06:43:47 +0800 CST

sed 命令出现错误标签太长:在Solaris 上

  • 5

给定数据库名称oltt206或DB01我希望从下面的 xml 中提取其各自的username,password和:connection string

wladmin@myremhost:/tmp$ cat /web/bea_apps/uat/Tomcat_Home_v9.0.56/TomcatNode01/conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8048" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!-- APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
          <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />

    <Resource auth="Container"
        driverClassName="oracle.jdbc.OracleDriver"
        global="dsspeedCanweb"
        name="dsspeedCanweb"
        password="O9jYL3yhwMF_Ep8P"
        username="VEL_CAN_WEB_USER"
        url="jdbc:oracle:thin:@host36db06v.mybank.com:1521:DB01"
        type="javax.sql.DataSource"
        factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
        initialSize="15" maxTotal="150" maxActive="100" maxWaitMillis="10000" minIdle="15"
        accessToUnderlyingConnectionAllowed="true"
        minEvictableIdleTimeMillis="90000"
        logAbandoned="true" removeAbandoned="true" removeAbandonedTimeout="7200"
        removeAbandonedOnBorrow="true" removeAbandonedOnMaintenance="true"
        jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer;SlowQueryReport(threshold=600000,logFailed=true)"
        testWhileIdle="true"
        validationQuery="select 1 from dual"
        validationInterval="30000"
        testOnBorrow="true" />

    <Resource auth="Container"
        driverClassName="oracle.jdbc.OracleDriver"
        global="canwebds"
        name="canwebds"
        password="bbgwfxt2Os_2024"
        username="CANADA_WEB_USER"
        url="jdbc:oracle:thin:@host36DB06V.mybank.com:1521/oltt206"
        type="javax.sql.DataSource"
        factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
        initialSize="15" maxTotal="150" maxActive="100" maxWaitMillis="10000" minIdle="15"
        accessToUnderlyingConnectionAllowed="true"
        minEvictableIdleTimeMillis="90000"
        logAbandoned="true" removeAbandoned="true" removeAbandonedTimeout="7200"
        removeAbandonedOnBorrow="true" removeAbandonedOnMaintenance="true"
        jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer;SlowQueryReport(threshold=600000,logFailed=true)"
        testOnBorrow="true" />

</GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="12408" address="uswl1212mrshm01.host35as28v.mybank.com" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="12409" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the APR/native implementation which always uses
         OpenSSL for TLS.
         Either JSSE or OpenSSL style configuration may be used. OpenSSL style
         configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                         certificateFile="conf/localhost-rsa-cert.pem"
                         certificateChainFile="conf/localhost-rsa-chain.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="12404" address="uswl1212mrshm01.host35as28v.mybank.com" protocol="AJP/1.3" redirectPort="12409" requiredSecret="QmtmM3hWcEVzUW5VTDNLdQo=" />

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="worker8">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
        Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className='org.apache.catalina.valves.ErrorReportValve'
                showServerInfo='false' />

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

我在solaris上尝试了以下命令但失败了:

错误输出:

wladmin@remhost:$ sed -n '/<Resource/{:a; N; /DB01/!ba; s/.*password="\([^"]*\)".*/\1/p}' /web/bea_apps/perf/Tomcat_Home_v9.0.56/TomcatNode01/conf/server.xml
Label too long: /<Resource/{:a; N; /DB01/!ba; s/.*password="\([^"]*\)".*/\1/p}

期望的结果:

        O9jYL3yhwMF_Ep8P
        VEL_CAN_WEB_USER
        host36db06v.mybank.com:1521:DB01

我最终会将解决方案交给ansible。

请协助。

sed
  • 3 个回答
  • 57 Views
Martin Hope
Ashar
Asked: 2023-12-01 05:03:33 +0800 CST

从 zip 中提取特定文件名而不解压它

  • 5

列出 zip 文件的内容如下:

wladmin@solarishost:/tmp$ unzip -l -q /tmp/package-391.zip | awk '{ print $4 }' | sed -n '3,$p' | grep -v '^$'
myapp/src/stage/bras.war
myapp-configuration/src/config/dev/bras.war
myapp-configuration/src/config/dev/deployfiles/acid.properties
myapp-configuration/src/config/perf/deployfiles/acid.properties
myapp-configuration/src/config/prod/deployfiles/acid.properties
myapp-configuration/src/config/qa/deployfiles/acid.properties
myapp-configuration/src/config/uat/deployfiles/acid.properties

从上面我希望通过获取所有具有deployfile和不具有的文件名来创建删除文件列表DEV,我可以使用下面的方法来做到这一点。

wladmin@solarishost:/tmp$ unzip -l -q /tmp/package-391.zip | awk '{ print $4 }' | sed -n '3,$p' | grep -v '^$' | grep deployfiles | grep -v -i DEV
myapp-configuration/src/config/perf/deployfiles/acid.properties
myapp-configuration/src/config/prod/deployfiles/acid.properties
myapp-configuration/src/config/qa/deployfiles/acid.properties
myapp-configuration/src/config/uat/deployfiles/acid.properties

从剩下的东西即

myapp/src/stage/bras.war
myapp-configuration/src/config/dev/bras.war
myapp-configuration/src/config/dev/deployfiles/acid.properties

从剩余的输出中,我希望获得任何出现多次的文件名,即

myapp-configuration/src/config/dev/bras.war

并将其添加到删除文件列表中

最终期望的输出:

myapp-configuration/src/config/perf/deployfiles/acid.properties
myapp-configuration/src/config/prod/deployfiles/acid.properties
myapp-configuration/src/config/qa/deployfiles/acid.properties
myapp-configuration/src/config/uat/deployfiles/acid.properties
myapp-configuration/src/config/dev/bras.war

最终目标是我将使用最终所需的输出列表从 zip 中删除这些文件并仅使用以下 2 个文件重建 zip:

myapp/src/stage/bras.war
myapp-configuration/src/config/dev/deployfiles/acid.properties

请建议。

wladmin@solarishost:/tmp$ uname -a

SunOS solarishost 5.11 11.4.62.151.3 sun4v sparc sun4v non-global-zone
bash
  • 1 个回答
  • 11 Views
Martin Hope
Ashar
Asked: 2022-12-06 12:21:07 +0800 CST

无法通过匹配字符串 MYAPP 仅取消注释 cron

  • 5

以下是我希望启用的现有 cron

crontab -l

####Cron to auto restart MYAPP
###*/15 * * * * ansible-playbook  /web/playbooks/detectMYAPP/va_action.yml | tee -a /web/playbooks/detectMYAPP/cron.out

我希望通过匹配应用程序名称来启用 cronMYAPP

我使用以下sed命令进行相同的操作:

crontab -l> /web/playbooks/cronenabledisable/wladmin.cron
sed -i '/^#.*MYAPP/Is/^[#]*//' /web/playbooks/cronenabledisable/wladmin.cron
crontab /web/playbooks/cronenabledisable/wladmin.cron

不幸的是,它取消了注释部分的注释,即####Cron to auto restart MYAPP无法安装 cron。

有问题的电流输出:

Cron to auto restart MYAPP
*/15 * * * * ansible-playbook  /web/playbooks/detectMYAPP/va_action.yml | tee -a /web/playbooks/detectMYAPP/cron.out

预期输出:

####Cron to auto restart MYAPP
*/15 * * * * ansible-playbook  /web/playbooks/detectMYAPP/va_action.yml | tee -a /web/playbooks/detectMYAPP/cron.out

注意:我希望保留MYAPP在评论部分 ie####Cron to auto restart MYAPP并且我不能为了命名约定而简单地删除它

linux
  • 2 个回答
  • 30 Views
Martin Hope
Ashar
Asked: 2022-11-11 20:45:41 +0800 CST

如何打印 PID 以及进程转储

  • 6

我希望结合以下两个命令:

ps -ef| grep -v grep|grep java | awk ' {print "PID is:" $2}';
PID is:515
PID is:22145
PID is:32703

ps -ef| grep -v grep|grep java
wladmin    515   506  0 Nov03 ?        01:11:39 /web/jdk-18.0.1.1/bin/java -jar remoting.jar -workDir /web/jenkinsprod -jar-cache /web/jenkinsprod/remoting/jarCache
wladmin  22145 22140  0 Nov04 ?        00:54:18 /web/jdk-18.0.1.1/bin/java -Djava.io.tmpdir=/web/jenkins_windows/tmp -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -jar remoting.jar -workDir /web/jenkins_windows -jar-cache /web/jenkins_windows/remoting/jarCache
wladmin  32703 32699  0 Nov03 ?        01:10:34 /web/jdk-18.0.1.1/bin/java -Djava.io.tmpdir=/web/jenkins/tmp -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -jar remoting.jar -workDir /web/jenkins -jar-cache /web/jenkins/remoting/jarCache

我怎样才能结合这两个命令来得到下面的

期望的输出:

PID is:515
Process Dump is:     wladmin    515   506  0 Nov03 ?        01:11:39 /web/jdk-18.0.1.1/bin/java -jar remoting.jar -workDir /web/jenkinsprod -jar-cache /web/jenkinsprod/remoting/jarCache

PID is:22145
Process Dump is:    wladmin  22145 22140  0 Nov04 ?        00:54:18 /web/jdk-18.0.1.1/bin/java -Djava.io.tmpdir=/web/jenkins_windows/tmp -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -jar remoting.jar -workDir /web/jenkins_windows -jar-cache /web/jenkins_windows/remoting/jarCache
awk
  • 2 个回答
  • 25 Views
Martin Hope
Ashar
Asked: 2022-09-27 14:48:22 +0800 CST

rsync 无法使用 -o StrictHostKeyChecking=no 选项

  • 1

下面的 rsync 工作并帮助将远程目录复制到本地主机

/bin/rsync -rv myremoteuser@myremotehost:/tmp/Deployments/ /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/

一旦我添加-o StrictHostKeyChecking=no它失败并出现以下错误:

/bin/rsync -rv -o StrictHostKeyChecking=no myremoteuser@myremotehost:/tmp/Deployments /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/
Unexpected remote arg: myremoteuser@myremotehost:/tmp/Deployments
rsync error: syntax or usage error (code 1) at main.c(1348) [sender=3.1.2]

我希望它能够工作并且当我将它放在双引号下时也能工作,如下所示:

"/bin/rsync -rv -o StrictHostKeyChecking=no myremoteuser@myremotehost:/tmp/Deployments /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/"
bash: /bin/rsync -rv -o StrictHostKeyChecking=no myremoteuser@myremotehost:/tmp/Deployments /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/: No such file or directory

以下是详细信息:

$ /bin/rsync --version
rsync  version 3.1.2  protocol version 31
Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes, prealloc

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
[mylocaluser@mylocalhost myremotehost]$ uname -a
Linux mylocalhost 3.10.0-1160.76.1.el7.x86_64 #1 SMP Tue Jul 26 14:15:37 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
linux rsync
  • 1 个回答
  • 28 Views
Martin Hope
Ashar
Asked: 2022-09-27 13:31:59 +0800 CST

无法使用 rsync 将目录从远程主机拉到本地

  • 0

我的问题只是我试图解决的一个更大问题的一小部分。

该问题始于rsync非常复杂且由 ansible 构建且不起作用的命令......此处报告:

https://stackoverflow.com/questions/73859216/ansible-synchronize-module-fails-to-get-directory-from-remote-to-local-failed

我希望从一个简单的 rsync 命令开始,将文件夹从远程主机复制到本地。

它复制的是远程是一个文件,但如果远程是一个目录则失败。

$ /bin/rsync --version
rsync  version 3.1.2  protocol version 31
Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes, prealloc

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
[mylocaluser@mylocalhost myremotehost]$ uname -a
Linux mylocalhost 3.10.0-1160.76.1.el7.x86_64 #1 SMP Tue Jul 26 14:15:37 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Rsync 为文件工作:

$ /bin/rsync -v myremoteuser@myremotehost:/tmp/Deployments/pay.war /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/

This system is for the use by authorized users only. All data contained
on all systems is owned by the company and may be monitored, intercepted,
recorded, read, copied, or captured in any manner and disclosed in any
manner, by authorized company personnel. Users (authorized or unauthorized)
have no explicit or implicit expectation of privacy. Unauthorized or improper
use of this system may result in administrative, disciplinary action, civil
and criminal penalties. Use of this system by any user, authorized or
unauthorized, constitutes express consent to this monitoring, interception,
recording, reading, copying, or capturing and disclosure.

IF YOU DO NOT CONSENT, LOG OFF NOW.

##################################################################
# *** This Server is using Centrify                          *** #
# *** Remember to use your Active Directory account          *** #
# ***    password when logging in                            *** #
##################################################################

pay.war

sent 43 bytes  received 83 bytes  252.00 bytes/sec
total size is 0  speedup is 0.00

但是,当我提供目录而不是文件时,它不起作用。

$ /bin/rsync -v myremoteuser@myremotehost:/tmp/Deployments/ /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/

This system is for the use by authorized users only. All data contained
on all systems is owned by the company and may be monitored, intercepted,
recorded, read, copied, or captured in any manner and disclosed in any
manner, by authorized company personnel. Users (authorized or unauthorized)
have no explicit or implicit expectation of privacy. Unauthorized or improper
use of this system may result in administrative, disciplinary action, civil
and criminal penalties. Use of this system by any user, authorized or
unauthorized, constitutes express consent to this monitoring, interception,
recording, reading, copying, or capturing and disclosure.

IF YOU DO NOT CONSENT, LOG OFF NOW.

##################################################################
# *** This Server is using Centrify                          *** #
# *** Remember to use your Active Directory account          *** #
# ***    password when logging in                            *** #
##################################################################

skipping directory .

sent 8 bytes  received 30 bytes  25.33 bytes/sec
total size is 0  speedup is 0.00

请建议。

linux rsync
  • 2 个回答
  • 32 Views
Martin Hope
Ashar
Asked: 2022-09-22 08:43:36 +0800 CST

在忽略文件中的大小写的同时取消对搜索字符串的注释

  • 0

以下是我的 cron 文件条目:

#Ansible: test2
*/15 * * * * ansible-playbook  /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out

# #Cron to auto restart MIMSJASPER tomcat server for all environments if it is down

#Ansible: test3
# */15 * * * * ansible-playbook  /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out

以下 sed 不适用于不区分大小写。

sed '/^#.*morten/s/^#//ig' wladmin.cron

期望的输出:

#Ansible: test2
*/15 * * * * ansible-playbook  /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out

 #Cron to auto restart MIMSJASPER tomcat server for all environments if it is down

#Ansible: test3
 */15 * * * * ansible-playbook  /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out

你能建议吗?

files sed
  • 1 个回答
  • 23 Views
Martin Hope
Ashar
Asked: 2022-04-25 18:30:31 +0800 CST

sed 替换字符串如何成为命令的输出?

  • 1

下面的 sed 命令有助于将文本添加Hello到输入的每一行的末尾

<complex_query> | sed "s,$,Hello,"
Output:
myvar1: Hello
myvar2: Hello

我现在希望输出grep wow data.txt | cut -d: -f2代替Hello

这怎么可能?

以下是我尝试过但不起作用的东西。

<complex_query> | sed "s,$,(grep wow data.txt  | cut -d: -f2),"

预期的期望输出:

myvar1: <output of grep wow data.txt  | cut -d: -f2 command>
myvar2: <output of grep wow data.txt  | cut -d: -f2 command>
sed command
  • 1 个回答
  • 871 Views
Martin Hope
Ashar
Asked: 2022-03-30 03:34:21 +0800 CST

无法将文件编码更改为 utf-8

  • 0

我使用 vi 编辑器修改了一个UTF-8编码的 xml 文件并保存了它。

我在 Redhat Linux 7.9

我检查了更改后的文件编码,发现它是us-ascii

file --mime-encoding tmpfiles/08/config/jdbc/jdbc.xml
tmpfiles/08/config/jdbc/jdbc.xml: us-ascii

我决定将编码改回UTF-8使用以下命令:

iconv -f us-ascii -t UTF-8 tmpfiles/08/config/jdbc/jdbc.xml >tmpfiles/08/config/jdbc/jdbc.xmlenc

echo $?
0

但是,新文件的编码jdbc.xmlenc并未更改为UTF-8并保持不变。请参阅下面的输出:

file --mime-encoding tmpfiles/08/config/jdbc/jdbc.xmlenc
tmpfiles/08/config/jdbc/jdbc.xmlenc: us-ascii

您能否建议我如何将文件编码更改为UTF-8?

linux files
  • 1 个回答
  • 378 Views
Martin Hope
Ashar
Asked: 2022-03-28 14:04:48 +0800 CST

在找到子字符串匹配时搜索并替换以空格分隔的字符串

  • -1

以下是示例文件内容:

猫样本.txt

-server -XX:+UseParallelGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+AggressiveHeap -XX:+PrintHeapAtGC -Djava.util.logging.FileHandler.limit=12908998 -XX:ParallelGCThreads=4 -Xms1536m -Xmx1536m -Xmn512m -Xss4m -XX:LargePageSizeInBytes=4m -XX:-BindGCTaskThreadsToCPUs -XX:PermSize=256m -XX:MaxPermSize=512m -XX:MaxTenuringThreshold=3 -XX:SurvivorRatio=20 -Dweblogic.SocketReaders=10

在一个单独的映射文件中,我得到了一个字符串列表,其中一个是-Djava.util.logging.FileHandler.limit. 如果找到此字符串,则应将其连同其值一起删除。

因此,我希望删除整个条目(连同它的值)-Djava.util.logging.FileHandler.limit=12908998

我可以-Djava.util.logging.FileHandler.limit通过替换-Djava.util.logging.FileHandler.limit为 null 来删除,如下所示:

sed -e s/-Djava.util.logging.FileHandler.limit//g -i sample.txt

由于正则表达式\S*\s让我尝试了用空格分隔的整个字符串,但以下尝试失败了:

sed -e s/-Djava.util.logging.FileHandler.limit\S*\s//g -i sample.txt

但我不确定如何删除它的价值,即-Djava.util.logging.FileHandler.limit=12908998

期望的输出:

猫样本.txt

-server -XX:+UseParallelGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+AggressiveHeap -XX:+PrintHeapAtGC -XX:ParallelGCThreads=4 -Xms1536m -Xmx1536m -Xmn512m -Xss4m -XX:LargePageSizeInBytes=4m -XX:-BindGCTaskThreadsToCPUs -XX:PermSize=256m -XX:MaxPermSize=512m -XX:MaxTenuringThreshold=3 -XX:SurvivorRatio=20 -Dweblogic.SocketReaders=10
files string
  • 1 个回答
  • 45 Views
Martin Hope
Ashar
Asked: 2022-03-28 10:18:55 +0800 CST

如何确保文件每行的最后一个字符以单引号字符结尾

  • -1

我有一个有几行的文件。

我希望更新文件,同时确保文件每一行的最后一个可见字符是单引号'。如果没有,那么我们应该在每行的末尾添加单引号。

如果单引号是一行中的最后一个字符,则保持原样。

猫测试.txt

fahsjhjkhkjhjhajkhjf
afasfsfsfffsfasf'
aaffa' sfff
wfafsfsaffs'
fsafsfs'afffafsasf

预期输出:

fahsjhjkhkjhjhajkhjf'
afasfsfsfffsfasf'
aaffa' sfff'
wfafsfsaffs'
fsafsfs'afffafsasf'
awk sed
  • 5 个回答
  • 288 Views
Martin Hope
Ashar
Asked: 2022-03-28 08:42:47 +0800 CST

如何仅在文件的最后一行末尾添加单引号 [重复]

  • 0
这个问题在这里已经有了答案:
如何替换最后一个非空行中的文本? (4 个回答)
6 个月前关闭。

我想要一个非 perl 解决方案,我应该能够'在文件的最后一个可见(非转义字符)行附加一个单引号并将其保存回文件。

猫示例.txt

var1: 'funn'
var2: 'weee'
var3: 'youuuu

   

预期产出

猫示例.txt

var1: 'funn'
var2: 'weee'
var3: 'youuuu'

我知道如何使用打印最后一行awk以及如何在每行末尾附加一个字符,但无法通过仅将单引号附加到最后一行并更新文件来更新文件。

awk sed
  • 1 个回答
  • 346 Views
Martin Hope
Ashar
Asked: 2022-03-24 02:15:13 +0800 CST

查找重复的第一个字段并在单行中连接其值

  • 3

我有一个文件,其条目key: value格式如下:

猫数据.txt

name: 'tom'
tom_age: '31'
status_tom_mar: 'yes'
school: 'anne'
fd_year_anne: '1987'
name: 'hmz'
hmz_age: '21'
status_hmz_mar: 'no'
school: 'svp'
fd_year_svp: '1982'
name: 'toli'
toli_age: '41'

同样...

我只需要查找并打印那些key: value具有重复键的单个条目。

下面的代码让我得到了重复的键

cat data.txt | awk '{ print $1 }' | sort  | uniq -d
name:
school:

但是,我想要在一行中连接重复键的值的输出。

预期输出:

name: ['tom', 'hmz', 'toli']
school: ['anne', 'svp']
tom_age: '31'
status_tom_mar: 'yes'
fd_year_anne: '1987'
hmz_age: '21'
status_hmz_mar: 'no'
fd_year_svp: '1982'
toli_age: '41'

你能建议吗?

awk text-processing
  • 5 个回答
  • 455 Views
Martin Hope
Ashar
Asked: 2022-03-16 22:06:05 +0800 CST

将文件中尖括号内的连字符替换为下划线

  • 0

我知道如何替换字符串;例如,将文件中的连字符替换为下划线。

但是,对于给定文件中尖括号内的所有文本,我希望用下划线替换所有连字符。

例如,下面的文件:

<charset-params> 
    <input-charset> 
        <resource-path>/*</resource-path> 
        <java-charset-name>UTF-8</java-charset-name> 
    </input-charset> 
</charset-params>

应改为:

<charset_params> 
    <input_charset> 
        <resource_path>/*</resource_path> 
        <java_charset_name>UTF-8</java_charset_name> 
    </input_charset> 
</charset_params>

请注意,UTF-8它没有改变,因为它不在尖括号内。我怎样才能做到这一点?

text-processing files
  • 5 个回答
  • 554 Views
Martin Hope
Ashar
Asked: 2021-11-11 06:37:52 +0800 CST

无法从远程主机连接 telnet 到 mysql 监听 ip 端口

  • 0

我可以在本地远程登录到 mysql 进程,如下所示:

我还通过bind-address = 0.0.0.0如下设置确保 MySQL 进程正在侦听所有 IP:

root@localhost:~# netstat -plutn | grep mysql
tcp        0      0 0.0.0.0:33060           0.0.0.0:*               LISTEN      39288/mysqld
tcp        0      0 0.0.0.0:7306            0.0.0.0:*               LISTEN      39288/mysqld

和

root@localhost:~# telnet 82.165.32.59 7306
Trying 82.165.32.59...
Connected to 82.165.32.59.
Escape character is '^]'.
>Host 'linux' is not allowed to connect to this MySQL serverConnection closed by foreign host

我打开防火墙端口 7306 并使用以下命令重新加载防火墙:

root@localhost:~# firewall-cmd --zone=public --permanent --add-port=7306/tcp
Warning: ALREADY_ENABLED: 7306:tcp
success
root@localhost:~#  firewall-cmd --reload
success
root@localhost:~# firewall-cmd --list-all
public
  target: default
  icmp-block-inversion: no
  interfaces:
  sources:
  services: dhcpv6-client ssh
  ports: 443/tcp 80/tcp 7306/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

但是,当从远程主机 telnet 失败时,如下所示:

$ telnet 82.165.32.59 7306
Trying 82.165.32.59...

telnet: connect to address 82.165.32.59: Connection timed out

我的操作系统是:

root@localhost:~# uname -a
Linux localhost 5.4.0-89-generic #100-Ubuntu SMP Fri Sep 24 14:50:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

root@localhost:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

我尝试重新启动防火墙服务,如下所示:

root@localhost:~# systemctl restart firewalld

我还使用以下脚本刷新了 IPTABLES,但没有帮助:

root@localhost:~# cat fw.stop
#!/bin/sh
echo "Stopping IPv4 firewall and allowing everyone..."
ipt="/sbin/iptables"
## Failsafe - die if /sbin/iptables not found
[ ! -x "$ipt" ] && { echo "$0: \"${ipt}\" command not found."; exit 1; }
$ipt -P INPUT ACCEPT
$ipt -P FORWARD ACCEPT
$ipt -P OUTPUT ACCEPT
$ipt -F
$ipt -X
$ipt -t nat -F
$ipt -t nat -X
$ipt -t mangle -F
$ipt -t mangle -X
$ipt -t raw -F
$ipt -t raw -X

我还使用以下网站检查了端口 7306 是否对外界开放,但它也说Port 7306 is closed on 82.165.32.59.

https://www.yougetsignal.com/tools/open-ports/

然而,下面是输出iptables -L,我没有理解它的专业知识。

root@localhost:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED,DNAT
ACCEPT     all  --  anywhere             anywhere
INPUT_direct  all  --  anywhere             anywhere
INPUT_ZONES  all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere             ctstate INVALID
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED,DNAT
ACCEPT     all  --  anywhere             anywhere
FORWARD_direct  all  --  anywhere             anywhere
FORWARD_IN_ZONES  all  --  anywhere             anywhere
FORWARD_OUT_ZONES  all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere             ctstate INVALID
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
OUTPUT_direct  all  --  anywhere             anywhere

Chain FORWARD_IN_ZONES (1 references)
target     prot opt source               destination
FWDI_public  all  --  anywhere             anywhere            [goto]

Chain FORWARD_OUT_ZONES (1 references)
target     prot opt source               destination
FWDO_public  all  --  anywhere             anywhere            [goto]

Chain FORWARD_direct (1 references)
target     prot opt source               destination

Chain FWDI_public (1 references)
target     prot opt source               destination
FWDI_public_pre  all  --  anywhere             anywhere
FWDI_public_log  all  --  anywhere             anywhere
FWDI_public_deny  all  --  anywhere             anywhere
FWDI_public_allow  all  --  anywhere             anywhere
FWDI_public_post  all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere

Chain FWDI_public_allow (1 references)
target     prot opt source               destination

Chain FWDI_public_deny (1 references)
target     prot opt source               destination

Chain FWDI_public_log (1 references)
target     prot opt source               destination

Chain FWDI_public_post (1 references)
target     prot opt source               destination

Chain FWDI_public_pre (1 references)
target     prot opt source               destination

Chain FWDO_public (1 references)
target     prot opt source               destination
FWDO_public_pre  all  --  anywhere             anywhere
FWDO_public_log  all  --  anywhere             anywhere
FWDO_public_deny  all  --  anywhere             anywhere
FWDO_public_allow  all  --  anywhere             anywhere
FWDO_public_post  all  --  anywhere             anywhere

Chain FWDO_public_allow (1 references)
target     prot opt source               destination

Chain FWDO_public_deny (1 references)
target     prot opt source               destination

Chain FWDO_public_log (1 references)
target     prot opt source               destination

Chain FWDO_public_post (1 references)
target     prot opt source               destination

Chain FWDO_public_pre (1 references)
target     prot opt source               destination

Chain INPUT_ZONES (1 references)
target     prot opt source               destination
IN_public  all  --  anywhere             anywhere            [goto]

Chain INPUT_direct (1 references)
target     prot opt source               destination

Chain IN_public (1 references)
target     prot opt source               destination
IN_public_pre  all  --  anywhere             anywhere
IN_public_log  all  --  anywhere             anywhere
IN_public_deny  all  --  anywhere             anywhere
IN_public_allow  all  --  anywhere             anywhere
IN_public_post  all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere

Chain IN_public_allow (1 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh ctstate NEW,UNTRACKED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https ctstate NEW,UNTRACKED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http ctstate NEW,UNTRACKED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:mysql ctstate NEW,UNTRACKED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:7306 ctstate NEW,UNTRACKED

Chain IN_public_deny (1 references)
target     prot opt source               destination

Chain IN_public_log (1 references)
target     prot opt source               destination

Chain IN_public_post (1 references)
target     prot opt source               destination

Chain IN_public_pre (1 references)
target     prot opt source               destination

Chain OUTPUT_direct (1 references)
target     prot opt source               destination

你能建议吗?

linux firewall
  • 2 个回答
  • 270 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve