I got this command that works perfectly on the remote server
perl -ne 'print "$1,$2,$3\n" if /^[^\[]*\[\K([^]]+)[^{]*{[^[]*\["\K([^"]+)(?:(?!SmsJob).)*SmsJob:\K([0-9a-f]+)/' /path/to/file.log
but then when I try to run it locally by saving it as a shell function like so:
function getRemoteLogs()
{
ssh -i $ssh_key_file ubuntu@$1 -t 'perl -ne `print "$1,$2,$3\n" if /^[^\[]*\[\K([^]]+)[^{]*{[^[]*\["\K([^"]+)(?:(?!SmsJob).)*SmsJob:\K([0-9a-f]+)/` /path/to/file.log' > local.txt
}
where $1
is the ip of the remote server
it returns this error:
bash: command substitution: line 0: syntax error near unexpected token `('
bash: command substitution: line 0: `print "$1,$2,$3\n" if /^[^\[]*\[\K([^]]+)[^{]*{[^[]*\["\K([^"]+)(?:(?!SmsJob).)*SmsJob:\K([0-9a-f]+)/'
Unknown regexp modifier "/w" at -e line 1, at end of line
Unknown regexp modifier "/w" at -e line 1, at end of line
Unknown regexp modifier "/w" at -e line 1, at end of line
syntax error at -e line 1, near "18.log
"
Execution of -e aborted due to compilation errors.
how do I do this?
'
.'
properly instead of `?ssh -i $ssh_key_file ubuntu@$1 -t 'perl -ne \'print "$1,$2,$3\n" if /^[^\[]*\[\K([^]]+)[^{]*{[^[]*\["\K([^"]+)(?:(?!SmsJob).)*SmsJob:\K([0-9a-f]+)/\' /var/www/toters/storage/logs/info-2019-02-18.log' > local.txt
'
inside a'
. You need to end the outer quotes, escape the quote, and start the quotes again.