You can complete the task using empty , a small utility from sourceforge. This is similar to the expectation, but probably more convenient in this case. After you install it, your first scp will be executed using the following two commands:
./empty -f scp InstallSWIG.sh root@ $node:/root/InstallSWIG.sh echo YOUR_SECRET_PASSWORD | ./empty -s -c
The first runs your team in the background, tricking it into thinking that it works interactively on the terminal. Another sends data from stdin. Of course, entering a password anywhere on the command line is dangerous due to saving the shell history, users can see it in ps results, etc. It is unsafe, but it would be a little better to store the password in the file and redirect the second input of the command from this file instead of using the echo and channel.
After copying to the server, you can run the script in the same way:
./empty -f ssh root@ $node sh InstallSWIG.sh echo YOUR_SECRET_PASSWORD | ./empty -s -c
source share