【Linux】salt的cmd.script命令介绍

salt是一个很棒的自动化运维工具之一,常用的有cmd.run,今天介绍的是cmd.script 

其实一眼就能看出这个命令是执行脚本的命令

具体操作如下:

1.将/etc/salt/master中的

file_roots:

   base:

     - /srv/salt

这三行取消注释,记住是取消注释

取消完成后保存

这个就执行了需要执行脚本存放的位置

2.创建该路径

mkdir /srv/salt/script/ -p

3.在该路径下存放脚本

这里有一个侧式脚本test.sh

#!/bin/bash

if [ ! -f "/test/test.txt" ];
then
       mkdir /test
       cp /test/test.txt /test/test.txt.bak
       echo "this is a test file " >/test/test.txt 
else
       touch /test/test.txt
      echo "this is a test file " >/test/test.txt 
fi

4.执行该脚本

我的minion有两台,分别是

[root@test6_100 script]# salt-key -L
Accepted Keys:
test6_101
test6_102

Denied Keys:
Unaccepted Keys:

下面将操作的是master服务器,将脚本的内容在这两台minion上执行

salt "*" cmd.script salt://script/test.sh

test6_102:
    ----------
    pid:
        2333
    retcode:
        0
    stderr:
    stdout:
test6_101:
    ----------
    pid:
        3325
    retcode:
        0
    stderr:
    stdout:

执行完不会报任何的error,如果有error证明有错误,需要查看脚本后,在进行操作

5.查看结果

分别登陆到这两台服务器中,找到/test/test.txt,并查看里面的内容,如果是this is a test file,那么命令就执行成功了

 

 

如果真的有error的错误的话,查看下minion的日志

日志位置查看配置文件

#####         Logging settings       #####
##########################################
# The location of the minion log file
# The minion log can be sent to a regular file, local path name, or network
# location. Remote logging works best when configured to use rsyslogd(8) (e.g.:
# ``file:///dev/log``), with rsyslogd(8) configured for network logging. The URI
# format is: <file|udp|tcp>://<host|socketpath>:<port-if-required>/<log-facility>
#log_file: /var/log/salt/minion
#log_file: file:///dev/log
#log_file: udp://loghost:10514
#
#log_file: /var/log/salt/minion
#key_logfile: /var/log/salt/key

配置文件中默认的位置是/var/log/salt/minion

tail -200 /var/log/salt/minion

查看下具体的报错

 

 

posted @   zclinux  阅读(547)  评论(0编辑  收藏  举报
编辑推荐:
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
阅读排行:
· C# 13 中的新增功能实操
· Ollama本地部署大模型总结
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(4)
· langchain0.3教程:从0到1打造一个智能聊天机器人
· 用一种新的分类方法梳理设计模式的脉络
点击右上角即可分享
微信分享提示