$ ansible -i LLTF/LLTF_hosts 10.253.108.6 -m shell -a "ps -aux |grep sshd |awk '{print $9"-"$10}' |sort |uniq -c |sort -rn |head -n 10" 10.253.108.6 | CHANGED | rc=0 >> 5 0 输出格式不正确是为什么?
时间: 2023-10-12 08:04:39 浏览: 58
根据你提供的命令,可能是因为输出中存在非标准字符,导致输出格式不正确。建议使用 `-b` 参数以特权模式执行命令,以避免权限问题。另外,也可以尝试使用 `tr` 命令过滤掉非标准字符,例如:
```
ansible -b -i LLTF/LLTF_hosts 10.253.108.6 -m shell -a "ps -aux |grep sshd |awk '{print $9\"-\"$10}' |tr -cd '[:print:]\n' |sort |uniq -c |sort -rn |head -n 10"
```
这个命令会在执行 `ps -aux |grep sshd` 命令后,使用 `awk` 脚本生成类似 `123-root` 的字符串,然后使用 `tr` 命令过滤掉非标准字符,最后再进行排序、去重和筛选操作,输出前 10 行结果。
相关问题
利用ansible -i /etc/auto-deploy/ansible_hosts all -m shell -a怎么批量备份/etc/ssh/sshd_config
使用Ansible进行批量备份/etc/ssh/sshd_config的步骤如下:
1. 确保已经安装了Ansible,并且已经配置好了主机清单文件(ansible_hosts)。
2. 在终端中执行以下命令:
```
ansible -i /etc/auto-deploy/ansible_hosts all -m shell -a "cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak"
```
这个命令会在所有主机上执行shell模块,将/etc/ssh/sshd_config文件备份为/etc/ssh/sshd_config.bak。
注意:在执行该命令之前,请确保你对Ansible和主机清单文件的配置都是正确的,并且你有足够的权限来执行备份操作。
ansible -i ~/hosts_jzyw/hosts_zhongbao6 fsm -m shell -a "tail /data/ucp/ipcc/logs/media/fsm/freeswitch.log"
Sorry, as a language model AI, I don't have access to your system and resources. However, I can explain to you the meaning of the command you have provided.
The command is using Ansible to run a shell command on a group of hosts specified in the inventory file located at ~/hosts_jzyw/hosts_zhongbao6. The command being run is "tail /data/ucp/ipcc/logs/media/fsm/freeswitch.log" which will print the last few lines of the specified log file. The group of hosts being targeted is 'fsm'.
相关推荐
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![.zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)