linux - Using external variable in awk being passed to ssh in bash -


i'm trying pass external variable $time awk command im running through ssh machine.

time=... pastusers=`ssh -n $host "last -n 10 | awk -v time=$time '{if ($7 > time) print $1}'"` 

is i've done far , command im passing ssh works on own passing through ssh causes fail.

i tried..

pastusers=`ssh -n $host "last -n 10"` | awk -v time=$time '{if ($7 > time) print $1}' 

but ssh call not return new lines awk doesn't right information. have idea pass external variable in tried first or how keep newline characters ssh call in tried second?

i have following test.sh:

#! /bin/bash host=$1 mytime=$2 pastusers=`ssh -n $host "last -n 10" | awk -v time=$mytime '{if($7>time) print $1}'` echo $pastusers 

when run bash test.sh <some_valid_host> 20:00 prints list of users expected, in same line. being in same line expected.

if have file test.txt like:

abc def ghi 

running

words=`cat test.txt`; echo $words 

will print abc def ghi in same line. expected behavior.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -