I want to read logs conveniently from my server. I'm trying to write a script that reads output of journalctl from my server, applying the parameters I pass to the script to journalctl call. I may want to apply various filters, so I want arguments to my script to translate to journalctl's arguments. For example
bin/log --since '2 days ago'
would run
ssh host journalctl --since '2 days ago'
I tried this:
#/usr/bin/env bash
ssh host journalctl "$@"
But when I call
bin/log --since '2 days ago'
I just says:
Failed to parse timestamp: 2
Ok, we got an argument with spaces that seems to transform to multiple arguments when passed as part of a command over SSH. Then I tried something like this:
#/usr/bin/env bash
ssh host bash -c 'journalctl autotests "$@"'
You can guess that doesn't do what I need.
How the hell do I pass $@ over ssh?
@Qmodifier adds bash-compatible quoting/escaping. In some (rather obscure) situations, if the remote shell is something other than bash, it might not parse the quoting/escaping as expected, leading to weird problems. – Gordon Davisson Sep 19 '23 at 01:54@Quse ANSI-C quoting mode, which I think only bash, zsh, and ksh support), or\\or\'or ends with\(which cause trouble because fish interprets\\and\'inside single-quoted strings). – Gordon Davisson Sep 19 '23 at 17:04