我正在使用亚马逊 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”。
我正在使用 bash shell。我正在尝试编写一个脚本,该脚本将读取一个属性文件,然后根据它在文件中读取的键值对在另一个文件中进行一些替换。所以我有
#!/bin/bash
file = "/tmp/countries.properties"
while IFS='=' read -r key value
do
echo "${key} ${value}"
sed -ie 's/:iso=>"${key}"/:iso=>"${key}",:alpha_iso=>"${value}"/g' /tmp/country.rb
done < "$file"
Run Code Online (Sandbox Code Playgroud)
但是当我去运行该文件时,尽管我的文件存在(我做了一个“ls”来验证它),但我得到一个“Nno such file or directory error”。
localhost:myproject davea$ sh /tmp/script.sh
=: cannot open `=' (No such file or directory)
/tmp/countries.properties: ASCII text
/tmp/script.sh: line 9: : No such file or directory
localhost:myproject davea$
localhost:myproject davea$ ls /tmp/countries.properties
/tmp/countries.properties
Run Code Online (Sandbox Code Playgroud)
我还需要做什么才能成功读取我的属性文件?
我在 Amazon Linux 上使用 bash shell。我正在尝试在文件顶部插入一行,所以我有
header_line="first_line_of_file"
...
sed -i "1 i\$header_line" /tmp/$file_title
Run Code Online (Sandbox Code Playgroud)
然而,实际出现在我的文件顶部的是
$header_line
Run Code Online (Sandbox Code Playgroud)
如何告诉 sed 不要按字面解释我的变量,而是使用变量中的值插入到文件顶部?
我正在使用 CentOS 7。我正在尝试编写一个脚本来启动和停止 puma 进程,但如果 taht 是正确的术语,我无法弄清楚如何获取“主”PID。在下面的命令中
[rails@server myproject_production]$ ps aux | grep puma
rails 15767 0.0 1.2 437904 13612 ? Sl 17:20 0:00 puma 3.11.4 (tcp://0.0.0.0:3000,unix:///home/rails/myproject_production/shared/sockets/puma.sock) [myproject_production]
rails 15779 0.6 7.6 1061248 80688 ? Sl 17:20 0:05 puma: cluster worker 1: 15767 [myproject_production]
rails 15781 0.6 7.7 1061248 80876 ? Sl 17:20 0:05 puma: cluster worker 2: 15767 [myproject_production]
rails 15785 0.6 7.4 1061964 78488 ? Sl 17:20 0:05 puma: cluster worker 3: 15767 [myproject_production]
rails 15880 0.7 7.4 …Run Code Online (Sandbox Code Playgroud) 我在 Amazon Linux 上使用 bash shell。我在 shell 脚本中有一个命令
wget -O - "http://localhost:8088/subco/books/$e_id/segments/$segment_id?product=$product_id&audience=teacher" > /dev/null
Run Code Online (Sandbox Code Playgroud)
阅读这个——https://superuser.com/questions/321240/how-do-you-redirect-wget-to-standard-out/321241,我被引导相信我可以输出 wget 的结果(它检索的结果) ) 到我的屏幕并抑制所有其他输出。然而,我得到的是
--2018-05-29 18:39:49-- http://localhost:8088/subco/books/C2644BB08F394E209A26175BD2C89F5A/segments/C2F62E7002964DD396E381DB331129A4?product=D399B9C5F6204EDE80A002930CC0D02F&audience=teacher
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8088... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘STDOUT’
Run Code Online (Sandbox Code Playgroud)
如何将 wget 的结果输出到屏幕并抑制所有其他信息(例如,“HTTP 请求已发送,等待响应... 200 OK”部分)?
我在 Amazon Linux 上使用 bash 脚本。当我想将 stderr 和 stdout 重定向到文件时,我可以运行
./my_process.pl &>/tmp/out.txt
Run Code Online (Sandbox Code Playgroud)
有没有办法可以将此输出重定向到文件并继续在控制台(在我的 shell 中)上查看它?这是怎么做到的?
我正在使用亚马逊 Linux。我有一个脚本来启动和停止服务,用 bash 编写,位于
/etc/init.d/wildfly
Run Code Online (Sandbox Code Playgroud)
例如,在不同的运行级别,我有符号链接来确保脚本启动和停止
/etc/rc.d/rc3.d/S80wildfly
/etc/rc.d/rc2.d/S80wildfly
Run Code Online (Sandbox Code Playgroud)
但是我的问题是,我需要怎么做才能保证服务失败了,可以自动重启?我在 CentOS 上阅读,您可以使用指令创建一个文件(例如“wildfly.service”)
Restart=always
RestartSec=3
Run Code Online (Sandbox Code Playgroud)
Amazon Linux 上的等效指令位于何处?
我正在使用 Ubuntu 14.04。我想弄清楚哪些目录占用了最多的空间,所以我正在运行这个命令
sudo du -a / | sort -n -r | head -n 100
Run Code Online (Sandbox Code Playgroud)
问题是,大多数返回的目录属于一个单独的分区,
1048580 /mnt/volume-nyc1-01/postgresql/9.5/main/base/16419/57411.6
Run Code Online (Sandbox Code Playgroud)
如何/mnt/volume-nyc1-01/从我的列表中排除分区?
我已将我的系统 (CentOS 7) 升级到 Python 3.7,这似乎破坏了很多东西。特别是,我无法执行 yum 升级...
[myuser@server ~]$ sudo yum upgrade
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.us-midwest-1.nexcess.net
* epel: mirror.layeronline.com
* extras: mirror.us-midwest-1.nexcess.net
* updates: mirror.us-midwest-1.nexcess.net
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
File "/usr/libexec/urlgrabber-ext-down", …Run Code Online (Sandbox Code Playgroud) 我正在使用 bash。如果我的脚本参数数量错误,如何以不成功代码退出?
我有这个
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "Should be three parameters to this script -- [CWD driver-directory side-file]"
fi
Run Code Online (Sandbox Code Playgroud)
但随后脚本继续。
我正在使用 bash shell。如果我想执行最后一个echo命令,我可以运行
history | grep echo
Run Code Online (Sandbox Code Playgroud)
然后从显示的内容中获取最后一个 echo 命令并运行它。我想知道,有没有更短的方法来做到这一点?如果我只知道以“echo”开头的命令,那么我很高兴使用另一个 shell,如果它允许我以某种方式更轻松地执行最后一个“echo”命令。