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

lylklb's questions

Martin Hope
lylklb
Asked: 2024-08-05 16:33:57 +0800 CST

为什么 ntptrace 对等体列表与 ntpq 对等体列表不一致?

  • 7

环境:NTP 客户端(AIX 6.1 TL07)+ P/S NTP 服务器(ST1 GPS)。

症状:

  1. 该ntpq -pn命令输出主和辅助(候选)NTP 服务器。
  2. 该ntptrace命令仅输出环回和主 NTP 服务器。

问题:

  1. 为什么即使( )ntptrace peers中没有此条目,环回也会出现在列表中?ntpqntp.conf
  2. 为什么辅助(候选)NTP 服务器条目没有出现在ntptrace peers列表中?
# grep -Ev "^(#|$)" /etc/ntp.conf
driftfile /etc/ntp.drift
tracefile /etc/ntp.trace
server 10.16.27.24
server 10.18.12.15
# ntpq -pn
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
*10.16.27.24   .GPS.            1 -   42  128  377     0.98   -0.078    0.11
+10.18.12.15   .GPS.            1 -   20   16  377     1.89   -0.056    0.41
# ntptrace
loopback: stratum 2, offset -0.000290, synch distance 0.00131
10.16.27.24: stratum 1, offset -0.000308, synch distance 0.00000, refid 'GPS'
aix
  • 2 个回答
  • 176 Views
Martin Hope
lylklb
Asked: 2024-07-21 21:18:10 +0800 CST

为什么使用本地时钟的ntp服务器必须使用默认的环回ip(127.127.1.0)?

  • 9

看来使用本地时钟的 ntp 服务器必须使用默认的环回 ip 地址 (127.127.1.0)。
如果我使用 ntp 服务器的本地以太网 ip 地址作为源本地时钟,它就会卡在 .INIT. 状态。

root@THCDB:/root# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           5 l   53   64    1    0.000    0.000   0.000
root@THCDB:/root# grep ^server /etc/ntp.conf
server 127.127.1.0
root@THCDB:/root# sed -i '/^server/s/127.127.1.0/172.25.180.170/' /etc/ntp.conf
root@THCDB:/root# grep ^server /etc/ntp.conf
server 172.25.180.170
root@THCDB:/root# service ntpd restart
Shutting down ntpd:                                        [  OK  ]
Starting ntpd:                                             [  OK  ]
root@THCDB:/root# ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 172.25.180.170  .INIT.          16 u    -   64    0    0.000    0.000   0.000
root@THCDB:/root# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 THCDB          .INIT.          16 u    -   64    0    0.000    0.000   0.000
ntp
  • 1 个回答
  • 649 Views
Martin Hope
lylklb
Asked: 2024-07-08 21:08:28 +0800 CST

为什么 ntpq -c 子命令输出没有收到任何内容,但仍然可以正确同步其时间

  • 5

环境:RHEL 6.4 带有 ntp-4.2.6p5-15.el6_10.x86_64
问题:以下 ntp 客户端可以将其时间同步到远程 ntp 服务器,但是为什么它无法与远程 ntp 服务器运行 ntpq -c 子命令?

# 
# 
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*10.130.22.10    .GPS.            1 u   17 1024  377    0.859   -0.178   0.428
# 
# 
# ntpq -n -cas 

ind assid status  conf reach auth condition  last_event cnt
===========================================================
  1 15314  963a   yes   yes  none  sys.peer    sys_peer  3
# 
# 
# 
# ntpq 
ntpq> as

ind assid status  conf reach auth condition  last_event cnt
===========================================================
  1 15314  963a   yes   yes  none  sys.peer    sys_peer  3
ntpq> 
ntpq> 
ntpq> quit
# 
# 
# 
# ntpq 10.130.22.10
ntpq> as
10.130.22.10: timed out, nothing received
***Request timed out
ntpq> 
ntpq> 
ntpq> pe
10.130.22.10: timed out, nothing received
***Request timed out
ntpq> 
ntpq> 
ntpq> quit
# 
# 
ntp
  • 1 个回答
  • 21 Views
Martin Hope
lylklb
Asked: 2024-06-26 20:58:06 +0800 CST

对部分标准输出在过渡期内重新定向的质疑

  • 3

如何保留过渡期间的完整 stdout 输出?
如下面典型的例子,你可以看到 yum 元数据刷新状态不会重定向到其 yr.log。
所以我的问题是如何在过渡期间保留这些输出。

# 
# yum  -v repolist
Not loading "rhnplugin" plugin, as it is disabled
Not loading "product-id" plugin, as it is disabled
Loading "refresh-packagekit" plugin
Loading "security" plugin
Not loading "subscription-manager" plugin, as it is disabled
Config time: 0.015
Yum Version: 3.2.29
RHEL_6.4_x86-64                                    | 3.9 kB     00:00 ... 
RHEL_6.4_zlocal                                    | 2.9 kB     00:00 ... 
Setting up Package Sacks
pkgsack time: 0.012
Repo-id      : RHEL_6.4_x86-64
Repo-name    : RHEL_6.4_x86-64_dvd_all
Repo-revision: 1359576928
Repo-updated : Thu Jan 31 04:22:56 2013
Repo-pkgs    : 3,648
Repo-size    : 3.2 G
Repo-baseurl : file:///mnt/
Repo-expire  : 21,600 second(s) (last: Wed Jun 26 08:26:11 2024)

Repo-id      : RHEL_6.4_zlocal
Repo-name    : RHEL_6.4_x86-64_dvd_zlocal
Repo-revision: 1715738735
Repo-updated : Wed Mar 31 17:26:56 2021
Repo-pkgs    : 3,720
Repo-size    : 3.2 G
Repo-baseurl : file:///install/rhel_6.4_x86_64/
Repo-expire  : 21,600 second(s) (last: Wed Jun 26 08:26:11 2024)

repolist: 7,368
# 
# 
# 
# yum -v repolist 1> /tmp/yr.log 2> /tmp/yr.err
# 
# 
# cat /tmp/yr.log
Not loading "rhnplugin" plugin, as it is disabled
Not loading "product-id" plugin, as it is disabled
Loading "refresh-packagekit" plugin
Loading "security" plugin
Not loading "subscription-manager" plugin, as it is disabled
Config time: 0.069
Yum Version: 3.2.29
Setting up Package Sacks
pkgsack time: 0.712
Repo-id      : RHEL_6.4_x86-64
Repo-name    : RHEL_6.4_x86-64_dvd_all
Repo-revision: 1359576928
Repo-updated : Thu Jan 31 04:22:56 2013
Repo-pkgs    : 3,648
Repo-size    : 3.2 G
Repo-baseurl : file:///mnt/
Repo-expire  : 21,600 second(s) (last: Wed Jun 26 15:24:26 2024)

Repo-id      : RHEL_6.4_zlocal
Repo-name    : RHEL_6.4_x86-64_dvd_zlocal
Repo-revision: 1715738735
Repo-updated : Wed May 15 10:06:56 2024
Repo-pkgs    : 3,720
Repo-size    : 3.2 G
Repo-baseurl : file:///install/rhel_6.4_x86_64/
Repo-expire  : 21,600 second(s) (last: Wed Jun 26 15:24:27 2024)

repolist: 7,368
# 
io-redirection
  • 1 个回答
  • 54 Views
Martin Hope
lylklb
Asked: 2024-06-16 20:20:26 +0800 CST

如何检查 RHEL 5 中的一些 yum 配置变量

  • 5

在 RHEL 6 以上版本中,我们可以使用 yum-config-manager 来检查 yum 配置变量...
但在 RHEL 5 中,没有 yum-config-manager 这个程序,而且 yum-debug-dump 和 python 都无法实现这样的功能。

这里仅以 RHEL 6 为例:

# 
# yum-config-manager  main|grep -Ei "metadata|keep"
keepalive = True
keepcache = False
metadata_expire = 21600
# 
yum
  • 1 个回答
  • 25 Views
Martin Hope
lylklb
Asked: 2024-05-21 21:08:11 +0800 CST

关于yum repolist强制刷新状态机制的疑问

  • 5

我注意到,每次使用 yum repolist 运行很长一段时间间隔时,都会有一个额外的“刷新状态”过程...
注意:这里的“长时间间隔”是指大约几天(至少超过 3 天) ),但不是几个小时......

# 
# yum repolist                                                                    <<<  a few days interval
Loaded plugins: security, verify
Cluster                                                                                                                                    | 1.5 kB     00:00     
ClusterStorage                                                                                                                             | 1.5 kB     00:00     
RHEL_5.8_local                                                                                                                             |  951 B     00:00     
Server                                                                                                                                     | 1.5 kB     00:00     
VT                                                                                                                                         | 1.3 kB     00:00     
repo id                                                                               repo name                                                                                 status
Cluster                                                                               Cluster_r58                                                                                  32
ClusterStorage                                                                        ClusterStorage_r58                                                                           39
RHEL_5.8_local                                                                        RHEL_5.8_x86-64_all_local                                                                 3,414
Server                                                                                Server_r58                                                                                3,285
VT                                                                                    VT_r58                                                                                       58
repolist: 6,828
# 
# 
# yum repolist                                                                    <<<  a few hours interval
Loaded plugins: security, verify
repo id                                                                               repo name                                                                                 status
Cluster                                                                               Cluster_r58                                                                                  32
ClusterStorage                                                                        ClusterStorage_r58                                                                           39
RHEL_5.8_local                                                                        RHEL_5.8_x86-64_all_local                                                                 3,414
Server                                                                                Server_r58                                                                                3,285
VT                                                                                    VT_r58                                                                                       58
repolist: 6,828
# 

更新:

这真的很奇怪,我的 yum 存储库元数据生命周期只是默认的 3600 秒,
所以这里如何解释我的 yum 存储库元数据实际生命周期而不是默认生命周期?
# yum -v repolist
Not loading "katello" plugin, as it is disabled
Not loading "product-id" plugin, as it is disabled
Not loading "rhnplugin" plugin, as it is disabled
Loading "security" plugin
Not loading "subscription-manager" plugin, as it is disabled
Loading "verify" plugin
Config time: 0.068
Yum Version: 3.2.22
Cluster                                                                                                                                                                                                                                                | 1.5 kB     00:00     
ClusterStorage                                                                                                                                                                                                                                         | 1.5 kB     00:00     
Server                                                                                                                                                                                                                                                 | 1.5 kB     00:00     
VT                                                                                                                                                                                                                                                     | 1.3 kB     00:00     
Setting up Package Sacks
pkgsack time: 0.032
Repo-id      : Cluster
Repo-name    : Cluster_r58
Repo-updated : Fri Feb  3 02:38:19 2012
Repo-pkgs    : 32
Repo-size    : 83 M
Repo-baseurl : file:///mnt/Cluster/
Repo-expire  : 3,600 second(s) (last: Fri May 24 18:27:23 2024)

Repo-id      : ClusterStorage
Repo-name    : ClusterStorage_r58
Repo-updated : Fri Feb  3 02:39:28 2012
Repo-pkgs    : 39
Repo-size    : 11 M
Repo-baseurl : file:///mnt/ClusterStorage/
Repo-expire  : 3,600 second(s) (last: Fri May 24 18:27:23 2024)

Repo-id      : RHEL_5.8_local
Repo-name    : RHEL_5.8_x86-64_all_local
Repo-updated : Tue Apr 23 10:43:03 2024
Repo-pkgs    : 3,414
Repo-size    : 3.6 G
Repo-baseurl : file:///install/rhel_5.8_x86-64_local
Repo-expire  : 3,600 second(s) (last: Fri May 24 18:20:41 2024)

Repo-id      : Server
Repo-name    : Server_r58
Repo-updated : Fri Feb  3 02:39:04 2012
Repo-pkgs    : 3,285
Repo-size    : 3.3 G
Repo-baseurl : file:///mnt/Server/
Repo-expire  : 3,600 second(s) (last: Fri May 24 18:27:23 2024)

Repo-id      : VT
Repo-name    : VT_r58
Repo-updated : Fri Feb  3 02:38:17 2012
Repo-pkgs    : 58
Repo-size    : 193 M
Repo-baseurl : file:///mnt/VT/
Repo-expire  : 3,600 second(s) (last: Fri May 24 18:27:23 2024)

repolist: 6,828
#
yum
  • 1 个回答
  • 18 Views
Martin Hope
lylklb
Asked: 2024-05-16 21:20:42 +0800 CST

为什么 yum list 输出中的某些软件包的第三列在 RHEL 6/7 下“已安装”

  • 5

其实,上述问题标题中可能包含以下两个子问题:
1) rpm 包结构的开发设计如何,是否会导致 repoquery -i 输出为空?
2) 如果 rpm 包结构中没有“from_repo”属性,是否会导致通过 yum list 得到“installed”?

#
#  
# yum list installed|grep -i installed
Installed Packages
storcli.x86_64                     007.1108.0000.0000-1           installed     
# 
# 
# 
# yum list installed|grep -i zabbix
zabbix-agent.x86_64                4.0.2-1.el7                    @zabbix  
# 
# 
# 
# yum info storcli.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : storcli
Arch        : x86_64
Version     : 007.1108.0000.0000
Release     : 1
Size        : 7.1 M
Repo        : installed
Summary     : Storage Command Line Tool.
URL         : http://www.avagotech.com
License     : AVAGO Technologies
Description : storcli is used to manage storage controllers.

# 
# 
# yumdb info storcli.x86_64
Loaded plugins: fastestmirror
storcli-007.1108.0000.0000-1.x86_64
# 
# 
# 
# repoquery -i  storcli.x86_64
# 
# 
# repoquery -i  storcli.x86_64
# 
# 
# yum info zabbix-agent.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : zabbix-agent
Arch        : x86_64
Version     : 4.0.2
Release     : 1.el7
Size        : 1.5 M
Repo        : installed
From repo   : zabbix
Summary     : Zabbix Agent
URL         : http://www.zabbix.com/
License     : GPLv2+
Description : Zabbix agent to be installed on monitored systems.

# 
# 
# repoquery -i zabbix-agent.x86_64

Name        : zabbix-agent
Version     : 4.0.2
Release     : 1.el7
Architecture: x86_64
Size        : 1559464
Packager    : None
Group       : Applications/Internet
URL         : http://www.zabbix.com/
Repository  : zabbix
Summary     : Zabbix Agent
Source      : zabbix-4.0.2-1.el7.src.rpm
Description :
Zabbix agent to be installed on monitored systems.
# 
# 
yum
  • 2 个回答
  • 30 Views
Martin Hope
lylklb
Asked: 2023-07-24 20:56:00 +0800 CST

为什么 ksh93 在 AIX 中不支持其内置 printf 的 %T 格式说明符?

  • 9

我们在许多 AIX 5.3/6.1 系统中使用 ksh93 测试了以下命令printf,但它们都失败并得到相同的结果。

这是为什么?

# 
# oslevel -s                               
6100-07-09-1341
# 
# 
# ksh93 -c 'echo ${.sh.version}'
Version M-12/28/93e
# 
# 
# ksh93 -c 'printf "%T\n" "now"'      
ksh93[1]: printf: T: unknown format specifier
# 
# 
ksh
  • 2 个回答
  • 387 Views
Martin Hope
lylklb
Asked: 2023-06-15 21:01:36 +0800 CST

如何使用 find -exec 命令通过 sh -c 'grep ...' 获取指定的输出格式

  • 5

我们想要 grep 包含一些固定字符串的相应文件,然后仅以 ls -l 格式输出这些文件。
例如:
A) 以下方法使用多个 -exec 输出 grep 和 ls -l。

# 
# 
# find /usr/bin -type f -exec grep -Eil '#\!\/usr\/bin\/csh' {} \; -exec ls -l  {} \; >scripts_csh_list 2>&1
# 
# 
# 
# cat scripts_csh_list      
/usr/bin/which
-r-xr-xr-x    1 bin      bin            1191 Sep 06 2007  /usr/bin/which
#  
#  

B) 但我们希望仅使用 ls -l ... 获得更好的方法输出,然后通过 sh -c 'grep ... {}' 失败
注意:find -exec 的以下所有不同组合命令 .. .输出相同的失败结果。

#                                                                                                                
# 
# find /usr/bin -type f -exec sh -c 'grep -Eil '\/usr\/bin\/csh' {} && ls -ltr  {}' \; >scripts_csh_list 2>&1t
#  
# 
# tail -6 scripts_csh_list
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
# 
# 
# 
# find /usr/bin -type f -exec sh -c ' grep -Eil '\/usr\/bin\/csh' {} '  \; >scripts_csh_list 2>&1  
# 
# 
# tail -6 scripts_csh_list                                                                         
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
# 
# 
# find /usr/bin -type f -exec sh -c ' grep -Eil '\/usr\/bin\/csh' "{}" '  \; >scripts_csh_list 2>&1  
# 
# 
# tail -6 scripts_csh_list                                                                         
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
# 
# 
# 
# find /usr/bin -type f -exec sh -c " grep -Eil '\/usr\/bin\/csh' {} "  \; >scripts_csh_list 2>&1  
# 
# 
# tail -6 scripts_csh_list                                                                         
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
# 
# 
# 
# find /usr/bin -type f -exec sh -c " grep -Eil '\/usr\/bin\/csh' {} "  \; >scripts_csh_list 2>&1  
# 
# 
# tail -6 scripts_csh_list                                                                         
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
# 
# 
shell
  • 2 个回答
  • 30 Views
Martin Hope
lylklb
Asked: 2023-06-13 20:48:15 +0800 CST

如何使用grep的-E选项匹配一些变量名

  • 5

我们想知道通过使用 grep -E 选项来匹配一些变量名(包括它的 $ 前缀)的正确方法。
似乎这个 grep macthing 函数只能在没有任何选项或 -e 选项的情况下工作......

> 
> 
> grep ""'$'status"" /home/ewpadm/.sapenv_wzwms1.csh
if ( $status == 0 ) then
if ( $status == 0 ) then 
    set rc1 = $status
    set rc2 = $status
    set rc3 = $status
    set rc4 = $status
    set rc5 = $status
    set rc6 = $status
    set rc7 = $status
    set rc8 = $status
> 
> 
> grep -E ""'$'status"" /home/ewpadm/.sapenv_wzwms1.csh
> 
> 
> grep -E """'$'status"""" /home/ewpadm/.sapenv_wzwms1.csh
> 
> 
> grep -e ""'$'status"" /home/ewpadm/.sapenv_wzwms1.csh 
if ( $status == 0 ) then
if ( $status == 0 ) then 
    set rc1 = $status
    set rc2 = $status
    set rc3 = $status
    set rc4 = $status
    set rc5 = $status
    set rc6 = $status
    set rc7 = $status
    set rc8 = $status
> 
> 
> grep -e "= "'$'status"" /home/ewpadm/.sapenv_wzwms1.csh
    set rc1 = $status
    set rc2 = $status
    set rc3 = $status
    set rc4 = $status
    set rc5 = $status
    set rc6 = $status
    set rc7 = $status
    set rc8 = $status
> 
>  
shell
  • 1 个回答
  • 49 Views
Martin Hope
lylklb
Asked: 2022-12-06 04:52:31 +0800 CST

如果正则表达式模式,&& 的逻辑运算符不能在 awk 中工作

  • 5

&& 的逻辑运算符不能在 awk if 正则表达式模式中工作,这与 || 的逻辑运算符相比似乎有点奇怪。可以正常工作!
注意:但是 && 的逻辑运算符可以在纯简单的 awk 正则表达式模式中工作,那为什么呢?

# 
# 
# cat /etc/passwd|awk '$0 ~/[Ss]ystem/ || /puls/ {print $0}'
dbus:x:81:81:System message bus:/:/sbin/nologin
pulse:x:497:495:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
# 
# 
# 
# cat /etc/passwd|awk '$0 ~/[Ss]ystem/ &&  /puls/ {print $0}'
pulse:x:497:495:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
# 
# 
# 
# cat /etc/passwd|awk '$0 ~/[Ss]ystem|puls/ {print $0}'
dbus:x:81:81:System message bus:/:/sbin/nologin
pulse:x:497:495:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
# 
# 
# 
# cat /etc/passwd|awk '{k1[NR]=$0}END{for(i=1;i<=NR;i++)if(k1[i] ~/[Ss]ystem/ || /puls/){print k1[i]}}'
dbus:x:81:81:System message bus:/:/sbin/nologin
pulse:x:497:495:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
# 
# 
# cat /etc/passwd|awk '{k1[NR]=$0}END{for(i=1;i<=NR;i++)if(k1[i] ~/[Ss]ystem/ && /puls/){print k1[i]}}'
# 
# 
# cat /etc/passwd|awk '{k1[NR]=$0}END{for(i=1;i<=NR;i++)if(k1[i] ~/[Ss]ystem/ && /puls/){print k1[i]}}'
# 
# 
# cat /etc/passwd|awk '$0 ~/[Ss]ystem/ &&  /puls/ {print $0}'
pulse:x:497:495:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
# 
# 


现在我稍作修改后,最新的情况可能会变得比以前奇怪得多!
为什么下面带有数组变量和逻辑运算符 && 的相同正则表达式模式可以工作?
注意:这应该可以解释某些 if 正则表达式模式中的 && 问题至少与数组变量本身无关。
# 
# 
# cat /etc/passwd|awk '{k0[NR]=$0;if(k0[NR] ~/[Ss]ystem/ && /puls/){print k0[NR]}}'
pulse:x:497:495:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
# 
# 
# cat /etc/passwd|awk '{k0[NR]=$0;if(k0[NR] ~/[Ss]ystem/ || /puls/){print k0[NR]}}'
dbus:x:81:81:System message bus:/:/sbin/nologin
pulse:x:497:495:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
# 
# 
# cat /etc/passwd|awk '{k0[NR]=$0;if(k0[NR] ~/[Ss]ystem/ && /puls/){print k0[NR]}}'
pulse:x:497:495:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
# 
# 
awk
  • 3 个回答
  • 90 Views
Martin Hope
lylklb
Asked: 2022-09-21 04:26:06 +0800 CST

命令变量的奇怪行为 | awk中的getline

  • -5

问题:命令变量的值li12[q]不能作为自己的实际内容引用。

症状:一旦我真正引用了 的命令变量值li12[q],因此以致命的失败:|重定向表达式具有空字符串值。

笔记:

  1. 但是命令变量li12[q]确实有自己的值,和前面getlinek5的变量一样!
  2. li12[q]由于可以引用命令变量名本身,因此相应的语法和结构应该没有问题。
# 
# 
# lspci -v|grep -Ei "fib|scsi|raid|sas|net|ide|ata"|grep -i ^[0-9]|awk  '{kin1[NR]=$1; prt[NR]="";for(ik=2;ik<=NF;ik++){prt[NR]=prt[NR]$ik" "}}END\
{while("ls -l /sys/class|grep -Ei \"scsi|sas|fc|net|ide|ata\"|grep -Eiv \"disk|tape|device|gen\""|getline){li11[++h1]=$9}; for(i=1;i<=NR;i++)\
{for(s=1;s<=h1;s++){h2=0;d3="(find /sys/class/"li11[s]" -type l -exec bash -c '\''echo s `ls -l {}`'\'' \\;|grep -i devices|grep -Ei \""kin1[i]"(/|$)\")\
2>/dev/null"; while(d3|getline){k5=li12[++h2]=$10$11$12; k6=h2}; for(q=1;q<=h2;q++){if(li12[q] ~/[a-zA-Z]/){ while("echo -e \"li12[q]\""|getline k7); k2=k7; k3=$1;\
if( q == h2 ){s=h1+1}; if(q>1){kin1[i]=prt[i]=""};printf " %-16s%-6s%-16s%-16s%-100s%-16s\n",kin1[i],k6,k5,k3,prt[i],k2}}}}}'
 03:00.0         1     /sys/class/scsi_host/host0/device->../../../devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0s RAID bus controller: Hewlett-Packard Company Smart Array Gen8 Controllers (rev 01)                  li12[q]         
 04:00.0         1     /sys/class/net/eth0/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.0s Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 01)                          li12[q]         
 04:00.1         1     /sys/class/net/eth1/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.1s Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 01)                          li12[q]         
 04:00.2         1     /sys/class/iscsi_host/host3/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.2/host3s Mass storage controller: Emulex Corporation OneConnect 10Gb iSCSI Initiator (be3) (rev 01)          li12[q]         
 04:00.3         1     /sys/class/iscsi_host/host4/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.3/host4s Mass storage controller: Emulex Corporation OneConnect 10Gb iSCSI Initiator (be3) (rev 01)          li12[q]         
 05:00.0         1     /sys/class/fc_host/host1/device->../../../devices/pci0000:00/0000:00:03.0/0000:05:00.0/host1s Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)             li12[q]         
 05:00.1         1     /sys/class/fc_host/host2/device->../../../devices/pci0000:00/0000:00:03.0/0000:05:00.1/host2s Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)             li12[q]         
# 
# 
# 
# lspci -v|grep -Ei "fib|scsi|raid|sas|net|ide|ata"|grep -i ^[0-9]|awk  '{kin1[NR]=$1; prt[NR]="";for(ik=2;ik<=NF;ik++){prt[NR]=prt[NR]$ik" "}}END\         
{while("ls -l /sys/class|grep -Ei \"scsi|sas|fc|net|ide|ata\"|grep -Eiv \"disk|tape|device|gen\""|getline){li11[++h1]=$9}; for(i=1;i<=NR;i++)\
{for(s=1;s<=h1;s++){h2=0;d3="(find /sys/class/"li11[s]" -type l -exec bash -c '\''echo s `ls -l {}`'\'' \\;|grep -i devices|grep -Ei \""kin1[i]"(/|$)\")\
2>/dev/null"; while(d3|getline){k5=li12[++h2]=$10$11$12; k6=h2}; for(q=1;q<=h2;q++){if(li12[q] ~/[a-zA-Z]/){ while("echo -e "li12[q]""|getline k7); k2=k7; k3=$1; \
if( q == h2 ){s=h1+1}; if(q>1){kin1[i]=prt[i]=""};printf " %-16s%-6s%-16s%-16s%-100s%-16s\n",kin1[i],k6,k5,k3,prt[i],k2}}}}}'
awk: cmd. line:3: (FILENAME=- FNR=7) fatal: expression for `|' redirection has null string value
# 
#

编辑这里是上面的代码,由@glennjackman 提供的格式更加清晰:

lspci -v \
| grep -Ei "fib|scsi|raid|sas|net|ide|ata" \
| grep -i ^[0-9] \
| awk  '
    {
        kin1[NR] = $1
        prt[NR] = ""
        for (ik = 2; ik <= NF; ik++) {prt[NR] = prt[NR] $ik " "}
    }
    END {
        while ("ls -l /sys/class | grep -Ei \"scsi|sas|fc|net|ide|ata\" | grep -Eiv \"disk|tape|device|gen\"" | getline) {
            li11[++h1] = $9
        }
        for (i = 1; i <= NR;i++) {
            for (s = 1; s <= h1;s++) {
                h2 = 0
                d3 = "(find /sys/class/"li11[s]" -type l -exec bash -c '\''echo s `ls -l {}`'\'' \\; | grep -i devices | grep -Ei \""kin1[i]"(/|$)\") 2>/dev/null"
                while (d3 | getline){
                    k5 = li12[++h2] = $10 $11 $12
                    k6 = h2
                }
                for (q = 1; q <= h2;q++){
                    if (li12[q] ~/[a-zA-Z]/) {
                        while ("echo -e "li12[q]"" | getline k7)
                            k2 = k7
                        k3 = $1
                        if (q == h2) {s = h1+1}
                        if (q > 1) {kin1[i] = prt[i] = ""}
                        printf " %-16s%-6s%-16s%-16s%-100s%-16s\n", kin1[i], k6, k5, k3, prt[i], k2
                    }
                }
            }
        }
    }
'

现在,在 RHEL 6.4 系统上使用上述相同的 awk 脚本会出现不同的失败结果/进度。
注意:所有先前关于相同空字符串值的失败结果都只在 RHEL 5.8 系统上运行。
sh: ../../../devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0: No such file or directory
 03:00.0         1     /sys/class/scsi_host/host0/device->../../../devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0s               RAID bus controller: Hewlett-Packard Company Smart Array Gen8 Controllers (rev 01)                                  
sh: ../../../devices/pci0000:00/0000:00:02.0/0000:04:00.0: No such file or directory
 04:00.0         1     /sys/class/net/eth0/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.0s               Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 01)                                          
sh: ../../../devices/pci0000:00/0000:00:02.0/0000:04:00.1: No such file or directory
 04:00.1         1     /sys/class/net/eth1/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.1s               Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 01)                                          
sh: ../../../devices/pci0000:00/0000:00:02.0/0000:04:00.2/host3: No such file or directory
 04:00.2         1     /sys/class/iscsi_host/host3/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.2/host3s               Mass storage controller: Emulex Corporation OneConnect 10Gb iSCSI Initiator (be3) (rev 01)                          
sh: ../../../devices/pci0000:00/0000:00:02.0/0000:04:00.3/host4: No such file or directory
 04:00.3         1     /sys/class/iscsi_host/host4/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.3/host4s               Mass storage controller: Emulex Corporation OneConnect 10Gb iSCSI Initiator (be3) (rev 01)                          
sh: ../../../devices/pci0000:00/0000:00:03.0/0000:05:00.0/host1: No such file or directory
 05:00.0         1     /sys/class/fc_host/host1/device->../../../devices/pci0000:00/0000:00:03.0/0000:05:00.0/host1s               Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)                             
sh: ../../../devices/pci0000:00/0000:00:03.0/0000:05:00.1/host2: No such file or directory
 05:00.1         1     /sys/class/fc_host/host2/device->../../../devices/pci0000:00/0000:00:03.0/0000:05:00.1/host2s               Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)  
awk
  • 2 个回答
  • 66 Views
Martin Hope
lylklb
Asked: 2019-03-21 07:06:34 +0800 CST

为什么partx无法读取某些磁盘的分区表

  • 2

partx无法读取/dev/sdb此系统上的分区表。为什么它返回如下所示的“读取分区表失败”,而不是null/empty?这种“失败”的结果是否总是意味着设备的分区表已损坏?

注意:这里sdb可以在没有任何分区的情况下作为LVM正常工作!

    # pvs
      PV         VG                                        Fmt  Attr PSize    PFree  
      /dev/sda3  vgroot                                    lvm2 a--    89.00g   4.00m
      /dev/sda4  vgroot                                    lvm2 a--   746.78g 746.78g
      /dev/sdb   vgdata                                    lvm2 a--  <836.99g      0 

    # 
    # 
    # sfdisk -l /dev/sdb

    Disk /dev/sdb: 109262 cylinders, 255 heads, 63 sectors/track
    # 
    #
    # sfdisk -l /dev/sda

    Disk /dev/sda: 109262 cylinders, 255 heads, 63 sectors/track
    Units: cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

       Device Boot Start     End   #cyls    #blocks   Id  System
    /dev/sda1          0+ 109262- 109263- 877647871+  ee  GPT
    sfdisk:                 start: (c,h,s) expected (0,0,2) found (0,0,1)

    /dev/sda2          0       -       0          0    0  Empty
    /dev/sda3          0       -       0          0    0  Empty
    /dev/sda4          0       -       0          0    0  Empty
    # 
    # 
    # partx -s /dev/sdb 
    partx: /dev/sdb: failed to read partition table
    # 
    # partx -s /dev/sda
    NR     START        END    SECTORS   SIZE NAME                 UUID
     1      2048     411647     409600   200M EFI System Partition 255f05dd-3c30-4eb5-b4ef-e222216eb27e
     2    411648    2508799    2097152     1G                      0eba1772-1106-4a63-bad6-6d20be988dba
     3   2508800  189171711  186662912    89G                      39fab8c9-bd96-47a2-b5db-495e43159055
     4 189171712 1755295710 1566123999 746.8G                      9e3d6237-5c7f-4443-8b60-b258052a8b32

    # 
    # 
    # pvdisplay /dev/sdb
      --- Physical volume ---
      PV Name               /dev/sdb
      VG Name               vgdata
      PV Size               836.99 GiB / not usable 2.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              214269
      Free PE               0
      Allocated PE          214269
      PV UUID               IsOr0G-UBTt-Qn1E-bx6R-dzvY-HqSE-bNiCaq

    # 
    # 
    # lsb_release -a
        LSB Version:    :core-4.1-amd64:core-4.1-noarch
        Distributor ID: RedHatEnterpriseServer
        Description:    Red Hat Enterprise Linux Server release 7.4 (Maipo)
        Release:        7.4
        Codename:       Maipo
    # 
    # 

另一个系统场景:

下面的partx可以不带分区直接输出null/empty,为什么?
注意:下面的sdb也可以作为LVM不带分区正常工作!

# 
# 
# partx  /dev/sdb
# 
# 
# 
# pvdisplay  /dev/sdb
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vgdoc
  PV Size               600.00 GB / not usable 4.00 MB
  Allocatable           yes (but full)
  PE Size (KByte)       4096
  Total PE              153599
  Free PE               0
  Allocated PE          153599
  PV UUID               mMPvrE-NBP5-9n3J-77w5-57p0-1R7E-ggFCEj

# 
#  
# 
# lsb_release -a
LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Release:        5.5
Codename:       Tikanga
# 
# 

1)我的想法是,如果磁盘真的没有分区,partx 不应该以“读取失败...”退出。
注意:如您所见,partx 仅在具有非分区磁盘的另一个系统中输出 null/empty。

2)在磁盘分区上可以创建和使用PV/LVM是正常的,不是吗?

 Device Boot Start     End   #cyls    #blocks   Id  System
   /dev/sda1   *      0+     25-     26-    204800   83  Linux
   /dev/sda2         25+  36404-  36380- 292215808   8e  Linux LVM
partition sfdisk
  • 1 个回答
  • 2199 Views
Martin Hope
lylklb
Asked: 2018-06-07 06:42:58 +0800 CST

shell 脚本中的最后一个命令行,没有换行符

  • 4

uptime为什么在文件末尾没有换行符的情况下,shell 脚本中的最后一个命令行(如下)可以成功执行?

例如:

root@jcdb:/tmp# 
root@jcdb:/tmp# 
root@jcdb:/tmp# cat dp
date
pwd
uptimeroot@jcdb:/tmp# 
root@jcdb:/tmp# 
root@jcdb:/tmp# 
root@jcdb:/tmp# ./dp
Wed Jun  6 16:27:26 EAT 2018
/tmp
  4:27pm  up 1 day, 17:25,  2 users,  load average: 0.39, 0.40, 0.41
root@jcdb:/tmp# 
root@jcdb:/tmp#
shell-script
  • 1 个回答
  • 783 Views
Martin Hope
lylklb
Asked: 2017-12-03 00:56:25 +0800 CST

如果未引用 -name 后面的模式,则 find 的奇怪行为

  • 0

奇怪的是,有时 find 中的以下 -name 模式会意外地成功搜索所有相应的文件名。按权利,它只能通过shell parse在当前目录中搜索一个对应的文件名(找不到不带引号的实用程序)。

find /tmp -type f -name *.txt

/tmp/amp_iostat.txt
/tmp/awrrpt_1_7950_7973.txt
/tmp/oplanlog/osys/2014-07-01-12-26-28/log.txt
/tmp/oplanlog/osys/2014-07-01-13-15-33/log.txt
/tmp/oplanlog/osys/2014-07-01-13-17-58/log.txt
/tmp/oplanlog/osys/2014-07-01-13-30-27/log.txt
/tmp/oplanlog/osys/2016-10-27-19-38-50/log.txt
/tmp/pms2_20170427.txt
/tmp/pmsdb1_20170622.txt
/tmp/pmssh1_20160728.txt
/tmp/pmssh1_20160831.txt
/tmp/pmssh1_20161227.txt
/tmp/pmssh1_20170328.txt
/tmp/pmssh1_20170523.txt
/tmp/pmssh1_20170727.txt
/tmp/pmssh1_20170822.txt
/tmp/pmssh2_20170328.txt
/tmp/pmssh_20170119.txt
/tmp/pmssh_20170220.txt
/tmp/sgpms_20140717_1736_summary.txt
/tmp/sgpms_20140717_1736_trace.txt
/tmp/sgpms_20140717_1737_summary.txt
/tmp/sgpms_20140717_1737_trace.txt
/tmp/sgpms_20140717_1739_summary.txt
/tmp/sgpms_20140717_1739_trace.txt
/tmp/sgpms_20140717_1743_summary.txt
/tmp/sgpms_20140717_1743_trace.txt
/tmp/sgpms_20140717_1749_summary.txt
/tmp/sgpms_20140717_1749_trace.txt
/tmp/sgpms_20140717_1751_summary.txt
/tmp/sgpms_20140717_1751_trace.txt

find /tmp -type f -name *.txt|wc -l
      31
find
  • 1 个回答
  • 69 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