I want to run commands after logging into the remote server using shh

#! /bin/bash
read -p 'Username: ' user
read -p 'IP: ' ip

ssh "$user"@"$ip"

osascript -e ' tell app "System Events" to display "Hello world"'

This file will be ran automatically so it’s not like I’m running command after command

It doesn’t run the last command and I don’t know why

This is terminal on mac

Answer

I don’t know how ssh exactly operates, but your script is written in a way that it will wait until the ssh command finally terminates. Then will it continue and run your last line (osascript…). To avoid waiting for ssh to return, write a & at the end of the ssh line. It will have the interpreter to continue executing the next command in a parallel thread.

Attribution
Source : Link , Question Author : Chad McMillin , Answer Author : Byte Commander

Leave a Comment