'How to quit a local host on mac?

to connect to a remote server I run the below code in my terminal

#!/bin/bash

REMOTE_SERVER='[email protected]'
REMOTE_PORT=XXXX
LOCAL_PORT=XXX

if [ $# -eq 1 ]
then
    ssh $REMOTE_SERVER .local/bin/stop_jupyter.sh $REMOTE_PORT
else
    ssh -L $LOCAL_PORT:localhost:$REMOTE_PORT $REMOTE_SERVER 
.local/bin/run_jupyter.sh $REMOTE_PORT
fi

I need to stop it to access the server again. However, I am getting the message:

The port xxxx is already in use.
ERROR: the Jupyter server could not be started because port xxxx is 
not available.

To stop this server, I was instructed to run the script again and then enter the command "./remote_jupyter stop" in terminal to stop it, but I did not understand how this should be done. Should I added that command after 'fi'? example:

#!/bin/bash

REMOTE_SERVER='[email protected]'
REMOTE_PORT=xxxx
LOCAL_PORT=xxxx

    if [ $# -eq 1 ]
    then
        ssh $REMOTE_SERVER .local/bin/stop_jupyter.sh $REMOTE_PORT
     else
        ssh -L $LOCAL_PORT:localhost:$REMOTE_PORT $REMOTE_SERVER 
     .local/bin/run_jupyter.sh $REMOTE_PORT
     fi ./remote_jupyter stop

or should I run the script, type the password and then enter the command ./remote_jupyter stop ?

I tried everything already and still could not stop it. Any help I would appreciate!! Many thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source