
shell脚本
橙子❦
这个作者很懒,什么都没留下…
展开
-
docker使用shell for循环批量创建容器和批量删除容器脚本
1、批量创建容器脚本[root@localhost ~]# cat docker_add.sh#!/bin/bash#前提在/root/add.txt中输入要创建容器的名称,名称切不相同#例如:#[root@localhost ~]# cat add.txt#test1#test2#test3name=cat /root/add.txtfor num in $namedofor char in numdo/usr/bin/dockerrun−idt−−name=num do原创 2020-10-04 10:52:12 · 1525 阅读 · 0 评论 -
shell 倒计时5秒
[root@localhost ~]# cat 5.sh #!/bin/bashecho "准备倒数5秒:"for i in $(seq 5 -1 1)do echo -e "$i/s";sleep 1doneecho -e "开始"[root@localhost ~]# sh 5.sh 5准备倒数5秒:5/s4/s3/s2/s1/s开始原创 2020-06-19 15:56:30 · 2149 阅读 · 0 评论 -
批量ping网段内的主机
1:批量ping网段内的主机[root@lxy for]# cat pingfor.sh #!/bin/bash##批量ping主机for i in {1..254}do { #{}&,将大括号里面的内容放入后台去执行 host=192.168.0.$i ping -c 1 $host &> /dev/null if [ $? -eq 0 ] then echo "$(date +%Y-%m-%d,%H:%M:%S) $host is up" >&g原创 2020-06-04 17:49:53 · 574 阅读 · 0 评论 -
shell输出Firewlld和Selinux状态
1、脚本编写cat Firewall_Selinux_status.sh#!/bin/bash#=====================================================================####Colors#YELLOW=黄色YELLOW='\033[0;33m'#GREEN=绿色GREEN='\033[32m'#GULES=红色GULES='\033[31m'#YELLOW=黄色YELLOW='\033[33m'#BLUE=蓝色B原创 2020-06-02 10:33:20 · 419 阅读 · 0 评论 -
全网最简单方法:shell 脚本ssh-expect做免秘钥登录
1、vim ssh_key.sh ##脚本#!/bin/bashfunction a {/usr/bin/expect <<EOF set timeout 10 spawn ssh-copy-id -i /root/.ssh/id_dsa.pub $username@$hostname expect { #first connect, no public key in ~/.ssh/known_hosts原创 2020-05-30 21:29:45 · 462 阅读 · 0 评论 -
shell 输出系统某几个服务状态和某几个版本版本
cat server_version.sh#!/bin/bash##输出系统某几个服务状态和某几个版本版本##变量system='systemctl status'system_name="neutron-linuxbridge-agent.service openstack-nova-api.service openstack-glance-api.service openstack-nova-compute.service mariadb.service rabbitmq-server.s原创 2020-06-01 15:04:44 · 362 阅读 · 0 评论 -
shell 判断rpm安装包是否存在,不存在安装
[root@orange ~]# rpm -ql expect/usr/bin/expectvim 1.sh ##通过检查文件是否存在判断安装包是否存在if [ ! -e “/usr/bin/expect” ]then/usr/bin/yum -y install expect >/dev/nullelse“已经安装”fi原创 2020-06-01 11:31:12 · 3189 阅读 · 0 评论 -
shell脚本(实现效果 修改网卡ip地址、重启网卡和ssh免秘钥登录、cpu、内存、磁盘、ip地址)
1、shell脚本(实现效果 修改网卡ip地址、重启网卡和ssh免秘钥登录、cpu、内存、磁盘、ip地址)[root@hhhh opt]# cat 888.sh #!/bin/bash#================================================================function fn_0 (){cat << EOF1) systemq) quitEOFread -p "please input one number for原创 2020-05-31 11:58:00 · 1237 阅读 · 1 评论 -
shell 判断文件是否存在不存在、创建文件并输入内容
1、cat if3.sh#!/bin/bash# 判断文件是否存在不存在、创建文件并输入内容file="/root/test.txt"if [ ! -f $file ];then echo "ok1" >> $fileelse cat $filefi2、效果[root@a lxy]# sh if3.sh [root@a lxy]# sh if3.sh ok1原创 2020-05-30 17:20:02 · 6185 阅读 · 0 评论 -
shell 判断目录是否存在,不存在创建
1、cat if2.sh#!/bin/bash#判断目录是否存在,不存在创建dir=/media/cdromif [ ! -d $dir ]then mkdir -p /media/cdrom echo -e "\033[32m this is $dir success ! \033[0m"else echo -e "\033[032m directory already exists \033[0m"fi2、效果[root@a lxy]# sh if2.sh原创 2020-05-30 17:18:24 · 8416 阅读 · 1 评论 -
shell数值比较(高级版)
1、if1.sh#!/bin/bash# 大小比较NUM1=100NUM2=200if (($NUM1 > $NUM2));then echo "this $NUM1 greate $NUM2"else echo "this $NUM1 less $NUM2"fi2、效果[root@a lxy]# sh if1.sh this 100 less 200原创 2020-05-30 17:16:41 · 1357 阅读 · 0 评论 -
Shell脚本实现判断成绩优秀、及格、不及格
1、需求为:从键盘输入分数,以此来判断,0-59为不及格,打印“您没有及格,请下次努力!”,60-79为及格,打印“您的成绩及格,请更加努力!”,80-100为成绩良,打印“您的成绩为优秀,请再接再厉!”,如果输入为0-100以外的分数,请打印“您的成绩为优秀,请再接再厉!”2、if4.sh#!/bin/bashread -p "prease enter your score :" sourceif [ $source -ge 0 -a $source -le 59 ] ;then echo原创 2020-05-30 17:13:52 · 9294 阅读 · 0 评论