# How to run SSH Monitor

Prerequisites:

* [Installation how-to](./install_update_remove_how_to.md#how-to-install).
* [Firewall how-to for SSH](./firewall_how_to.md#firewall-configuration-for-ssh).
* [Firewall how-to for EPICS](./firewall_how_to.md#standard-firewall-configuration-for-epics).
* [SSH how-to](./ssh_how_to.md).
* [`.cmd` and `.substitutions` how-to](./cmd_and_sub_how_to.md)
* [Security how-to](./security_how_to.md)

Once the prerequisites have been followed, you can run {{SSH_Monitor}} like so:

1. Change directory to the `ioc*` folder of the `iocBoot` directory of your {{Top}}, e.g.:

    ```{code} bash
    $ cd /path/to/myTargetMonitoringTop/iocBoot/iocMyTargetMonitoring
    ```

2. Check the first line of the {{cmd}}
   (i.e. the [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)))
   and make sure that the relative location indicated here is valid
   (i.e. it points to an existing binary program).
   E.g.:

    ```{code} bash
    $ head -n 1 st_target1.cmd

         #!../../bin/linux-x86_64/myTargetMonitoring

    $ ls ../../bin/linux-x86_64/myTargetMonitoring

        ../../bin/linux-x86_64/myTargetMonitoring

    $ echo $?

        0
    ```

    ```{seealso}
    More details about Shebangs
    in the [`.cmd` explanations](../../explanations/cmd_and_template_and_sub_explanations.md#cmd-explanations).
    ```

3. If running multiple {{IOC_program}}s in parallel on the same machine,
   then make sure that each {{IOC_program}} defines a unique `EPICS_CAS_SERVER_PORT`
   with the `epicsEnvSet` {{IOC_shell}} command.
   You can refer to the syntax used in the [`.cmd` and `.substitutions` how-to](./cmd_and_sub_how_to.md#cmd-creation-and-configuration)
   (detailed in the [`.cmd` explanations](../../explanations/cmd_and_template_and_sub_explanations.md#cmd-explanations)).
   The reasons about why are given in the [TCP ports limitations explanations](../../explanations/tcp_ports_limitation_explanations.md).

    ```{code} bash
    $ grep "EPICS_CAS_SERVER_PORT" st_target1.cmd
        
        epicsEnvSet("EPICS_CAS_SERVER_PORT", "5064")
    ```

4. Make sure the {{cmd}} file is executable and run it. E.g.:

    ```{code} bash
    $ if [[ ! -x st_target1.cmd ]]; then chmod +x st_target1.cmd; fi
    $ ./st_target1.cmd
    ```

```{tip}
You might want to check
[how to run SSH Monitor as a daemon](./ssh_monitor_daemon_how_to.md)
and how [to run SSH Monitor with a system service](./ssh_monitor_service_how_to.md)
for more reliable ways to run {{SSH_Monitor}} in production.
```

