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-268006

pyramid13's questions

Martin Hope
pyramid13
Asked: 2018-07-07 21:37:47 +0800 CST

ansible 和期望的问题

  • 0

我想通过 ansible 在 bash 脚本中使用期望工具。首先,执行我的 shell 脚本。检查$JAVA_HOME变量。我设置$JAVA_HOME但在 Ansible 中,我得到一个错误。

我env的$JAVA_HOME:

[root@portal bin]# env | grep JAVA
JAVA_HOME=/usr/java/jdk1.8.0_161

和我的外壳:

#!/usr/bin/expect -f

set timeout 1    
spawn /opt/install.sh

expect  "\[input\] Are you installing the application at the central data center? \[yes/no default: yes\]? \[yes\]\r"
send    "yes\r"

expect  "\[input\] What is the code of central data center \[default: 01\]? \[01\]\r"
send    "01\r"

expect  "What is ip or hostname of your server \[default: localhost\]? \[localhost\]\r"
send     "portal\r"

我的剧本:

- name: --- run portal expect ---
  shell: |
    cd /opt/
    chmod +x portal
    ./portal

Ansible 中的最终错误:

TASK [ansible-portal : --- run portal expect ---]
****************************************************************************************************
fatal: [portal]: FAILED! => {"changed": true, "cmd": "cd /opt/installer/bin/\n chmod +x portal\n ./portal", "delta": "0:00:00.015509", "end": "2018-07-07 14:01:57.971794",
"msg": "non-zero return code", "rc": 1, "start": "2018-07-07 14:01:57.956285", "stderr": "send: spawn id exp6 not open\n    
while executing\n\"send    \"yes\\r\"\"\n    (file \"./portal\" line 8)", "stderr_lines": ["send: spawn id exp6 not open", "    
while executing", "\"send    \"yes\\r\"\"", "    (file \"./portal\" line 8)"], "stdout": "spawn /opt/installer/bin/install.sh\r\nChecking input tasks\r\nSetting 
ANT_HOME\r\nChecking Java\r\nError: No JAVA_HOME is set", "stdout_lines": 
["spawn /opt/installer/bin/install.sh", "Checking input tasks", "Setting ANT_HOME",
 "Checking Java", "Error: No JAVA_HOME is set"]}

像往常一样运行脚本没有问题。

shell-script shell
  • 1 个回答
  • 2517 Views
Martin Hope
pyramid13
Asked: 2018-05-19 22:44:26 +0800 CST

使用 jq 检查是否有任何值为零并将 0 返回到调用 shell 脚本

  • 3

我有这个 JSON 文件:

{ "key11":1010, "key12":12120, "key13":12103 }

如何jq检查与 a 对应的任何值key[0-9][0-9]是否为零,jq如果有则成功退出,否则不成功?

我有一个来自上一个问题的脚本

#!/bin/bash
json=$(cat <<EOF
{"key11":12120,"key11_":13,"key11_yes":12107,
"key12":13492,"key12_no":9,"key12_yes":13483,
"key13":10200,"key13_no":9,"key13_yes":10191,
"key21":16756,"key21_no":30,"key21_yes":16726,
"key22":17057,"key22_no":34,"key22_yes":17023,
"key23":16798,"key23_no":25,"key23_yes":16773,
"key31":2733,"key31_yes":2733,
"key32":2561,"key32_yes":2561,
"key33":2570,"key33_yes":2570}
EOF
)
json2=$(echo ${json}|jq 'with_entries(if (.key|test("key[0-9][0-9]$")) then ( {key: .key, value: .value } ) else empty end )')

结果是:

{ "key11": 12120, "key12": 13492, "key13": 10200, "key21": 16756, "key22": 17057, "key23": 16798, "key31": 2733, "key32": 2561, "key33": 2570 }

现在我想检查附加到所有键$json2的值,然后如果任何条目的值为零返回0。

shell-script json
  • 1 个回答
  • 10936 Views
Martin Hope
pyramid13
Asked: 2018-03-07 07:46:05 +0800 CST

在bash脚本中输出while循环

  • 0

我有ips包含内容的文件:

192.168.10.10 3306
192.168.10.20 3306

我的脚本是:

1 #!/bin/bash
  2
  3 p=0
  4 cat /root/ips | while read host port
  5  do
  6    check_up=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
  7     if [ $check_up != 0 ]
  8         then
  9           p=$[$p+1]
 10           echo "(1):p in loop = $p"
 11     fi
 12         echo "(2):p in loop = $p"
 13  done
 14      echo "(3):p out loop = $p"
 15
 16     if [ $p % 2 != 0 ]
 17        then
 18             exit 1
 19      fi
~

输出是:

[root@db1 ~]# ./new-script.sh
(1):p in loop = 1
(2):p in loop = 1
(1):p in loop = 2
(2):p in loop = 2
(3):p out loop = 0
./new-script.sh: line 16: [: too many arguments

为什么echo "(3):p out loop = $p"返回0(第一个值$p)!?最后一个值$p是什么时候2?另外,如何修复第 16 行的错误?

shell-script shell
  • 1 个回答
  • 304 Views
Martin Hope
pyramid13
Asked: 2018-02-13 04:52:51 +0800 CST

ansible中事实变量的分隔符值

  • 0

实际上,我从事实变量中获得了 ssh 连接。

我在模板中的代码(get-ip.j2):

nod= {{ ansible_env.SSH_CONNECTION }}

我的输出是:

nod= 192.168.231.115 55414 192.168.231.91 22

现在,我怎样才能从中分离192.168.231.91?

ansible template
  • 1 个回答
  • 825 Views
Martin Hope
pyramid13
Asked: 2018-01-25 05:03:23 +0800 CST

zabbix_sender 错误

  • 0

这个错误是什么意思?

[root@db2 zabbix]# zabbix_sender -z zabbix -s zabbix -k mysql[Threads_running] -o 100 -vv               
zabbix_sender [55944]: DEBUG: answer [{"response":"success","info":"processed: 0; failed: 1; total: 1; seconds spent: 0.000015"}]
info from server: "processed: 0; failed: 1; total: 1; seconds spent: 0.000015"
sent: 1; skipped: 0; total: 1
[root@db2 zabbix]# 

另外这个链接我完全解释了我的配置和问题。

perl mysql
  • 1 个回答
  • 1886 Views
Martin Hope
pyramid13
Asked: 2018-01-03 02:16:14 +0800 CST

无法在.ZKUI 中找到 Javac 编译器

  • 2

我想在centos 7.1上安装zkui,但是我有这个错误。

[root@server-1 zkui]# mvn clean install
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building zkui 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ zkui ---
[INFO] Deleting /root/zkui/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ zkui ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 29 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ zkui ---
[INFO] Compiling 20 source files to /root/zkui/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
  /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64/jre/../lib/tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.680 s
[INFO] Finished at: 2018-01-02T08:17:00-05:00
[INFO] Final Memory: 11M/102M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project zkui: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR]   /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64/jre/../lib/tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

MV版本:

[root@server-1 zkui]# mvn -v
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T03:58:13-04:00)
Maven home: /usr/local/maven3
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-229.el7.x86_64", arch: "amd64", family: "unix"

还有我的 JAVA_HOME :

[root@server-1 zkui]# echo $JAVA_HOME  
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64/jre
java maven
  • 2 个回答
  • 1558 Views
Martin Hope
pyramid13
Asked: 2018-01-01 06:55:35 +0800 CST

警告找不到记录器的附加程序(org.apache.zookeeper.ZooKeeper)

  • 1

我在这条路径上安装了 zookeeper /opt/zookeeper。

我zoo-1.cfg的/opt/zookeeper/conf/:

#Node1
 dataDir=/var/zookeeper/data-1
 clientPort=2181
 server.1=127.0.0.1:2888:3888
 server.2=127.0.0.1:2889:3889
 server.3=127.0.0.1:2890:3890

我log4j.properties的/opt/zookeeper/conf/:

zookeeper.root.logger=DEBUG, SYSLOG8
log4j.rootLogger=${zookeeper.root.logger}
zookeeper.log.dir=/var/log/zookeeper
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=DEBUG
zookeeper.tracelog.dir=.
zookeeper.tracelog.file=zookeeper_trace.log
#-------------------------------------------------
log4j.appender.SYSLOG8=org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG8.threshold=DEBUG
log4j.appender.SYSLOG8.syslogHost=192.168.26.16
log4j.appender.SYSLOG8.facility=USER
log4j.appender.SYSLOG8.layout=org.apache.log4j.PatternLayout
log4j.appender.SYSLOG8.layout.conversionPattern=[%p] %c:%L - %m$

当我想与客户端连接时,出现此错误:

[root@server-1 bin]# sh zkCli.sh -server 127.0.0.1:2182
log4j:ERROR Could not find value for key log4j.appender.CONSOLE
log4j:ERROR Could not instantiate appender named "CONSOLE".
Connecting to 127.0.0.1:2182
log4j:WARN No appenders could be found for logger 
(org.apache.zookeeper.ZooKeeper).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for 
more info.
Welcome to ZooKeeper!
JLine support is enabled

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2182(CONNECTED) 0] 

我的rsyslog.cnf:

$ModLoad imudp
$UDPServerRun 514
$ModLoad imtcp
$InputTCPServerRun 514
*.*  @192.168.26.16:514

请说明错误的原因。还需要做什么才能在 syslog 中注册 zookeeper 日志?谢谢。

logs rsyslog
  • 2 个回答
  • 5373 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