This is a bit long, but please bear with me.I am currently doing a lot of work with the shell, and I need help writing some specific shell-script.I have basic shell scripting skills, at least enough to realize that what I'm trying to accomplish is not trivial for me.Let me first describe the procedure I am trying to automate.For the sake of this explanation, machine is my laptop, and I use it to connect to a remote server - which I will refer to as server_name.The procedure can be described as follows:I connect to server server_name with ssh from machineI then inserts password for server_nameI compile something on server_nameI log out of server_name (using exit)I then reboot server_name from machine I ping server_name and then I wait until I get a response from it (ping's output is shown on the console)I ssh into server_name againI run some checksFinally, I exit to server_name in order to go back to machineTo accomplish the above recipe, I manually run the following commands from machine:<machine>$ ssh server_nameinsert password for server_name:<server_name>$ cd /some/path/<server_name>$ make clean > /dev/null<server_name>$ make > /dev/null<server_name>$ exit<machine>$ ./my_reboot_script server_name<machine>$ ping server_namePING 10.23.22.7 with 56(84) bytes of data.ping output... (not very interesting)...ping output... (not very interesting)...ping output... (not very interesting)...ping output... (not very interesting)...^C<machine>$ ssh server_nameinsert password for server_name:<server_name>$ ./run_some_checks<server_name>$ exit<machine>$ echo Done!Couple of notes on the above is in order:- my_reboot_script is just a program that allows me to cold-reboot server_name from the comport of my own seat.- After I cold-reboot server_name, I need to wait for it to go back up, so I can reconnect to it using ssh. To do that, I use ping; it is merely used as an indication to when server_name is ready to accept connections again; Only when I see the ping output finally spawning on the console, I interrupt it with Ctrl+C, and then I ssh into server_name.Doing the above manually is tedious and time consuming. It requires my attention several times (entering the password to ssh and interrupting the ping) and I want my hands and mind free to work on other stuff.So I want to automate the above process, but there are three difficulties:While connected to server_name, issuing the exit command from the shell gracefully logs me out and returns me to machine. However, issuing exit from within a script .sh file will terminate the script...  How can I automate the password to server_name phase? I don't want to manually typing the password, but rather let the script do it; in other words - I want to somehow hardcode the password into the script so it won't bother me with it.  The waiting-for-server-to-be-ready-for-ssh-connections phase: How can I automate this? Meaning, instead of just pinging until I get a response, then interrupting with Ctrl+C, I want the script to ping, recognize that there is a response from server_name, then connect with ssh. Although, using ping might not be such a good idea here, since response to ping does not guarantee that server_name is ready to listen to ssh connections (from my experience with the above process, it takes a few more seconds from the moment the first response to the ping is obtained). Therefore, a better approach might be for the script to keep on trying to ssh in a loop until it granted access (some sort of a busy waiting mechanism, or even a loop that sleeps and wakes up every few seconds to try to connect).Any help with these three difficulties would very much appreciated!Thanks for reading through.
Help with writing script that logs in and out of ssh server
shell script