satlstack常用命令

Posted netma

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了satlstack常用命令相关的知识,希望对你有一定的参考价值。

查看解压和压缩命令支持的格式和命令

[root@host106 salt]# salt \'*\' sys.list_functions archive
host104:
    - archive.cmd_unzip
    - archive.cmd_zip
    - archive.gunzip
    - archive.gzip
    - archive.is_encrypted
    - archive.list
    - archive.rar
    - archive.tar
    - archive.unrar
    - archive.unzip
    - archive.zip
host105:
    - archive.cmd_unzip
    - archive.cmd_zip
    - archive.gunzip
    - archive.gzip
    - archive.is_encrypted
    - archive.list
    - archive.rar
    - archive.tar
    - archive.unrar
    - archive.unzip
    - archive.zip

salt远程压缩文件命令

[root@host106 ~]# salt \'*\' archive.zip /opt/t.zip /tmp/t1,/tmp/t2
host104:
    - tmp/t1
    - tmp/t2
host105:
    - tmp/t1
    - tmp/t2

salt远程解压命令

[root@host106 ~]# salt \'*\' archive.unzip /opt/t.zip /tmp/
host104:
    - tmp/t1
    - tmp/t2
host105:
    - tmp/t1
    - tmp/t2

 

二、cmd模块命令

查看cmd模块支持的命令

[root@host106 ~]# salt \'*\' sys.list_functions cmd
host104:
    - cmd.exec_code
    - cmd.exec_code_all
    - cmd.has_exec
    - cmd.powershell
    - cmd.retcode
    - cmd.run
    - cmd.run_all
    - cmd.run_bg
    - cmd.run_chroot
    - cmd.run_stderr
    - cmd.run_stdout
    - cmd.script
    - cmd.script_retcode
    - cmd.sdecode
    - cmd.shell
    - cmd.shell_info
    - cmd.shells
    - cmd.tty
    - cmd.which
    - cmd.which_bin
host105:
    - cmd.exec_code
    - cmd.exec_code_all
    - cmd.has_exec
    - cmd.powershell
    - cmd.powershell_all
    - cmd.retcode
    - cmd.run
    - cmd.run_all
    - cmd.run_bg
    - cmd.run_chroot
    - cmd.run_stderr
    - cmd.run_stdout
    - cmd.script
    - cmd.script_retcode
    - cmd.shell
    - cmd.shell_info
    - cmd.shells
    - cmd.tty
    - cmd.which
    - cmd.which_bin

 

salt \'*\' cmd.run \'free -m\'  # 命令cmd.run

salt \'*\' cmd.script /tmp/t.sh  # cmd.script

salt \'host105\' cmd.shell \'rm /tmp/lsfz* -rf\' # cmd.shell

三、cp模块

[root@host106 ~]# salt \'*\' sys.list_functions cp
host104:
    - cp.cache_dir
    - cp.cache_file
    - cp.cache_files
    - cp.cache_local_file
    - cp.cache_master
    - cp.get_dir
    - cp.get_file
    - cp.get_file_str
    - cp.get_template
    - cp.get_url
    - cp.hash_file
    - cp.is_cached
    - cp.list_master
    - cp.list_master_dirs
    - cp.list_master_symlinks
    - cp.list_minion
    - cp.list_states
    - cp.push
    - cp.push_dir
    - cp.recv
    - cp.recv_chunked
    - cp.stat_file
host105:
    - cp.cache_dest
    - cp.cache_dir
    - cp.cache_file
    - cp.cache_files
    - cp.cache_local_file
    - cp.cache_master
    - cp.envs
    - cp.get_dir
    - cp.get_file
    - cp.get_file_str
    - cp.get_template
    - cp.get_url
    - cp.hash_file
    - cp.is_cached
    - cp.list_master
    - cp.list_master_dirs
    - cp.list_master_symlinks
    - cp.list_minion
    - cp.list_states
    - cp.push
    - cp.push_dir
    - cp.recv
    - cp.recv_chunked
    - cp.stat_file

cp.cache_local_file
将master端的/etc/hosts文件复制到minion端的salt cache目录(/var/cache/salt/minion/localfiles/)

[root@host106 ~]# salt \'*\' cp.cache_local_file /etc/hosts
host104:
    /var/cache/salt/minion/localfiles/etc/hosts
host105:
    /var/cache/salt/minion/localfiles/etc/hosts

cp.get_dir
将master端salt主目录下面的目录复制到minion端的/opt目录下

[root@host106 ~]# ls /srv/salt/
apache.sls  _modules  nginx  top.sls
[root@host106 ~]# salt \'*\' cp.get_dir salt://nginx/ /opt/
host104:
    - /opt//nginx/files/nginx-1.25.0.tar.gz
    - /opt//nginx/files/nginx.conf
    - /opt//nginx/files/nginx.service
    - /opt//nginx/init.sls
host105:
    - /opt//nginx/files/nginx-1.25.0.tar.gz
    - /opt//nginx/files/nginx.conf
    - /opt//nginx/files/nginx.service
    - /opt//nginx/init.sls

cp.get_url
下载URL内容到被控主机指定位置(/tmp/index.html)

[root@host106 ~]# salt \'*\' cp.get_url https://www.cyy123.com /tmp/index.html
host105:
    /tmp/index.html
host104:
    /tmp/index.html

DNS模块

功能:实现被控主机通用DNS操作

添加minion端的hosts域名解析信息

[root@host106 ~]# salt \'*\' dnsutil.hosts_append /etc/hosts 10.1.1.1 www.baidu.com
host104:
    The following line was added to /etc/hosts:
    10.1.1.1 www.baidu.com
host105:
    The following line was added to /etc/hosts:
    10.1.1.1 www.baidu.com

删除minion端的hosts域名解析信息

[root@host106 ~]# salt \'*\' dnsutils.hosts_remove /etc/hosts www.baidu.com

 

四、file模块

功能:被控主机常见的文件操作,包括文件读写、权限、查找、校验

首先查看帮助文档,看看支持什么命令

[root@host106 ~]# salt \'*\' sys.list_functions file
host104:
    - file.access
    - file.append
    - file.apply_template_on_contents
    - file.basename
    - file.blockreplace
    - file.check_file_meta
    - file.check_hash
    - file.check_managed
    - file.check_managed_changes
    - file.check_perms
    - file.chgrp
    - file.chown
    - file.comment
    - file.comment_line
    - file.contains
    - file.contains_glob
    - file.contains_regex
    - file.copy
    - file.delete_backup
    - file.directory_exists
    - file.dirname
    - file.diskusage
    - file.extract_hash
    - file.file_exists
    - file.find
    - file.get_devmm
    - file.get_diff
    - file.get_gid
    - file.get_group
    - file.get_hash
    - file.get_managed
    - file.get_mode
    - file.get_selinux_context
    - file.get_source_sum
    - file.get_sum
    - file.get_uid
    - file.get_user
    - file.gid_to_group
    - file.grep
    - file.group_to_gid
    - file.is_blkdev
    - file.is_chrdev
    - file.is_fifo
    - file.is_link
    - file.join
    - file.lchown
    - file.line
    - file.link
    - file.list_backup
    - file.list_backups
    - file.list_backups_dir
    - file.lstat
    - file.makedirs
    - file.makedirs_perms
    - file.manage_file
    - file.mkdir
    - file.mknod
    - file.mknod_blkdev
    - file.mknod_chrdev
    - file.mknod_fifo
    - file.move
    - file.normpath
    - file.open_files
    - file.pardir
    - file.patch
    - file.path_exists_glob
    - file.prepend
    - file.psed
    - file.read
    - file.readdir
    - file.readlink
    - file.remove
    - file.remove_backup
    - file.rename
    - file.replace
    - file.restore_backup
    - file.restorecon
    - file.rmdir
    - file.search
    - file.sed
    - file.sed_contains
    - file.seek_read
    - file.seek_write
    - file.set_mode
    - file.set_selinux_context
    - file.source_list
    - file.stats
    - file.statvfs
    - file.symlink
    - file.touch
    - file.truncate
    - file.uid_to_user
    - file.uncomment
    - file.user_to_uid
    - file.write
host105:
    - file.access
    - file.append
    - file.apply_template_on_contents
    - file.basename
    - file.blockreplace
    - file.chattr
    - file.check_file_meta
    - file.check_hash
    - file.check_managed
    - file.check_managed_changes
    - file.check_perms
    - file.chgrp
    - file.chown
    - file.comment
    - file.comment_line
    - file.contains
    - file.contains_glob
    - file.contains_regex
    - file.copy
    - file.delete_backup
    - file.directory_exists
    - file.dirname
    - file.diskusage
    - file.extract_hash
    - file.file_exists
    - file.find
    - file.get_devmm
    - file.get_diff
    - file.get_gid
    - file.get_group
    - file.get_hash
    - file.get_managed
    - file.get_mode
    - file.get_selinux_context
    - file.get_source_sum
    - file.get_sum
    - file.get_uid
    - file.get_user
    - file.gid_to_group
    - file.grep
    - file.group_to_gid
    - file.is_blkdev
    - file.is_chrdev
    - file.is_fifo
    - file.is_hardlink
    - file.is_link
    - file.join
    - file.lchown
    - file.line
    - file.link
    - file.list_backup
    - file.list_backups
    - file.list_backups_dir
    - file.lsattr
    - file.lstat
    - file.makedirs
    - file.makedirs_perms
    - file.manage_file
    - file.mkdir
    - file.mknod
    - file.mknod_blkdev
    - file.mknod_chrdev
    - file.mknod_fifo
    - file.move
    - file.normpath
    - file.open_files
    - file.pardir
    - file.patch
    - file.path_exists_glob
    - file.prepend
    - file.psed
    - file.read
    - file.readdir
    - file.readlink
    - file.remove
    - file.remove_backup
    - file.rename
    - file.replace
    - file.restore_backup
    - file.restorecon
    - file.rmdir
    - file.search
    - file.sed
    - file.sed_contains
    - file.seek_read
    - file.seek_write
    - file.set_mode
    - file.set_selinux_context
    - file.source_list
    - file.stats
    - file.statvfs
    - file.symlink
    - file.touch
    - file.truncate
    - file.uid_to_user
    - file.uncomment
    - file.user_to_uid
    - file.write
file.chown 修改文件权限

[root@host106 ~]# salt \'*\' file.chown /etc/passwd root root
host104:
None
host105:
None


[root@host106 ~]# salt \'*\' file.copy /tmp/t.sh /opt/t.sh
host104:
    True
host105:
    True
[root@host106 ~]# salt \'*\' file.copy /root/test /opt/test recurse=True
host104:
    True
host105:
    True
[root@host106 ~]# salt \'*\' file.directory_exists /tmp
host104:
    True
host105:
    True
[root@host106 ~]# salt \'*\' file.stats /etc/passwd
host104:
    ----------
    atime:
        1685606591.579007
    ctime:
        1685520187.770625
    gid:
        0
    group:
        root
    inode:
        3149087
    mode:
        0o644
    mtime:
        1685520187.6146245
    size:
        3007
    target:
        /etc/passwd
    type:
        file
    uid:
        0
    user:
        root
host105:
    ----------
    atime:
        1685675456.4029915
    ctime:
        1685589056.2419565
    gid:
        0
    group:
        root
    inode:
        68500246
    mode:
        0644
    mtime:
        1685589056.1539576
    size:
        1505
    target:
        /etc/passwd
    type:
        file
    uid:
        0
    user:
        root
[root@host106 ~]# salt \'*\' file.get_mode /etc/passwd
host104:
    0o644
host105:
    0644
[root@host106 ~]# salt \'*\' file.set_mode /etc/passwd 0644
host104:
    0o644
host105:
    0644
[root@host106 ~]# salt \'*\' file.mkdir /tmp/test
host104:
    True
host105:
    True
[root@host106 ~]# salt \'*\' file.sed /opt/t.sh \'ls\' \'ls -la\'
host104:
    ----------
    pid:
        8754
    retcode:
        0
    stderr:
    stdout:
host105:
    ----------
    pid:
        6309
    retcode:
        0
    stderr:
    stdout:
[root@host106 ~]# salt \'*\' file.append /tmp/t.sh \'ls /root/test\'
host104:
    Wrote 1 lines to "/tmp/t.sh"
host105:
    Wrote 1 lines to "/tmp/t.sh"
[root@host106 ~]# salt \'*\' file.remove /opt/t.sh
host104:
    True
host105:
    True
[root@host106 ~]# salt \'*\' file.touch /opt/t.sh
host104:
    True
host105:
    True
[root@host106 ~]# salt \'*\' file.move /opt/t.sh /opt/t1.sh
host104:
    ----------
    comment:
        \'/opt/t.sh\' moved to \'/opt/t1.sh\'
    result:
        True
host105:
    ----------
    comment:
        \'/opt/t.sh\' moved to \'/opt/t1.sh\'
    result:
        True
[root@host106 ~]# salt \'*\' file.rename /opt/t1.sh /opt/t2.sh
host104:
    True
host105:
    True
[root@host106 ~]# salt \'*\' file.find /root/ type=f name=\\*.tar.gz size=+200m
host104:
    - /root/pkg/mysql-8.0.26.tar.gz
host105:
    - /root/soft/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
[root@host106 ~]# salt \'*\' file.find /root/ mtime=-30d size=+100m print=path.size,mtime 
host104:
    - 1683167746
    - 1683252009
    - 1683507314
    - 1684812540
host105:

 

Shell脚本常用命令

参考技术A

Linux常用命令

ls常用命令

cd常用命令

rm常用命令

grep常用命令

grep命令用于查找文件里符合条件的字符串。

常用指令名称

-A
–after-context
显示符合范本样式的那一行之外及该行之后的内容

输出内容:
aaaa // 该行高亮
bbbb

-b
–byte-offset
输出匹配行并且在在该行前展示第几行

输出内容:
0: aaaa

-c
–count
输出符合匹配字符串的行数

输出内容:
1

其他命令

获取当前界面元素

获取任务列表

app入口

启动应用

列出当前已连接的设备

输出内容:

连接指定设备

例:(SERIAL的值为adb devices -l 输出的值)

屏幕截图

获取屏幕截图

录制视频

获取录制视频

测试界面性能

输出中会包含录制阶段所发生的动画帧的相关性能信息。以下命令使用 gfxinfo 收集指定软件包名称的界面性能数据:

输出最近帧性能信息

检查网络诊断信息

netstats 服务可提供自设备上次启动以来收集的网络使用情况统计信息

检查电池诊断信息

batterystats 服务会生成关于设备电池用量的统计数据

options列表

使用以下命令以计算机可读的 CSV 格式生成 batterystats 输出:

输出内容:

以上是关于satlstack常用命令的主要内容,如果未能解决你的问题,请参考以下文章

Hexo常用命令

Shell脚本常用命令

CentOS7 常用命令汇总

Linux操作系统与常用命令

Informix常用命令

:常用工具命令第23节:常用命令 - Linux命令