Are you sure it was working before you added the loop?
1. your command= line looks like it will break on spaces - that needs to be quoted, I think. In order to avoid escaping quotes-within-quotes you can try
Code:
command="awk -F\: -v a=${l##UID_MIN} -v b=${l1##UID_MAX} '{ if ( $3 >= a && $3 <= b && $7 != /sbin/nologin ) print $0 }' $_p 2>&1 | tee -a users.txt"
2. it looks like you need additional measures to pass the $x awk variables unmolested through ssh - for example
Code:
$ _p=/etc/passwd
$
$ awk -F\: -v a=1000 -v b=5999 '{ if ( $3 >= a && $3 <= b && $7 != /sbin/nologin ) print $0 }' $_p 2>&1 | tee -a users.txt
steeldriver:x:1002:1003:steeldriver:/home/steeldriver:/bin/bash
works, but
Code:
$ ssh 192.168.1.102 "awk -F\: -v a=1000 -v b=5999 '{ if ( $3 >= a && $3 <= b && $7 != /sbin/nologin ) print $0; }' $_p 2>&1 | tee -a users.txt"
awk: line 1: syntax error at or near >=
doesn't; however if I escape the $ characters
Code:
$ ssh 192.168.1.102 "awk -F\: -v a=1000 -v b=5999 '{ if ( \$3 >= a && \$3 <= b && \$7 != /sbin/nologin ) print \$0; }' $_p 2>&1 | tee -a users.txt"
steeldriver:x:1002:1002:,,,:/home/steeldriver:/bin/bash
BTW you may want to have a play with the 'getent' command e.g.
Code:
$ getent passwd {1000..5999}
steeldriver:x:1002:1003:steeldriver:/home/steeldriver:/bin/bash
Also I'd personally use a 'while' loop and avoid $(cat xxx) i.e.
Code:
while read -r host; do ssh "$host" "$command"; done < hosts.txt
Hope this helps
Bookmarks