Если Вы имеете inetd
установленный, просто создайте сценарий как (я сделал ошибку, сценарий не нужен),
#!/bin/bash
кошка 1$
затем добавьте строку к inetd.conf
http stream tcp nowait root /bin/cat cat /some/other/dir/file.txt
С Python просто расширяются BaseHTTPServer.BaseHTTPRequestHandler
класс и определяет a do_GET
метод, затем выполненный, как описано в документации, например.
import BaseHTTPServer
class HTTPHandlerOne(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self): self.wfile.write("test\r\n")
def run(server_class=BaseHTTPServer.HTTPServer,
handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
run(handler_class=HTTPHandlerOne)
Вы можете использовать параметр SSH LocalCommand, но есть некоторые ограничения. От man ssh_config
:
LocalCommand
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.
Вот быстрый пример:
ssh -v -o PermitLocalCommand=yes -o 'LocalCommand=/bin/date >/tmp/test' localhost
Позже вам, вероятно, потребуется поместить эти параметры в соответствующий раздел Host в файле $ HOME / .ssh / config
.
Думали ли вы об изменении вашего файла .bashrc
? Это будет запускаться каждый раз при входе в систему. Если это должно происходить каждый раз, когда кто-то входит в систему, вы также можете изменить глобальный / etc / bashrc
.
ssh -fN
заставит клиента SSH перейти в фоновый режим после соединение установлено, так что вы можете просто дождаться этого и затем выполнить команду.