Sahip olduğum kabuk komut dosyası iki farklı bölümden oluşuyor. Çevre Platformu uzak ana üzerindeki paket kurulumu için Kabuk betiğini çalıştırırken ana makineyi dinamik olarak nasıl değiştirebilirim?
- .
Örnek:
#!/bin/bash
# Setting Environment Platform
init(){
echo "Enter username of guest machine"
read USERNAME
echo "Enter IP of guest machine"
read GUEST_IP
echo "Guest IP : $GUEST_IP"
echo "Guest Username $USERNAME"
echo "running === ssh -l $USERNAME $GUEST_IP"
if ssh -l $USERNAME $GUEST_IP; then
install_packages
echo SUCCESS
else
retry_connection
echo FAIL
fi
}
# Scripts for package installation on remote host.
install_packages(){
sudo apt-get -y update && apt-get -y upgrade
sudo apt-get -y install aptitude
sudo apt-get -y install default-jre
sudo apt-get -y install default-jdk
}
retry_connection(){
if ssh -l $USERNAME $GUEST_IP; then
install_packages
echo SUCCESS
else
retry_connection
echo FAIL
fi
}
Yani, bu ilk bölümünde init()
benim makinede kendisinde çalışmalıdır. Ssh bağlantısının başarısı üzerine install_packages(), init() 'de girilen konuk makinede çalışmalıdır. Nasıl yapabilirim?