You can use LocalCommand ssh option, but there are some limitations. From
Specifies a command to execute on the local machine after successfully connecting
to the server. The command string extends to the end of the line, and is
executed with the user's shell. The following escape character substitutions
will be performed:
‘%d’ (local user's home directory),
‘%h’ (remote host name), ‘%l’ (local host name),
‘%n’ (host name as provided on the command line),
‘%p’ (remote port),
‘%r’ (remote user name) or ‘%u’ (local user name).
The command is run synchronously and does not have access to the session of
the ssh(1) that spawned it. It should not be used for interactive commands.
This directive is ignored unless PermitLocalCommand has been enabled.
Here is quick example:
ssh -v -o PermitLocalCommand=yes -o 'LocalCommand=/bin/date >/tmp/test' localhost
Later, you probably need to put those options into proper Host section in