如何在 bash 脚本中实现试运行选项?
我可以考虑将每个命令都包含在 if 中并回显该命令,而不是在脚本以试运行方式运行时运行它。
另一种方法是定义一个函数,然后通过该函数传递每个命令调用。
就像是:
function _run () {
if [[ "$DRY_RUN" ]]; then
echo $@
else
$@
fi
}
`_run mv /tmp/file /tmp/file2`
`DRY_RUN=true _run mv /tmp/file /tmp/file2`
Run Code Online (Sandbox Code Playgroud)
这是错误的,有更好的方法吗?
我目前正在尝试将 3 个应用程序从一个存储库拆分为 3 个,但保留 url 结构,因此同一域下的不同位置基本上必须由不同的应用程序交付。
我正在努力解决的是其中一个应用程序需要成为不存在网址的后备,因此如果第一个不匹配,第二个不匹配,那么第三个应该处理请求
我得到的结构是:
/etc/nginx/sites-enabled/main_site,在这里,除了 server_name 和日志include /etc/nginx/subsites-enabled/*
,我有 3 个配置文件,每个应用程序一个。
3 个配置文件中的每一个都包含一个位置块。
我已经在正则表达式中尝试了负前瞻(基本上是尝试对其他应用程序处理的 url 进行硬编码)但失败了。
所以,总结一下:
/ 和 /community 应该由 /etc/nginx/subsites-enabled/example.org/home 提供(一些 perl 脚本)
/news 应该由 /etc/nginx/subsites-enabled/example.org/news (wordpress) 提供
其他一切都应该由 /etc/nginx/subsites-enabled/example.org/app (cake app) 提供
perl 位工作正常。我遇到的问题是该应用程序正在接管新闻(可能是因为它匹配 .*),我尝试了各种选项(我已经在这呆了 2 天),但没有一个解决了所有问题(有时静态资产不起作用等)。
我的配置是:
/etc/nginx/sites-enabled/example.org:
server {
listen 80;
server_name example.org;
error_log /var/log/nginx/example.org.log;
include /etc/nginx/subsites-enabled/example.org/*;
}
Run Code Online (Sandbox Code Playgroud)
/etc/nginx/subsites-enabled/example.org/home:
location = / {
rewrite ^.*$ /index.pl last;
}
location ~* /community(.*) {
rewrite ^.*$ /index.pl last;
}
location ~ …
Run Code Online (Sandbox Code Playgroud) 有没有办法使用 puppet 设置服务器的主机名?
我可以编写自定义类型,但也许有更简单的方法。
谢谢
[编辑] 抱歉,我应该提到我运行 puppet masterless,首先设置 puppet,然后设置其他所有内容。
我对 strace / netstat / 等很陌生。我正在使用此命令来跟踪处理我的请求 (telnet) 的 apache 进程,有没有办法稍微简化一下?
sudo strace -o /tmp/strace -f -s4096 -r -p $(netstat -antlp | \
grep $(lsof -p `pidof telnet` | grep TCP | \
perl -n -e'/localhost:(\d+)/ && print $1') | grep apache2 | \
perl -n -e'/ESTABLISHED (\d+)/ && print $1')
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在尝试从远程文件在 tmux 中运行一系列命令,如下所示:
tmux $(wget -qO- http://example.com/tmux)
Run Code Online (Sandbox Code Playgroud)
该文件包含类似split-window
和的命令send-keys
问题是,send-keys
正在剥离空格。发送密钥命令是:
send-keys ssh example.com C-m;
Run Code Online (Sandbox Code Playgroud)
但相反它发送 sshexample.com
知道为什么吗?
干杯!
所以,我试图对每个请求执行一个脚本。我知道这听起来如何,这是针对开发环境的。
我已将此添加到我的 nginx 配置中 access_by_lua_file "/opt/nginx/git-magic.lua";
git-magic.lua 包含 local status = os.execute('/opt/nginx/git-magic.sh')
并且 git-magic.sh 包含: echo hello >> /tmp/git-magic
问题是:
每当我点击任何 URL 时,我都会在 nginx 错误日志中得到以下信息: 2012/09/27 15:35:48 [alert] 3241#0: waitpid() failed (10: No child processes)
任何想法我可能做错了什么?
当尝试在 AWS 上设置 ubuntu 12.04.2(使用 ubuntu 提供的 ami:ami-ce7b6fba)时,有时build-essential 不可用,我遇到了重复出现的问题。
设置实例的脚本:
set -o xtrace
set -e
sudo apt-get update
sudo apt-get -y install build-essential
Run Code Online (Sandbox Code Playgroud)
相当烦人的一点是它有时会起作用。我尝试添加 eu-west-1 ubuntu 镜像,但这并没有解决问题。
有任何想法吗?
输出:
amazon-ebs: ++ set -e
amazon-ebs: ++ sudo apt-get update
amazon-ebs: Get:1 http://security.ubuntu.com precise-security Release.gpg [198 B]
amazon-ebs: Hit http://archive.ubuntu.com precise Release.gpg
amazon-ebs: Get:2 http://security.ubuntu.com precise-security Release [49.6 kB]
amazon-ebs: Get:3 http://archive.ubuntu.com precise-updates Release.gpg [198 B]
amazon-ebs: Hit http://archive.ubuntu.com precise Release
amazon-ebs: Get:4 http://archive.ubuntu.com precise-updates Release [49.6 kB] …
Run Code Online (Sandbox Code Playgroud) 当尝试加载需要更长时间在 Web 服务器上生成的页面时,Varnish 不断抛出 503 Service Unavailable。
在 varnishlog 中,我可以看到一个FetchError c http read error: 0
错误,但我不太确定它的含义。
我还尝试增加后端超时:
backend default {
.host = "x.x.x.x";
.port = "80";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}
Run Code Online (Sandbox Code Playgroud)
后端是一个 Apache 服务器。
所有其他页面工作正常。
有任何想法吗?
为什么木偶会按时间表[每周]挂起?
我正在无主设置中运行 puppet,因此要通过清单应用,我只是在运行 puppet apply /etc/puppet/manifests/site.pp
在调试模式下,这些是它挂起之前说的最后一句话
debug: /Schedule[never]: Skipping device resources because running on a host
debug: /Schedule[daily]: Skipping device resources because running on a host
debug: /Schedule[monthly]: Skipping device resources because running on a host
debug: /Schedule[puppet]: Skipping device resources because running on a host
debug: /Schedule[hourly]: Skipping device resources because running on a host
debug: /Schedule[weekly]: Skipping device resources because running on a host
Run Code Online (Sandbox Code Playgroud)
如果我发送 SIGINT,它会说
Exiting
debug: Storing state
debug: Stored state in 0.03 seconds
debug: …
Run Code Online (Sandbox Code Playgroud)