好吧,显然我不是一个bash guru而且我需要一个!
我之前从未使用过'coproc',但它似乎正是我所需要的.但是,我不得不承认我无法从那里的各种'ping'例子中推断出来![我确实尝试了几个小时...]
我想要做的就是启动一个'coproc'shell脚本,它可以从标准输入中获取输入,并将其结果写入标准输出.我希望主脚本分别发送和处理这些命令和结果.
这是我想要做的最简单的概述之一:用 更好的细节编辑
#! /bin/bash
coproc bkgndProc {
/some/path/to/usefulScript.sh maybeSomeArgsHere
}
// send command #1 to bkgndProc here
result=$(echo 'command' <&${bkgndProc[0]}) ### Doesn't work for me
echo "Did it work? $result" ### this just prints back the 'command' I used
// here execute conditional logic based on result:
// if result1; then
// send command #2 here, getting results
// else
// send command #3 here, again getting results
// fi
Run Code Online (Sandbox Code Playgroud)
很抱歉使用上面的伪代码,但我不确定那些发送命令应该是什么!如果有人能提供非常感谢的细节!
我正在将用户交互的文本移动到外部groovy配置文件.我没有遇到任何问题"啜饮"这个问题,直到需要处理这样的文本:
text:"Enter the port number used by the program (${defaultPort}): "
Run Code Online (Sandbox Code Playgroud)
有没有办法将此值读入String或GString,然后绑定到活动程序值(如defaultPort)?
在将处理此代码的代码中,"defaultValue"可以设置为多个值.例如,如果使用http,则该值可能为80,但如果使用https,则可能为443.
我意识到SimpleTemplateEngine会起作用,但是有更简单的方法吗?
两个不起作用的解决方案:
1)
text:{ value -> "Enter the port number used by the program ($value)" }
Run Code Online (Sandbox Code Playgroud)
好的,实际上这确实有效!但是,我不能(或者不认为我可以)使用这种方法,因为这是例外情况,绝大多数用途只会读取文本.这种方法要求您将其称为一种方法,它会破坏所有其他用途.
我尝试将其作为Java String(单引号)读取并从中创建一个GString.我甚至不会展示代码 - 这是新的一年,而不是愚人节!我只想说我无法工作!
2)
我也试过这个变种:
def defaultPort = determinePort()
def textVal = myConfig.text // tried single and double quotes in the config file
def newVal = "${writer -> writer << textVal}"
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
根据loteq的回答添加更多细节
如果很清楚,这里有一个更详细的草图,我想做什么:
// questions would be in a file parseable by ConfigSlurper: …Run Code Online (Sandbox Code Playgroud) 在这篇博客文章中,我在评论中找到了以下引文:
本菲什曼
是的 - 你是对的我应该指出Docker套接字的安全问题.这是目前在生产中实用的主要阻碍因素,我们肯定正在寻找帮助以使其更好地工作,正如您从待办事项列表中注意到的那样.
虽然我确信这对许多人来说是有道理的,对于我们其他人来说,有人可以用明确的术语来解释这个"安全问题"究竟是什么吗?我认为它指的是:
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
Run Code Online (Sandbox Code Playgroud)
在docker-compose文件中.那是对的吗?如何被利用?这是否有效地禁止了生产使用的这种方法?如果是这样,有解决方法吗?
我有一个我需要修改的文件.我需要修改的部分(不是整个文件)类似于下面显示的属性.问题是我只需要替换部分"值",即"ConfigurablePart".我收到此文件,因此无法控制其格式.
alpha.beta.gamma.1 = constantPart1ConfigurablePart1
alpha.beta.gamma.2 = constantPart2ConfigurablePart2
alpha.beta.gamma.3 = constantPart3ConfigurablePart3
Run Code Online (Sandbox Code Playgroud)
我用这种方式做了这个工作,虽然我知道这真的很糟糕!
def updateFile(String pattern, String updatedValue) {
def myFile = new File(".", "inputs/fileInherited.txt")
StringBuffer updatedFileText = new StringBuffer()
def ls = System.getProperty('line.separator')
myFile.eachLine{ line ->
def regex = Pattern.compile(/$pattern/)
def m = (line =~ regex)
if (m.matches()) {
def buf = new StringBuffer(line)
buf.replace(m.start(1), m.end(1), updatedValue)
line = buf.toString()
}
println line
updatedFileText.append(line).append(ls)
}
myFile.write(updatedFileText.toString())
}
Run Code Online (Sandbox Code Playgroud)
传入模式需要包含在StringBuffer中替换的组.有谁知道如何在Groovy中真正做到这一点?
编辑 - 定义预期输出
需要更新包含示例行的文件,以便每行的"ConfigurablePart"替换为提供的更新文本.对于我丑陋的解决方案,我需要调用方法3次,一次替换ConfigurablePart1,一次用于ConfigurablePart2,最后用于ConfigurablePart3.对此也有更好的方法!
*更新 - 做出我真正需要的答案*
如果其他人遇到类似的问题,我询问的常规代码改进最好反映在接受的答案中.但是,对于我的问题并没有完全解决我的问题.由于我只需要替换部分匹配的行,我需要使用反向引用和组.我能做到这一点的唯一方法是定义一个由三部分组成的regEx:
(.*)(matchThisPart)(.*)
Run Code Online (Sandbox Code Playgroud)
一旦完成,我就可以使用:
it.replaceAdd(~/$pattern/, "\$1$replacement\$3") …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用gradle-grails-plugin来构建一个现有的(小)Grails项目.这有用吗?依赖关系build.gradle和指定的依赖关系是什么buildConfig.groovy?
无论如何,我有两个项目,所以最顶层的build.gradle文件在父目录中,如下所示:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.2.0.RC1"
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
Run Code Online (Sandbox Code Playgroud)
然后Grails项目中的build.gradle看起来像:
apply plugin: "grails"
repositories {
grails.central() //creates a maven repo for the Grails Central repository (Core libraries and plugins)
}
grails {
grailsVersion = '2.4.4'
groovyVersion = '2.3.9'
springLoadedVersion '1.2.0.RELEASE'
}
dependencies {
bootstrap "org.grails.plugins:tomcat:7.0.55.3"
compile 'org.grails.plugins:asset-pipeline:3.0.1'
compile 'org.grails.plugins:scaffolding:2.1.2'
compile 'org.grails.plugins:cache:1.1.8'
runtime 'org.grails.plugins:hibernate4:4.3.1.1'
runtime 'org.grails.plugins:database-migration:1.3.8'
runtime 'org.grails.plugins:jquery:1.11.0'
}
Run Code Online (Sandbox Code Playgroud)
但是,当我跑步时./gradlew war …
尽管--restart标志看起来很简单明了,但是在尝试使用它时我提出了许多问题:
ENTRYPOINT定义-重新启动期间实际定义的语义是什么?exec进入容器(我在DDC上)并杀死-9,该过程将重新启动,但是如果我不docker kill这样做,则重新启动。为什么?我最近没有升级Docker.我曾经能够毫无错误地删除容器.我现在一直都这样:
docker rm -f 05344fa394a4
Error response from daemon: driver "overlay" failed to remove root filesystem for
05344fa394a43e5080deb1a43fdeab3a6f141038069f1a49209e29ec8f06a20c:
remove /var/lib/docker/overlay/c9eb21a91ae1a37a121855a1ef65a89593994dc036affa9ff295b59b4eca1af5/merged:
device or resource busy
Run Code Online (Sandbox Code Playgroud)
我基本上必须重新启动(systemctl restart docker不修复)才能成功删除并继续.任何人都对可能出错的东西有任何见解?
我root和Docker 17.06 一样在Centos 7.3上运行.一切都在/var/lib/docker和/var/lib/docker/overlay它的拥有者root:root是保护700 /var/lib/docker/network实际上是750]
目前,在Linux上使用ZooKeeper满足我们的初始需求.代码库是所有Java/Groovy.稍后,将需要支持Windows.但是,ZooKeeper文档支持的平台仅列出对Windows 32的"开发"支持:
Win32 is supported as a development platform only for both server and client.
Run Code Online (Sandbox Code Playgroud)
人们在Windows上成功运行ZK吗?有什么问题?
另外,64位Windows呢?有人这样做,你可以分享任何经验吗?
从这个 Spring 文档中我知道当我使用 @Bean 时,默认值已经等同于:
@Bean(autowire = Autowire.NO)
(默认)没有自动装配。Bean 引用必须通过 ref 元素定义。对于较大的部署,不建议更改默认设置,因为明确指定协作者可以提供更好的控制和清晰度。在某种程度上,它记录了系统的结构。
我只是想了解这对我意味着什么。如果我的系统是 100% Java 配置并且没有 XML 配置,那么据我所知,当我使用 @Bean 时,“Autowire.no”没有任何影响。
编辑
“无影响”是指其他对此 bean 的 @Autowired 引用是自动装配的(在其他 Java Config 类中)。我怀疑这是因为在 Java Config 中没有明确定义“ref 元素”,因此此(默认)设置无效。
例子:
第一个配置:
package a.b.c;
@Configuration
public class AlphaConfig {
@Bean(autowire = Autowire.NO)
public AlphaBeanType alphaBean() {
return new AlphaBeanType();
}
}
Run Code Online (Sandbox Code Playgroud)
然后在第二个配置中:
package d.e.f;
import a.b.c.AlphaBeanType;
@Configuration
public class AnotherConfig {
@Autowire
private AlphaBeanType alphaBeanType;
@Bean
. . .
}
Run Code Online (Sandbox Code Playgroud)
我看到的是“alphaBeanType”总是在第二个配置类中自动装配 - 这似乎与文档冲突 …
在代码领域遇到大麻烦,因此我需要帮助!
使用Groovy和JsonSlurper我正在处理下面表单的JSON.当"类型"键设置为某个值时,我正在寻找外部包含元素(在我的情况下,这应该是全部应该是地图).例如,如果类型是"Type5",那么我需要返回三个地图:包含外部Type5的"body"地图,包含INNER Type5的"body"地图和靠近底部的Type5地图(每个的EntrySet也可以正常工作).Type3和Type4表现出相同的行为!
根据请求编辑以拥有有效的Json
我通过Groovy的JsonSlurper运行它,所以它应该是有效的.
{
"type": "Run1",
"body": [
{
"type": "Type1",
"expression": {
"type": "Type2",
"expressions": [
{
"type": "Type3",
"body": {
"type": "Type4",
"id": null,
"params": [
{
"type": "Identifier",
"name": "a"
},
{
"type": "Identifier",
"name": "b"
},
{
"type": "Identifier",
"name": "c"
}
],
"body": {
"type": "Type5",
"body": [
{
"type": "Type6",
"id": {
"type": "Identifier",
"name": "d"
},
"params": [
{
"type": "Identifier",
"name": "a"
}
],
"body": {
"type": "Type5",
"body": [ …Run Code Online (Sandbox Code Playgroud)