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

abiyi's questions

Martin Hope
abiyi
Asked: 2019-10-17 19:43:47 +0800 CST

在 crontab 中运行 xprop:“无法打开显示”

  • 1

我刚刚制作了一个运行良好的 Bash 脚本xprop(由普通用户和 root 运行):

#!/bin/bash
# time tracking BASH script

# current time and date
current_date=$(date --rfc-3339='seconds')

# active window id
window_id=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut --fields 2)

# active window class
wm_class=$(xprop '\t$0\n' -id $window_id WM_CLASS | cut --fields 2)

# active window name
wm_name=$(xprop '\t$0\n' -id $window_id _NET_WM_NAME | cut --fields 2)

echo '"'$current_date'", '$wm_class', '$wm_name

使用以下输出(以普通用户和 root 身份运行):

nelson@triplecero:~$ bash-scripts/time-tracking.sh
"2019-10-16 23:28:41-04:00", "konsole", "nelson@triplecero: ~ — Konsole"

该脚本是从普通用户调用的,crontab但它没有按预期工作,在日志中写入错误消息:"xprop: unable to open display ''"这是当前会话用户未运行 xprop(和任何 GUI 程序)时显示的典型错误消息,情况并非如此,因为我可以xprop以 root 用户身份运行(和任何其他家伙程序)。

crontab(对于普通用户)是这样的:

# m h  dom mon dow   command
  * *    *   *   *   /home/nelson/bash-scripts/time-tracking.sh >> /home/nelson/log/time-tracking.log 2>&1
  * *    *   *   *   window_id=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut --fields 2) 2>&1; echo $window_id >> /home/nelson/log/test.log 2>&1
 

第一行执行时出现以下错误消息time-tracking.log:

xprop:  unable to open display ''
xprop:  unable to open display ''
xprop:  unable to open display ''
"2019-10-16 23:21:01-04:00", ,

而第二个只是在test.log

我做错了什么cron来获取这些错误消息而不是正确的输出?

bash
  • 1 个回答
  • 1854 Views
Martin Hope
abiyi
Asked: 2019-10-12 15:34:28 +0800 CST

识别空闲或最小化进程

  • 0

我想知道某些 GUI 进程是否空闲或在 Linux 中最小化,使用Net-SNMP.

我一直在做研究,据我所知,SNMP 似乎是为监控服务而设计的,而不是普通用户运行的进程。

我发现只有一个 MIB 对象hrSWRunStatus ( RFC 2790 ),它只有四种运行状态:running(1)、runnable(2)、notRunnable(3)和invalid(4),但通过最大化和最小化一些 GUI 进行测试应用程序不会显示它们各自状态的任何变化,事实上,列出的每个进程snmpwalk都有runnable(2)状态,除了一个:snmpd被列为running(1)。

# snmpwalk -v 2c -c public localhost .1.3.6.1.2.1.25.4.2.1.7 | grep "running(1)"
HOST-RESOURCES-MIB::hrSWRunStatus.920 = INTEGER: running(1)
# snmpwalk -v 2c -c public localhost .1.3.6.1.2.1.25.4.2.1.2 | grep 920
HOST-RESOURCES-MIB::hrSWRunName.920 = STRING: "snmpd"

即使使用ps我也看不到我目前正在使用的进程状态的变化(除了htop)。如果htop在终端控制台中运行,比如konsole我正在用 编写文本kate,这些进程都没有状态“ R ”(正在运行或可运行),只有“ S ”(可中断睡眠),我觉得这很奇怪,但是应该是那种方式... https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk112953

那么,在 Linux 中,我怎么知道某个进程是空闲的还是最小化的……?

process-management
  • 1 个回答
  • 184 Views
Martin Hope
abiyi
Asked: 2019-07-24 18:22:21 +0800 CST

Debian Buster 中的 OpenNMS 24 安装:未满足的依赖项

  • 1

尝试在Debian的最新稳定版本中安装OpenNMS的最新版本,按照官方安装说明会导致存储库出现 apt 错误:

root@triplecero:~# apt update
Ign:1 http://nightly.odoo.com/12.0/nightly/deb ./ InRelease
Ign:2 https://debian.opennms.org stable InRelease
Hit:3 http://nightly.odoo.com/12.0/nightly/deb ./ Release
Hit:4 https://debian.opennms.org stable Release
Hit:7 http://ftp.debian.org/debian buster-backports InRelease
Hit:8 http://deb.debian.org/debian buster InRelease
Hit:9 http://repo.mysql.com/apt/debian stretch InRelease
Hit:10 http://deb.debian.org/debian-security buster/updates InRelease
Hit:11 http://deb.debian.org/debian buster-updates InRelease
Hit:12 http://linorg.usp.br/debian-marillat stable InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
W: Conflicting distribution: https://debian.opennms.org stable Release (expected stable but got opennms-24)
root@triplecero:~#

只需将存储库文件中的stable关键字更改为./etc/apt/sources.list.d/opennms.listopennms-24

root@triplecero:~# apt update
Hit:1 http://repo.mysql.com/apt/debian stretch InRelease
Hit:2 http://deb.debian.org/debian buster InRelease
Hit:3 http://deb.debian.org/debian-security buster/updates InRelease
Hit:4 http://ftp.debian.org/debian buster-backports InRelease
Ign:5 http://nightly.odoo.com/12.0/nightly/deb ./ InRelease
Hit:6 http://deb.debian.org/debian buster-updates InRelease
Hit:7 http://nightly.odoo.com/12.0/nightly/deb ./ Release
Hit:9 http://linorg.usp.br/debian-marillat stable InRelease
Ign:10 https://debian.opennms.org opennms-24 InRelease
Get:11 https://debian.opennms.org opennms-24 Release [11.2 kB]
Get:12 https://debian.opennms.org opennms-24 Release.gpg [224 B]
Get:13 https://debian.opennms.org opennms-24/main Sources [3,696 B]
Get:14 https://debian.opennms.org opennms-24/main i386 Packages [25.8 kB]
Get:15 https://debian.opennms.org opennms-24/main i386 Contents (deb) [97.6 kB]
Fetched 138 kB in 18s (7,643 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
root@triplecero:~#

但在那之后,当我尝试安装OpenNMS时,我从 apt 收到依赖错误(尝试安装这些包会导致另一个依赖包错误)。

root@triplecero:~# apt install opennms
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 opennms : Depends: opennms-server (= 24.1.2-1) but it is not going to be installed
           Depends: opennms-webapp-jetty (= 24.1.2-1) but it is not going to be installed
           Recommends: opennms-source (= 24.1.2-1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
root@triplecero:~#

将存储库从 更改opennms-24为opennms-23或opennms-22导致PostgreSQL的另一个未满足的依赖项错误。

似乎很明显Debian OpenNMS存储库已经破坏了依赖包。还有其他选择,或者只需要等待修复......?

debian apt
  • 1 个回答
  • 699 Views
Martin Hope
abiyi
Asked: 2019-06-18 17:35:11 +0800 CST

带有自签名证书的 Apache 2.4 始终重定向到默认虚拟主机

  • 1

我一直在尝试使用 Apache 2.4 制作具有自签名证书的虚拟主机。我尝试了许多设置组合,但无论如何,我在 Firefox 中尝试的每个虚拟主机都会直接进入默认主机(清除缓存后)。我得到的唯一错误消息是在 Apache error.log 中(所有子域虚拟主机日志都没有错误消息):

[Mon Jun 17 19:32:48.866641 2019] [ssl:debug] [pid 3084] ssl_engine_kernel.c(2122): [client 192.168.1.100:57956] AH02044: No matching SSL virtual host for servername subdomain.7d.net found (使用默认/第一个虚拟主机)

当前设置是基于 IP 的虚拟主机(一个物理 IP 地址由默认主机使用,许多虚拟 IP 地址用于许多虚拟主机,一对一)。在此之前,Apache 使用基于名称的虚拟主机,只有一个物理 IP 地址具有相同的行为。

每个虚拟主机都使用自己的自签名证书,在此之前所有虚拟主机都使用一个。由于 SSL 证书,未报告任何错误消息。每个证书都与其对应的名称匹配。OpenSSL 1.1.0用于生成证书。

除了自签名证书 Apache 正在使用Starfield Class 2 Certificate Authority.

没有安装 DNS 服务器,只有一个/etc/hosts文件,每个 IP 地址和主机名都运行良好。

Apache 2.4.25在Debian GNU/Linux «Stretch»上运行。

ports.conf(我尝试将Listed 443指令放在条件块之外,但行为是相同的)。

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80

<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

001-默认-ssl.conf

<IfModule mod_ssl.c>
    #<VirtualHost 192.168.1.201:443>
    <VirtualHost *:443>
        ServerAdmin webmaster@localhost
        ServerName triplecero.7d.net
        #ServerAlias www.7d.net

        DocumentRoot /var/www/html

        LogLevel info ssl:debug

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Include conf-available/serve-cgi-bin.conf

        SSLEngine On

        SSLCertificateFile /etc/ssl/localcerts/triplecero.7d.net.crt
        SSLCertificateKeyFile /etc/ssl/localcerts/triplecero.7d.net.key

        SSLCACertificateFile /etc/ssl/certs/Starfield_Class_2_CA.pem

        SSLVerifyClient optional
        SSLVerifyDepth  10

        SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>

         BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0

    </VirtualHost>
</IfModule>

子域.conf

<VirtualHost 192.168.1.210:433>
#<VirtualHost subdomain.7d.net:433>
    ServerName subdomain.7d.net
    DocumentRoot "/var/www/subdomain"
    DirectoryIndex index.php

    LogLevel info ssl:debug

    CustomLog ${APACHE_LOG_DIR}/subdomain-access.log combined
    ErrorLog ${APACHE_LOG_DIR}/subdomain-error.log

    SSLEngine On

    SSLCertificateFile "/etc/ssl/localcerts/subdomain.7d.net.crt"
    SSLCertificateKeyFile "/etc/ssl/localcerts/subdomain.7d.net.key"

    SSLCACertificateFile "/etc/ssl/certs/Starfield_Class_2_CA.pem"

    SSLVerifyClient optional
    SSLVerifyDepth 10

    <Directory "/var/www/subdomain">
        Redirect "http://subdomain.7d.net" "https://subdomain.7d.net"
        Require all granted
        AllowOverride All
    </Directory>
</VirtualHost>

阿帕奇2状态:

Triplecero:~# apache2ctl -S
虚拟主机配置:
192.168.1.210:433 subdomain.7d.net (/etc/apache2/sites-enabled/grupoglobaleyr.conf:3)

[许多其他虚拟主机省略]

*:80 Triplecero.7d.net (/etc/apache2/sites-enabled/000-default.conf:2)
*:443 是一个 NameVirtualHost
         默认服务器 Triplecero.7d.net (/etc/apache2/sites-enabled/001-default-ssl.conf:3)
         端口 443 namevhost Triplecero.7d.net (/etc/apache2/sites-enabled/001-default-ssl.conf:3)
         端口 443 namevhost Triplecero.7d.net (/etc/apache2/sites-enabled/002-default-tls.conf:2)
服务器根目录:“/etc/apache2”
主文档根目录:“/var/www/html”
主要错误日志:“/var/log/apache2/error.log”
互斥锁默认:dir="/var/run/apache2/" 机制=默认
互斥体 mpm-accept: using_defaults
互斥体 fcgid 管道:using_defaults
互斥看门狗回调:using_defaults
互斥体重写映射:using_defaults
Mutex ssl-stapling-refresh: using_defaults
互斥 gnutls-cache: using_defaults
互斥 gnutls-ocsp: using_defaults
互斥锁 fcgid-proctbl: using_defaults
互斥 ssl 装订:using_defaults
互斥代理: using_defaults
互斥 ssl 缓存:using_defaults
PidFile:“/var/run/apache2/apache2.pid”
定义:DUMP_VHOSTS
定义:DUMP_RUN_CFG
用户:name="www-data" id=33
组:name="www-data" id=33
三重奏:~#

子域-error.log

[Tue Jun 18 00:05:46.274025 2019] [ssl:info] [pid 3050] AH01914:为 SSL 协议配置服务器 subdomain.7d.net:443
[2019 年 6 月 18 日星期二 00:05:46.274415] [ssl:debug] [pid 3050] ssl_engine_init.c(1756): AH02209: CA 证书: OU=Starfield Class 2 Certification Authority,O=Starfield Technologies\\, Inc., C=美国
[2019 年 6 月 18 日星期二 00:05:46.274481] [ssl:debug] [pid 3050] ssl_engine_init.c(413): AH01893: 配置 TLS 扩展处理
[Tue Jun 18 00:05:46.340584 2019] [ssl:debug] [pid 3050] ssl_util_ssl.c(443): AH02412: [subdomain.7d.net:443] 名称“subdomain.7d.net”的证书匹配 [主题:emailAddress=triplecerogmail.com,CN=subdomain.7d.net,OU=Development,O=ZZZ Corp.,L=Skycity,ST=Highstate,C=XX / 发行人:emailAddress=triplecerogmail.com,CN=subdomain。 7d.net,OU=Development,O=ZZZ Corp.,L=Skycity,ST=Highstate,C=XX / 序列号:B06BB41BBE840955 / 之前:格林威治标准时间 2019 年 6 月 16 日 22:00:11 / 之后:6 月 15 日 22:00:格林威治标准时间 2020 年 11 月]
[Tue Jun 18 00:05:46.340606 2019] [ssl:info] [pid 3050] AH02568:从 /etc/ssl/localcerts/subdomain.7d.net 配置的证书和私钥 subdomain.7d.net:443:0。 crt 和 /etc/ssl/localcerts/subdomain.7d.net.key
debian apache-httpd
  • 2 个回答
  • 1873 Views
Martin Hope
abiyi
Asked: 2018-12-03 19:05:41 +0800 CST

在命令替换中查找:while 中的空结果,结果在命令行中

  • 0

我有这个 bash 脚本来查找由 PhotoRec 恢复的文件(我知道的文件在那里,但由于它们的编号我无法一个一个地找到它们),但是如果我逐个运行 find 命令不会返回任何结果一个脚本行,(while 循环除外)每一个都有效......除了查找。我正在使用 SystemRescueCd,所以我将zsh更改为bash,但即使如此,奇怪的行为也没有改变。

这是 bash 脚本无法正常工作:

#!/bin/bash

findpath="/media/samsung/recup_dir.2/"
echo "FIND PATH: $findpath"

fileslistfile="/media/windows2/photorec-created-files.txt"
rm -rf "$fileslistfile"
touch "$fileslistfile"
echo "FILES LIST FILE: $fileslistfile"
echo "* * * * *"

while IFS= read -r line; do
    echo "LINE: $line"
    #echo "$line" >> "$fileslistfile"

    uncreatedfile=$(basename "$line")
    echo "UNCREATED FILE: $uncreatedfile"

    # this command doesn't return any result
    createdfile=$(find "$findpath" -name "$uncreatedfile" -print)
    echo "CREATED FILE: $createdfile"

    if [ "$createdfile" != "" ]; then
        echo "$createdfile" >> "$fileslistfile"
    else
        echo "$line" >> "$fileslistfile"
    fi
done < "/root/photorec-uncreated-files.txt"

exit 1

这是在 CLI 中执行的命令序列,可以正常工作:

findpath="/media/samsung/recup_dir.1/";
echo "FIND PATH: $findpath";

line="/media/samsung/recup_dir.1/inode_733583/R Jota - Pantomima-kCcgjM55IqA.mp4";
echo "LINE: $line";

uncreatedfile=$(basename "$line");
echo "UNCREATED FILE: $uncreatedfile";

# this command returns a result
createdfile=$(find "$findpath" -name "$uncreatedfile" -print);
echo "CREATED FILE: $createdfile";

if [ "$createdfile" = "" ]; 
then echo "FILE UNCREATED $line"; 
else echo "FILE CREATED $createdfile"; 
fi;

我在IFS=$'\n'的while循环中使用IFS变量,并在find中使用-print和-print0参数(甚至删除两者),结果总是一样的......

所以。为什么相同的命令替换行为不同?bash 脚本中缺少什么?

bash shell-script
  • 1 个回答
  • 341 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