sh, 批量执行Linux命令

Posted 千里之行始于足下

tags:

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

step 1:创建一个sh批处理命令文件 
# vim /etc/batch_ssh/install_redis.sh


step 2:给当前用户,能够执行sh脚本权限
# chmod install_redis.sh 777


step 3: 编写要批量执行的命令,read表示等待前端用户输入,sleep表示等待时间单位为 秒。

echo ‘\n begin to install 01 plugin \n‘;
yum install cpp -y;
echo ‘\n yum finish install 01 plugin \n‘;
sleep 3;
 
echo ‘\n begin to install 02 plugin \n‘;
yum install binutils -y;
echo ‘\n yum finish install 02 plugin \n‘;
sleep 3;
 
echo ‘\n begin to install 03 plugin \n‘;
yum install glibc-kernheaders -y;
echo ‘\n yum finish install 03 plugin \n‘;
sleep 3;
 
echo ‘\n begin to install 04 plugin \n‘;
yum install glibc-common -y;
echo ‘\n yum finish install 04 plugin \n‘;
sleep 3;
 
echo ‘\n begin to install 05 plugin \n‘;
yum install glibc-devel -y;
echo ‘\n yum finish install 05 plugin \n‘;
sleep 3;
 
echo ‘\n begin to install 06 plugin \n‘;
yum install gcc -y;
echo ‘\n yum finish install 06 plugin \n‘;
sleep 3;
 
echo ‘\n begin to install 07 plugin \n‘;
yum install make -y;
echo ‘\n yum finish install 07 plugin \n‘;
sleep 3;
 
echo ‘all plugin had installed completed‘;
read;


step 4: 最后,记得保存文件 

# :wq install_redis.sh


step 5: 执行批量脚本文件install_redis.sh
# /etc/batch_ssh/install_redis.sh
或者在当前目录,则执行
# ./install_redis.sh

 

技术分享

当所有命令,后台执行完毕后,提示信息如下:

 

技术分享

以上是关于sh, 批量执行Linux命令的主要内容,如果未能解决你的问题,请参考以下文章

Linux系统批量配置脚本

Linux多台主机批量执行命令

MongoDB怎样批量执行命令

批量远程执行命令

2.3-命令批量执行脚本

Shell实战批量在多台服务器上执行命令