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