1. 程式人生 > >sh, 批量執行Linux命令

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

圖片

當所有命令,後臺執行完畢後,提示資訊如下:

圖片