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

 

图片

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

 

图片


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM