我需要创建一个Ansible playbook,*.web只有在文件存在的情况下才能删除特定目录中的文件.
操作系统:分OS,Redhat 5x,6x.
我试过以下但没有成功:
- stat: path=/opt/app/jboss/configuration/*.web
register: web
- shell: rm -rf /opt/app/jboss/configuration/*.web
when: web.stat.exists
Run Code Online (Sandbox Code Playgroud) 我想在expect文件中设置一个变量b,这里最初我通过这个脚本ssh到一台机器,在那台机器上我想要获取一个值并使用以下命令设置expect变量:
set b [exec `cat /home/a |grep "work"|awk -F '=' '{print $2}'`]
send_user "$b"
Run Code Online (Sandbox Code Playgroud)
file/home/a有以下结构:
home=10.10.10.1
work=10.20.10.1
Run Code Online (Sandbox Code Playgroud)
我打算在打印后使用变量b但是在执行ssh脚本之后它会给出:
不能读"2":没有这样的变量
while executing
Run Code Online (Sandbox Code Playgroud)
如果我将此输出放在该机器的文件名temp中并尝试执行以下操作:
设置b [exec cat ./temp]
然后它还给出了:
cat:./ temp:没有这样的文件或目录
如果我发送"cat ./temp",它会输出正确的输出.
请让我知道我哪里出错了.
在我的前同事处理用bash编写的项目时,我注意到所有.sh文件都只包含函数定义#!/bin/false,据我所知,这是一种防止执行仅包含文件的安全机制.
例:
my_foo.sh
#!/bin/false
function foo(){
echo foontastic
}
Run Code Online (Sandbox Code Playgroud)
my_script.sh
#!/bin/bash
./my_foo.sh # does nothing
foo # error, no command named "foo"
. ./my_foo.sh
foo # prints "foontastic"
Run Code Online (Sandbox Code Playgroud)
但是,当我不使用时#!/bin/false,正确和不正确使用的效果完全相同:
例:
my_bar.sh
function bar(){
echo barvelous
}
Run Code Online (Sandbox Code Playgroud)
my_script.sh
#!/bin/bash
./my_bar.sh # spawn a subshell, defines bar and exit, effectively doing nothing
bar # error, no command named "bar"
. ./my_bar.sh
bar # prints "barvelous"
Run Code Online (Sandbox Code Playgroud)
由于source在两种情况下正确使用这些脚本都可以按预期工作,并且在两种情况下执行它们都不会从父shell的角度执行任何操作并且不会生成有关无效使用的错误消息#!/bash/false,这些脚本的目的究竟是什么?
我想sshd_config通过使用Ansible 取消注释文件中的一行,我有以下工作配置:
- name: Uncomment line from /etc/ssh/sshd_config
lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^#AuthorizedKeysFile'
line: 'AuthorizedKeysFile .ssh/authorized_keys'
Run Code Online (Sandbox Code Playgroud)
但是,此配置仅在行开始时有效#AuthorizedKeysFile,但如果行以# AuthorizedKeysFile或# AuthorizedKeysFile(#单词和单词之间的空格)开头则不起作用.
如何配置正则表达式,以便在"#"之后不考虑任何数量的空格?
我试图在'#'之后添加另一个带有空格的lineinfile选项,但这不是一个好的解决方案:
- name: Uncomment line from /etc/ssh/sshd_config
lineinfile:
dest: /etc/ssh/sshd_config
regexp: '# AuthorizedKeysFile'
line: 'AuthorizedKeysFile .ssh/authorized_keys'
Run Code Online (Sandbox Code Playgroud) 我在不同的服务器上尝试一个curl命令.一个正在工作,另一个正在报告"nss error -5938".
服务器1:
OS:
Linux 4.1.12-61.1.10.el6uek.x86_64 x86_64 x86_64 x86_64 GNU/Linux
CURL -V:
curl 7.19.7(x86_64-redhat-linux-gnu)libcurl/7.19.7 NSS/3.19.1基本ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2协议:tftp ftp telnet dict ldap ldaps http file https ftps scp sftp特性:GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
命令运行状态:错误
Content-Type:application/x-www-form-urlencoded; charset = UTF-8 HTTP/1.0 200建立连接HTTP/1.0 200建立连接
- 代理回复确定CONNECT请求
- 使用certpath初始化NSS:sql:/ etc/pki/nssdb
- CAfile:/etc/pki/tls/certs/ca-bundle.crt CApath:none
- NSS错误-5938
- 关闭连接#0
- SSL连接错误卷曲:(35)SSL连接错误
服务器2:
- OS:
Linux 412c25016c7b 4.1.12-37.5.1.el7uek.x86_64#2 SMP Thu Jun 9 16:01:20 PDT 2016 x86_64 x86_64 x86_64 GNU/Linux
- CURL -V
curl 7.19.7(x86_64-redhat-linux-gnu)libcurl/7.19.7 NSS/3.16.2.3基本ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2协议:tftp ftp telnet dict ldap …
我目前有一个blacklist.php文件生成一个黑名单,我需要一个linux上的blacklist.txt文件,从php文件中提取输出.
这可能吗 ?
我正在尝试从 php 执行 bash 脚本并实时获取其输出。
我正在应用在这里找到的答案:
然而他们不为我工作。
当我以这种方式调用 .sh 脚本时,它工作正常:
<?php
$output = shell_exec("./test.sh");
echo "<pre>$output</pre>";
?>
Run Code Online (Sandbox Code Playgroud)
然而,当做:
<?php
echo '<pre>';
passthru(./test.sh);
echo '</pre>';
?>
Run Code Online (Sandbox Code Playgroud)
或者:
<?php
while (@ ob_end_flush()); // end all output buffers if any
$proc = popen(./test.sh, 'r');
echo '<pre>';
while (!feof($proc))
{
echo fread($proc, 4096);
@ flush();
}
echo '</pre>';
?>
Run Code Online (Sandbox Code Playgroud)
我的浏览器中没有输出。
我还尝试在这两种情况下调用变量而不是脚本,我的意思是:
<?php
$output = shell_exec("./test.sh");
echo '<pre>';
passthru($output);
echo '</pre>';
?>
Run Code Online (Sandbox Code Playgroud)
这是我的 test.sh 脚本:
#!/bin/bash
whoami
sleep 3
dmesg
Run Code Online (Sandbox Code Playgroud) 我正在执行:
ansible-playbook --version
我得到以下输出:
ansible-playbook 2.5.14
config file = /etc/ansible/ansible.cfg
configured module search path = [u'~/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
Run Code Online (Sandbox Code Playgroud)
但是当我执行时:
ansible-playbook --version -e 'ansible_python_interpreter=/usr/bin/python3'
我有完全相同的输出。我期待有类似的东西:
python version = 3.5.2
Run Code Online (Sandbox Code Playgroud)
我有什么误解?
我正在尝试使用execv执行命令。运行该程序后,我可以看到“将要调用execv!”语句。在标准输出上打印。
我还可以从程序“ leaky”中看到打印内容。实际上,一切都按预期工作,除了在if或else块中看不到打印语句外,即“ execv failed!error:”和“ Valgrind成功执行!” 在输出上打印。
我在这里是否缺少关于execv的明显要点?
#include<stdio.h>
#include<errno.h>
#include<string.h>
#include<unistd.h>
int main()
{
char *args[5] = {"/usr/bin/valgrind", "--leak-check=full", "--log-file=valgrindReport.txt", "./leaky", NULL};
printf("Going to call execv!\n");
if(execv("/usr/bin/valgrind", args) < 0)
{
printf("execv failed! error: %s\n", strerror(errno));
return 0;
}
else
{
printf("Successfully executed valgrind!\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用发布的输入文件名,我不会在任何地方上传.
我只需要发布文件名的名称,所以我正在尝试这个代码;
<form method="post" enctype="multipart/form-data" role="form">
<input type="file" id="file" name="file">
<input type="submit" name="submit" value="Submit Form">
</form>
<?php
if(isset($_POST['submit'])){
echo $_FILES['file'];
}
?>
Run Code Online (Sandbox Code Playgroud)
如果我enctype="multipart/form-data"换成表格标签,没关系,但我需要这个标签.
我正在尝试为模式进行grep并按列排序,并使用以下命令仅显示第一行:
grep "BEST SCORE" Result.txt | sort -nk 4 | "display only first line"
Run Code Online (Sandbox Code Playgroud)
我不想将grep两者都不保存sort到文件中。
我在网上找到了这个命令,查找并显示文件的硬链接,例如text.txt。
我的问题:这个命令中的感叹号(!)是做什么的?
find $PWD ! -type d -links +1 -ls | sort -n|cut -d" " -f29 | grep --color=auto "$2"
Run Code Online (Sandbox Code Playgroud) 如果我直接使用单个命令对退出代码进行简单测试:
[user@localhost ~]$ date
Tue Sep 8 14:00:11 CEST 2020
[user@localhost ~]$ echo $?
0
[user@localhost ~]$ dat
bash: dat: command not found...
[user@localhost ~]$ echo $?
127
Run Code Online (Sandbox Code Playgroud)
但是,如果我想将它们放入 if 语句中,我发现对于退出代码 0,输出正常,但是,对于“命令未找到”代码(应该是 127),它返回“1”。
[user@localhost ~]$ date
Tue Sep 8 14:02:18 CEST 2020
[user@localhost ~]$ if [ $? -eq 0 ]; then echo "Success: $?"; else echo "Failure: $?" >&2; fi
Success: 0
[user@localhost ~]$ dat
bash: dat: command not found...
[user@localhost ~]$ if [ $? -eq 0 ]; then echo …Run Code Online (Sandbox Code Playgroud)