Shell script which i have is having two different part.
- Setting Environment Platform
- Scripts for package installation on remote host.
Example:
#!/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
}
So, in this the first part init()
should run in my machine itself. On success of the ssh connection install_packages() should run in guest machine which is entered in init().
How can i do it?