4

This does work:

server:~> history | tail -100   | grep etc
  908  2018-01-17 08:53:43 cd /etc/apache2/vhosts.d/default.d/
  ....
  ....

But this does not:

ssh root@server "history | tail -100 | grep etc"

Why?

guettli
  • 3,591
  • 17
  • 72
  • 123

1 Answers1

9

Apparently bash does not enable history handling when run non-interactively.

You can work around this by starting bash with the -i for interactive option:

ssh root@server "echo history | bash -i | tail -100 | grep etc"
wurtel
  • 3,864
  • 12
  • 15