Skip to main content
deleted 4 characters in body
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118

If you are going to call the awk script here, always it's good practice to have a script and call the script so you no need worry about inner variables escaping:

ssh user@localhost "\
    awk -v start=\"$start_time\"start='$start_time' -v end=\"$end_time\"end='$end_time' -v q=\' \
        -f /path/to/awk-script.awk /path/to/log-file"

also note that we used escaped quotes for $start_time and $end_time above with quotes.


awk-script.awk contains:

BEGIN {
        st = "date -d" q start q " +%s"
        st | getline start
        close(st)
        ed = "date -d" q end q " +%s"
        ed | getline end
        close(ed)
}
    
{
        dt = $1 " " $2
        epoch = "date -d" q dt q " +%s"
        epoch | getline dt
        close(epoch)
}

(dt >= start && dt <= end) { print }

If you are going to call the awk script here, always it's good practice to have a script and call the script so you no need worry about inner variables escaping:

ssh user@localhost "\
    awk -v start=\"$start_time\" -v end=\"$end_time\" -v q=\' \
        -f /path/to/awk-script.awk /path/to/log-file"

also note that we used escaped quotes for $start_time and $end_time above.


awk-script.awk contains:

BEGIN {
        st = "date -d" q start q " +%s"
        st | getline start
        close(st)
        ed = "date -d" q end q " +%s"
        ed | getline end
        close(ed)
}
    
{
        dt = $1 " " $2
        epoch = "date -d" q dt q " +%s"
        epoch | getline dt
        close(epoch)
}

(dt >= start && dt <= end) { print }

If you are going to call the awk script here, always it's good practice to have a script and call the script so you no need worry about inner variables escaping:

ssh user@localhost "\
    awk -v start='$start_time' -v end='$end_time' -v q=\' \
        -f /path/to/awk-script.awk /path/to/log-file"

also note that we used escaped $start_time and $end_time above with quotes.


awk-script.awk contains:

BEGIN {
        st = "date -d" q start q " +%s"
        st | getline start
        close(st)
        ed = "date -d" q end q " +%s"
        ed | getline end
        close(ed)
}
    
{
        dt = $1 " " $2
        epoch = "date -d" q dt q " +%s"
        epoch | getline dt
        close(epoch)
}

(dt >= start && dt <= end) { print }
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118

If you are going to call the awk script here, always it's good practice to have a script and call the script so you no need worry about inner variables escaping:

ssh user@localhost "\
    awk -v start=\"$start_time\" -v end=\"$end_time\" -v q=\' \
        -f /path/to/awk-script.awk /path/to/log-file"

also note that we used escaped quotes for $start_time and $end_time above.


awk-script.awk contains:

BEGIN {
        st = "date -d" q start q " +%s"
        st | getline start
        close(st)
        ed = "date -d" q end q " +%s"
        ed | getline end
        close(ed)
}
    
{
        dt = $1 " " $2
        epoch = "date -d" q dt q " +%s"
        epoch | getline dt
        close(epoch)
}

(dt >= start && dt <= end) { print }