小编sfg*_*ups的帖子

Groovy计数文件数与目录中的regex匹配

我正在使用此代码来计算目录中以's'结尾的文件数.

            def count=0
        def p = ~/.*s/
        new File("c:\\shared").eachFileMatch(p) { file->
            println file.getName().split("\\.")[0]
            count++
        }
        print "$count"
Run Code Online (Sandbox Code Playgroud)

如果有办法避免temp变量并在File类本身使用一些方法?

谢谢

groovy

5
推荐指数
1
解决办法
4367
查看次数

Perl单行单引号

我使用Perl单行创建一个SQL语句,但我不能包含单引号.

这就是我想要的:首先提交并添加引号.

echo "a,b" | perl -F',' -lane 'print $F[0];'
 'a'
Run Code Online (Sandbox Code Playgroud)

我尝试了几种不同的方法,但它对我不起作用.

1.

echo "a,b" | perl -F',' -lane 'print qq('$F[0]');'
[0]
Run Code Online (Sandbox Code Playgroud)

2.

echo "a,b" | perl -F',' -lane 'print q('$F[0]');'
[0]
Run Code Online (Sandbox Code Playgroud)

这是另一个有趣的.

它使用print语句打印单引号,但如果我为变量赋值并打印它不起作用.

perl -lwe "print q( i'am );"
 i'am

perl -lwe "$b=q( didn't ); print $b"
Run Code Online (Sandbox Code Playgroud)

你能帮助我理解我们如何在Perl单行中使用单引号和双引号?

shell perl quoting

4
推荐指数
2
解决办法
1万
查看次数

SQL Server:按降序选择不同的mon-yyyy格式输出sorty

datetime在表中有一列包含以下数据:

2011-03-23
2011-04-19
2011-04-26
2011-05-26
Run Code Online (Sandbox Code Playgroud)

我想选择mon-yyyy按报告日期降序排序的不同格式输出.我们需要在SQL语句中只选择一列

这个SQL有效,但我想按ReportDate列排序

SELECT  distinct SUBSTRING (convert(varchar, ReportDate, 100),1,3) +'-'+
        SUBSTRING (convert(varchar, ReportDate, 100),8,4 ) 
  FROM [EnvelopsDB].[dbo].[Envelopes]
Run Code Online (Sandbox Code Playgroud)

产量

Apr-2011
Mar-2011
May-2011
Run Code Online (Sandbox Code Playgroud)

这个SQL给出了一个错误:

SELECT  distinct SUBSTRING (convert(varchar, ReportDate, 100),1,3) +'-'+
        SUBSTRING (convert(varchar, ReportDate, 100),8,4 ) 
  FROM [EnvelopsDB].[dbo].[Envelopes]
  order by ReportDate
Run Code Online (Sandbox Code Playgroud)

错误:


如果指定了SELECT DISTINCT,则消息145,级别15,状态1,行2 ORDER BY项目必须出现在选择列表中.

什么是获得我需要的输出的最佳SQL查询?

sql sql-server-2008

4
推荐指数
1
解决办法
9441
查看次数

在Unix中删除ANSI颜色转义的最佳方法

我有一个perl progaram它的打印输出颜色.如果我重新扫描文件中的输出并在vi中打开它,我会看到颜色特殊字符.这样的事情.

^[[31;43mAnd this is red on_yellow too^[[0m
Run Code Online (Sandbox Code Playgroud)

从输出文件中删除此颜色字符的最佳方法是什么?

谢谢

更新:

我尝试了正则表达式.这个对我有用:

 cat -v a|head
^[[30;41mThis is black on_red^[[0m
^[[30;41mAnd this is black on_red too^[[0m
^[[30;42mThis is black on_green^[[0m
^[[30;42mAnd this is black on_green too^[[0m
^[[30;43mThis is black on_yellow^[[0m
^[[30;43mAnd this is black on_yellow too^[[0m
^[[30;44mThis is black on_blue^[[0m
^[[30;44mAnd this is black on_blue too^[[0m
^[[30;45mThis is black on_magenta^[[0m
^[[30;45mAnd this is black on_magenta too^[[0m


$ cat -v a|head|perl -lane 's/\^\[\[\d+(;\d+)*m//g; print'
This is black on_red
And this is black …
Run Code Online (Sandbox Code Playgroud)

unix perl

4
推荐指数
2
解决办法
2566
查看次数

docker将cgroup驱动程序更改为systemd

我想让docker从systemd cgroup驱动程序开始。由于某些原因,它仅在我的centos 7服务器上使用cgroupfs。

这是启动配置文件。

# systemctl cat docker
# /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer

[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
          --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
          --default-runtime=docker-runc \
          --exec-opt native.cgroupdriver=systemd \
          --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
MountFlags=slave

[Install]
WantedBy=multi-user.target

# /etc/systemd/system/docker.service.d/docker-thinpool.conf
 [Service]
 ExecStart=
 ExecStart=/usr/bin/dockerd --storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool \
 --storage-opt=dm.use_deferred_removal=true --storage-opt=dm.use_deferred_deletion=true
 EOF
Run Code Online (Sandbox Code Playgroud)

当启动docker这样运行时:

# ps -fed |grep docker …
Run Code Online (Sandbox Code Playgroud)

linux docker

4
推荐指数
3
解决办法
1万
查看次数

Ansible 在 Windows 主机上创建一个 zip 文件备份

我想将 windows 目录压缩为 zip 文件。存档功能不起作用。

对于 Windows,我看到了win_unzip模块,但我没有找到win_zip模块。

我们如何在 Windows 中备份现有文件夹?

  - name: Backup existing install folder to zip 
    archive:
      path:
        - "{{ installdir }}"
      dest: "{{ stragedir }}\\{{ appname }}.zip"
      format: zip 
Run Code Online (Sandbox Code Playgroud)

错误:

 [WARNING]: FATAL ERROR DURING FILE TRANSFER: Traceback (most recent call last):   File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/winrm.py", line 276, in _winrm_exec
self._winrm_send_input(self.protocol, self.shell_id, command_id, data, eof=is_last)   File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/winrm.py", line 256, in
_winrm_send_input     protocol.send_message(xmltodict.unparse(rq))   File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 256, in send_message     raise
WinRMOperationTimeoutError() WinRMOperationTimeoutError
Run Code Online (Sandbox Code Playgroud)

谢谢 SR

windows winrm ansible

4
推荐指数
1
解决办法
4215
查看次数

Rookio Ceph 集群:mon c 可用空间不足消息

RookIO 1.4我在 Kubernetes 1.18 中设置了集群。有 3 个节点,每个节点分配了 1TB 存储。\n创建集群后。当我运行时,ceph status集群状态显示HEALTH_WARNmon c is low on available space

\n

尚未存储任何数据。为什么可用空间状态这么低?如何清除这个错误?

\n
[root@rook-ceph-tools-6bdcd78654-sfjvl /]#  ceph  status\n  cluster:\n    id:     ad42764d-aa28-4da5-a828-2d87205aff08\n    health: HEALTH_WARN\n            mon c is low on available space\n\n  services:\n    mon: 3 daemons, quorum a,b,c (age 37m)\n    mgr: a(active, since 36m)\n    osd: 3 osds: 3 up (since 37m), 3 in (since 37m)\n\n  data:\n    pools:   1 pools, 1 pgs\n    objects: 0 objects, 0 B\n    usage:   3.0 GiB used, …
Run Code Online (Sandbox Code Playgroud)

ceph kubernetes

4
推荐指数
1
解决办法
9631
查看次数

Helm3 模板错误调用包括: template: no template "microservice.labels" Associated with template "gotpl"

我使用命令创建了 helm 3 模板helm create microservice。它有以下文件。

/Chart.yaml
./values.yaml
./.helmignore
./templates/ingress.yaml
./templates/deployment.yaml
./templates/service.yaml
./templates/serviceaccount.yaml
./templates/hpa.yaml
./templates/NOTES.txt
./templates/_helpers.tpl
./templates/tests/test-connection.yaml
Run Code Online (Sandbox Code Playgroud)

根据我的应用程序更新了值文件,当我尝试安装 helm chat 时,它给出以下错误消息。

Error: UPGRADE FAILED: template: microservice/templates/ingress.yaml:20:8: executing "microservice/templates/ingress.yaml" at <include "microservice.labels" .>: error calling include: template: no template "microservice.labels" associated with template "gotpl"
helm.go:75: [debug] template: microservice/templates/ingress.yaml:20:8: executing "microservice/templates/ingress.yaml" at <include "microservice.labels" .>: error calling include: template: no template "microservice.labels" associated with template "gotpl"
Run Code Online (Sandbox Code Playgroud)

这是ingress.yaml文件。

{{- if .Values.ingress.enabled -}}
{{- $fullName := include "microservice.fullname" . -}} …
Run Code Online (Sandbox Code Playgroud)

kubernetes kubernetes-helm kubernetes-ingress nginx-ingress helm3

4
推荐指数
1
解决办法
2万
查看次数

实体框架无法检查CTP5模型兼容性,因为数据库不包含模型元数据

我试图用现有表测试实体框架CTP 5 Code First.

  1. 我定义了模型类和DbContext并运行了应用程序.它创建了数据库和表.
  2. EdmMetadata从数据库中删除了表.
  3. Trusted_Connection=true;Persist Security Info=True在我的连接字符串中添加.
  4. 当我再次运行应用程序时,它给了我这个错误.

__PRE__

如何在没有EdmMetadata表格的情况下运行此应用程序?

entity-framework entity-framework-4 ef-code-first

3
推荐指数
1
解决办法
8597
查看次数

minio direct-csi 在版本“storage.k8s.io/v1”中没有匹配种类“CSIDriver”

我要使用 direct-csi 驱动程序以分布式模式设置 4 节点 minio 集群。根据文档,我尝试创建直接 csi 部署,但失败并显示以下错误消息。我正在使用 Kubernetes v1.17.0 集群。

https://github.com/minio/direct-csi

# DIRECT_CSI_DRIVES=data{1...4} DIRECT_CSI_DRIVES_DIR=/mnt kubectl apply -k github.com/minio/direct-csi
namespace/direct-csi unchanged
storageclass.storage.k8s.io/direct.csi.min.io unchanged
serviceaccount/direct-csi-min-io unchanged
clusterrole.rbac.authorization.k8s.io/direct-csi-min-io unchanged
clusterrolebinding.rbac.authorization.k8s.io/direct-csi-min-io unchanged
configmap/direct-csi-config unchanged
secret/direct-csi-min-io unchanged
service/direct-csi-min-io unchanged
deployment.apps/direct-csi-controller-min-io unchanged
daemonset.apps/direct-csi-min-io unchanged
error: unable to recognize "github.com/minio/direct-csi": no matches for kind "CSIDriver" in version "storage.k8s.io/v1"
Run Code Online (Sandbox Code Playgroud)

如何解决此错误消息?

【更新】查看CIS版本:

kubectl explain CSIDriver
KIND:     CSIDriver
VERSION:  storage.k8s.io/v1beta1
Run Code Online (Sandbox Code Playgroud)

谢谢 SR

kubernetes minio

3
推荐指数
1
解决办法
661
查看次数