随笔分类 -  shell脚本

shell脚本
摘要:[root@bogon ~]# cat a.sh #!/bin/bash ssh root@192.168.0.98 'ls /root' 阅读全文
posted @ 2019-03-04 12:40 effortsing 阅读(1301) 评论(0) 推荐(0) 编辑
摘要:#!/bin/bash #定义变量 export NODE_NAMES=(test1 test2 test3 test4) export NODE_IPS=(192.168.0.91 192.168.0.92 192.168.0.93 192.168.0.94) for node_name in ${NODE_NAMES[*]} do for node_ip in ${NODE_IPS... 阅读全文
posted @ 2019-02-07 19:33 effortsing 阅读(171) 评论(0) 推荐(0) 编辑
摘要:说明:必须要带上$ ,否则报错ENCRYPTION_KEY=$(head -c 16 /dev/urandom | od -An -t x | tr -d ' ') echo ${ENCRYPTION_KEY} 阅读全文
posted @ 2019-02-06 16:07 effortsing 阅读(2713) 评论(0) 推荐(0) 编辑
摘要:cat > a.sh <<EOF #!/bin/bash export NODE_NAMES=(kube-test1 kube-test2 kube-test3 kube-test4) for node_name in ${NODE_NAMES[*]} do echo ${node_name} done EOF 阅读全文
posted @ 2019-02-06 15:35 effortsing 阅读(143) 评论(0) 推荐(0) 编辑
摘要:hostname -i | awk '{print $NF}' 阅读全文
posted @ 2019-02-04 10:23 effortsing 阅读(150) 评论(0) 推荐(0) 编辑
摘要:shell脚本安装python、pip--不需要选择安装项目--不管用总报错,必须带上判断符号,while没有这种用法,写在这里为了以后少走弯路,所以不要用下面的执行了首先把pip-18.0.tar.gz 、Python-3.6.5.tgz 安装包放在 /usr/local 下面,按照顺序先安装pip,再安装python。不要先安装或只安装python,否则很容易出错, #!/bin/bash... 阅读全文
posted @ 2019-01-31 21:42 effortsing 阅读(1984) 评论(0) 推荐(0) 编辑
摘要:首先把pip-18.0.tar.gz 、Python-3.6.5.tgz 安装包放在 /usr/local 下面,按照顺序先安装pip,再安装python。不要先安装或只安装python,否则很容易出错, cat >>pip-python.sh<<EOF #!/bin/bash func1(){ yum -y groupinstall "Development tools" [... 阅读全文
posted @ 2019-01-29 21:41 effortsing 阅读(1140) 评论(0) 推荐(0) 编辑
摘要:[root@www zabbix_scripts]# cat check_httpd.sh #!/bin/bash a=`lsof -i:80 | wc -l` if [ "$a" -gt "0" ];then echo "0" else echo "1" fi 阅读全文
posted @ 2018-12-12 14:47 effortsing 阅读(7437) 评论(0) 推荐(1) 编辑
摘要:# 注意:shell脚本批量执行命令,不能只写一个函数,然后把所有命令复制进去,之前试过这样是不行的。必须要有一个判断命令执行成功与否的语句 # 简单的命令可以不加结果判断符号,但是遇到解压包、sed 的命令就不往下执行了。测试过 [mysql@www ~]$ cat firewall.sh #!/bin/bash func1(){ firewall-cmd --zone=public... 阅读全文
posted @ 2018-12-07 16:47 effortsing 阅读(2268) 评论(0) 推荐(0) 编辑
摘要:1、shell脚本安装jdk 提前把jdk安装包放在 /usr/local 下 [root@bogon ~]# cat jdk.sh #!/bin/bash cd /usr/local/ && tar xf jdk-8u171-linux-x64.tar.gz cat >> /etc/profile << EOF export JAVA_HOME=/usr/local/jdk1.8.0_1... 阅读全文
posted @ 2018-11-25 20:42 effortsing 阅读(746) 评论(0) 推荐(0) 编辑
摘要:1、批量注释 使用替换命令 :% s/^/#/g 来在全部内容的行首添加 # 号注释 :1,10 s/^/#/g 在1~10 行首添加 # 号注释 也可以用sed批量注释sed '1,3 s/^/#/g' development.yaml 2、批量取消注释 进配置文件注释:删除多行注释的方法,同样 阅读全文
posted @ 2018-11-25 20:25 effortsing 阅读(186) 评论(0) 推荐(0) 编辑
摘要:echo 用法 echo加不加双引号都是一样的效果 #!/bin/bash #this script display the date and who's login on echo "the time and date are:" date echo let's see who's login the system: who #!/bin/bash #this script disp... 阅读全文
posted @ 2018-11-24 16:32 effortsing 阅读(320) 评论(0) 推荐(0) 编辑
摘要:[root@bogon ~]# cat d.sh #!/bin/bash#. /etc/init.d/functionscat <<END+ +| || This is install python || || 1.安装依赖环境 || 2.安装pip || 3.安装python3.5 || |+ + 阅读全文
posted @ 2018-11-22 16:07 effortsing 阅读(155) 评论(0) 推荐(0) 编辑
摘要:1、安装软件 yum install expect -y 2、查看expect命令位置 expect命令的位置也可能是在 /usr/local/bin/expect,使用前用户应确认工具是否存在(确认方法是在root用户下运行“which expect”命令) 3、expect非交互拷贝秘钥 注意这里的spawn ssh -l,因为这个脚本属于登录脚本,所以需要加ssh -l... 阅读全文
posted @ 2018-11-21 20:33 effortsing 阅读(711) 评论(0) 推荐(0) 编辑
摘要:1、比较符号解释 $# 表示提供到shell脚本或者函数的参数总数; $1 表示第一个参数。 -ne 表示 不等于 $?是shell变量,表示"最后一次执行命令"的退出状态.0为成功,非0为失败. 2、整数比较 -eq 等于,如:if ["$a" -eq "$b" ] -ne 不等于,如:if [" 阅读全文
posted @ 2018-11-20 21:34 effortsing 阅读(179) 评论(0) 推荐(0) 编辑
摘要:1、cat向文件覆盖内容 cat > local.repo << EOF [local]name=localbaseurl=file:///mnt/cdromgpgcheck=0enabled=1EOF 2、cat向文件追加内容 cat >> local.repo << EOF[local]name 阅读全文
posted @ 2018-11-20 21:19 effortsing 阅读(185) 评论(0) 推荐(0) 编辑
摘要:首先把pip-18.0.tar.gz 、Python-3.6.5.tgz 安装包放在 /usr/local 下面,按照顺序先安装pip,再安装python。不要先安装或只安装python,否则很容易出错, [root@bogon ~]# cat pip-python.sh #!/bin/bash func1(){ yum -y groupinstall "Development to... 阅读全文
posted @ 2018-11-19 10:59 effortsing 阅读(3775) 评论(0) 推荐(0) 编辑
摘要:[root@bogon ~]# cat menue.sh #!/bin/bash yum_list(){ #列出所有yum安装包 yum repolist [ $? -eq 0 ] && echo "right" } make(){ mkdir -p /home/a.txt [ $? -eq 0 ] && echo "创建文件成功" } #脚本菜单函... 阅读全文
posted @ 2018-11-19 10:58 effortsing 阅读(200) 评论(0) 推荐(0) 编辑
摘要:1、find工具-name find /data -name "*.txt" 查找data目录意.txt结尾的文件 find /data -name "[A-Z]*" 查找data目录下以大写字母开头的文件 find /data -name "test*" 查找data目录下以test开头的文件 f 阅读全文
posted @ 2018-11-19 10:57 effortsing 阅读(181) 评论(0) 推荐(0) 编辑
摘要:参考文档 https://blog.csdn.net/caoshunxin01/article/details/79355566 [root@kube-node3 ~]# cat tab_space.txt this is tab finish.this is several space finis 阅读全文
posted @ 2018-11-19 10:54 effortsing 阅读(460) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示