我有一台运行 OpenSUSE 12.1、64 位、默认安装的计算机。
目前它是如何工作的:
问题是这个提示有超时,所以我必须坐在电脑旁边,注意发生了什么。
如何禁用该计时器,例如,我可以打开计算机并离开,然后在 1 小时后返回并仍然看到此提示?
我正在使用亚马逊 Linux,
[davea@mymachine ~]$ uname -a
Linux mymachine.mydomein.org 4.4.35-45.83.amzn1.x86_64 #1 SMP Wed Jul 27 22:37:49 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
在我的 /etc/ssh/sshd_config 中,我没有为“ServerAliveInterval”设置值。在这个答案中 - sshd_config 中的 `ServerAliveInterval` 和 `ClientAliveInterval` 选项究竟做了什么?,他们说“将值设置为 0(默认值)将禁用这些功能,因此如果连接空闲时间过长,您的连接可能会断开”。这意味着什么?准确地说,如果提交此参数,连接将保持活动的默认时间是多少?假设我在客户端设置了一个值“1000000000000”。
我想在同一命令上执行这两个超时命令,但时间和指令不同。所以
timeout --signal=SIGINT 5s command
timeout --signal=SIGKILL 10s command
Run Code Online (Sandbox Code Playgroud)
如何将它们附加到一行中?
我正在使用dig实用程序来查找公共 IP 地址。
我使用的命令是:
dig +short myip.opendns.com @resolver1.opendns.com
Run Code Online (Sandbox Code Playgroud)
但我遇到了问题,因为在其他一些计算机上花了很长时间,所以我在 5 秒后添加了超时:
dig +short +time=5 +tries=1 myip.opendns.com @resolver1.opendns.com
Run Code Online (Sandbox Code Playgroud)
它在某些计算机上按预期失败,但在其他一些计算机上它永远不会完成。它所做的只是挂起......
知道为什么以及如何将其修复为预期的 5 秒后超时吗?
编辑:
已经尝试过timeout,但仍然挂起。我认为解析 DNS 时它会卡住。例如,我不能ping www.google.com,但可以172.217.20.4。
I have a written a shell script that helps me calculate the disk utilization in remote servers using df -h. I'm including the code snippet below
s_arch_1_per=`sshpass -p 'password' ssh root@server_ip_1 "df -h | grep '/Archive_1'| awk '{print $ (NF-1)}'"`
master_per=`sshpass -p 'password' ssh nidhal@server_ip_2 "df -h | grep '/dev/mapper/centos-root'| awk '{print $ (NF-1)}'"`
arch_5_per=`df -h | grep '/archive_1'| awk '{print $ (NF-1)}'`
Run Code Online (Sandbox Code Playgroud)
The problem is either in the local or remote system the execution of df -h sometimes …
我试图找到一种简单的方法来在一定时间后重复重新启动命令(就本问题而言,假设为 10 秒)。为了简单起见,我们假设有问题的命令是htop --tree。
到目前为止,我的尝试是:一旦找到命令,就运行然后停止命令timeout,因此timeout 10 htop --tree运行命令并在 10 秒后再次停止。重复一下,我找到了一个命令watch,它可以让您在每个给定的时间间隔重新运行命令。所以我的尝试是将两者结合起来使用
watch -n 10 `timeout 9 htop --tree`
Run Code Online (Sandbox Code Playgroud)
但随后它的输出htop不显示。任何人都可以看到我做错了什么或如何解决这个问题,或者为我想要实现的目标提出替代的 bash 解决方案?
在 Bash 中,这将为慢命令设置 10 秒的时间限制
timeout 10 slowcommand
Run Code Online (Sandbox Code Playgroud)
我想知道如何获得相同的行为,如果我必须调用sudo才能运行slowcommand,即:
timeout 10 sudo slowcommand
Run Code Online (Sandbox Code Playgroud)
这将限制sudo,而不是slowcommand ......在使用 sudo 时有没有一种优雅的方法来做到这一点?
编辑:假设不允许使用 sudo 运行超时。
我遇到一个问题,在极少数情况下,我的Type=simplesystemd 服务会挂起或陷入循环。这会导致其计时器停止调度服务,因为正如通过 确认的那样sudo systemctl status myservice,服务在应该早已退出的情况下仍在运行。我还没有弄清楚这个错误,但这并不重要。但与此同时,我不希望它停止安排未来的运行。
有没有办法在 systemd 服务文件中指定最大运行时间,之后它将强制停止?
[Unit]
Description=scripts should run and exit but occasionally hangs or infinite loop
[Service]
SyslogIdentifier=myservice
Environment='MYVAR=myvar'
User=deanresin
Type=simple
ExecStart=/usr/bin/python3 /home/deanresin/myscript
Run Code Online (Sandbox Code Playgroud) timeout ×8
bash ×2
boot ×1
centos ×1
command-line ×1
dig ×1
disk-usage ×1
dns ×1
encryption ×1
opensuse ×1
password ×1
shell ×1
shell-script ×1
signals ×1
ssh ×1
sshd ×1
systemd ×1
watch ×1