小编Pet*_*ete的帖子

在bash脚本中提取XML值

我正在尝试从已作为变量读入我的脚本的xml文档中提取值.原始变量$ data是:

<item> 
  <title>15:54:57 - George:</title>
  <description>Diane DeConn? You saw Diane DeConn!</description> 
</item> 
<item> 
  <title>15:55:17 - Jerry:</title> 
  <description>Something huh?</description>
</item> 
Run Code Online (Sandbox Code Playgroud)

我希望提取第一个标题值,所以

15:54:57 - George:
Run Code Online (Sandbox Code Playgroud)

我一直在使用sed命令:

title=$(sed -n -e 's/.*<title>\(.*\)<\/title>.*/\1/p' <<< $data)
Run Code Online (Sandbox Code Playgroud)

但这只输出第二个标题值:

15:55:17 - Jerry:
Run Code Online (Sandbox Code Playgroud)

有谁知道我做错了什么?谢谢!

xml bash shell sed

38
推荐指数
3
解决办法
11万
查看次数

Tomcat未能部署.war

我正在尝试按照教程创建一个简单的REST Web服务,但是我可以在tomcat上部署它并抛出异常:

FAIL - Application at context path /restful could not be started
FAIL - Encountered exception org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/restful]]
Run Code Online (Sandbox Code Playgroud)

我看了看周围的解决方案,发现这个问题,这一个,他们让我觉得这是一个servlet的映射问题但是我不知道如何解决它!

这是我的日志文件:

18/12/2012 9:57:16 AM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive /opt/tomcat7/webapps/restful.war
java.lang.IllegalStateException: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/restful]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
Run Code Online (Sandbox Code Playgroud)

这是我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://java.sun.com/xml/ns/javaee" …
Run Code Online (Sandbox Code Playgroud)

java rest tomcat war illegalstateexception

18
推荐指数
1
解决办法
6万
查看次数

以版本2运行远程Powershell会话

我在运行Powershell版本2的服务器上:

PS C:\> $PSVersionTable

Name      Value
----      -----
...
PSVersion 2.0
Run Code Online (Sandbox Code Playgroud)

然后,我创建一个到另一台计算机的新远程会话并连接到它:

$sess = New-PSSession -ComputerName {ComputerName} -Credential $credential
Run Code Online (Sandbox Code Playgroud)

它返回结果:

PS C:\> Invoke-Command -Session $sess -ScriptBlock { $PSVersionTable }

Name      Value
----      -----
...
PSVersion 3.0
Run Code Online (Sandbox Code Playgroud)

但是,我需要Powershell在我的脚本的版本2中,所以我进入一个会话(以使其更容易).然后我尝试让Powershell成为第2版:

C:\> Enter-PSSession -Session $sess
[{ComputerName}]: PS C:\> Powershell -Version 2
Windows Powershell
Copyright (C) 2009 Microsoft Corporation. All rights reserverd
Run Code Online (Sandbox Code Playgroud)

然后它就会挂起(或者至少从来没有让我在控制台中输入任何其他内容,直到我按Ctrl-C).

我也尝试过通过Invoke-Command:

PS C:\> Invoke-Command -Session $sess -ScriptBlock { Powershell -version 2 }
Run Code Online (Sandbox Code Playgroud)

它也是如此.

我还尝试按照此处注册PSSessionConfiguration:https://technet.microsoft.com/en-us/library/hh847899.aspx

PS C:\> Register-PSSessionConfiguration -Name PS2 …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-2.0 powershell-3.0

8
推荐指数
1
解决办法
1727
查看次数