0

Is there anything like a "local-procedure-call" mechanism in SSH that would allow me to momentarily redirect STD{IN,OUT,ERR} to a process on my workstation, after having SSHed into a remote machine? Perhaps a kludge involving SSH port-forwarding and netcat?

Let's say a client has reported high load on their web server, which I do not normally manage, and installing SSHFS, NFS or any other new package is out of the question.

I decide I need to pipe the apache request logs through my trusty IP address counting script to list the greediest clients. I could SCP / uuencode my script / the log file to / from the server. I could copy and paste $PWD, open a new terminal, and run another SSH command to cat the log file into my local script.

But seconds later I decide I need to block the abusive IPs, and I have a script for that too. Then I find I need another script and another script and pretty quickly SCP / uuencode / pbcopy / copy and paste and juggling terminal windows becomes a drag.

I'd like to just:

$ ssh server.example.com

$ runhere whereis-apache-log.sh
Apache logs found:
wordpress.example.com /var/logs/apache2
example.com /dev/null    
business.example.com /opt/serious_business/logs/apache/usr/logs/nfs/hello_logs/logs/log

$ cd /opt/serious_business/logs/apache/usr/logs/nfs/hello_logs/logs/log

$ pipehome ip-tally.pl < access.log
13.14.15.16 5
1.2.3.4 20
9.10.11.12 46
5.6.7.8 57
17.18.19.20 43728

$ runhere block-forever.py 17.18.19.20
Idris
  • 101
  • 2
  • [ssh multiplexing with ControlMaster](https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing). Not a full solution, but it makes extra connections much faster by skipping auth. – Andrew Domaszek Feb 05 '18 at 22:37

1 Answers1

1

Could you just do this:

workstation$ ssh server cat /var/log/apache/access.log |ip-tally.pl

The cat would be run on server, stdout piped to workstation and ip-tally run locally on workstation with cat output as stdin

ptman
  • 27,124
  • 2
  • 26
  • 45