[SOLVED] I get syntax error from awk command when querying a remote server
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Your command works, but please allow me to expand on my issue. When I add a command to identify the remote host (uname -n), it prints the remote host name but then performs the 'df -P' on the local host. Note the hostnames are correct, but the numbers are all identical:
for scf in {20..73} ; do
ssh -q -o "StrictHostKeyChecking no" 192.168.210."$scf" "uname -n"
ssh -q -o "StrictHostKeyChecking no" 192.168.210."$scf" "df -P" | awk '0+$5 >= 40 {print}';done
done
or inline true false
Code:
"uname -n && df -P" | awk '0+$5 >= 40 {print}'
The first will work for sure. I'm out of town right now so I don't have a remote to test the second one against.
The problem with formatting like this is harder to find problems imo.
Code:
for scf in {20..73} ; do ssh -q -o "StrictHostKeyChecking no" 192.168.210.$scf uname -n;df -P | awk '0+$5 >= 40 {print}';done
The reason your df isn't working is this is what you are passing with the above command. In this case you are running the df on the local machine. Hence your results.
Code:
for scf in {20..73} ; do
ssh -q -o "StrictHostKeyChecking no" 192.168.210."$scf" uname -n
df -P | awk '0+$5 >= 40 {print}'
done
Formatting like this is generally easier to read, again imo even if it's more lines. It also makes possible to keep in the 80 character line length which i understand is just good practices in a script.
Last edited by jmgibson1981; 08-05-2021 at 04:34 PM.
do ssh -q -o "StrictHostKeyChecking no" 192.168.210.$scf "uname -n;df -P | awk '\$5>=40 {print}'";done[/code]
One way run awk on the remote host would be to use an escape character i.e backslash to avoid variable expansion.
Thank you Michael
Your solution works, however, it also caught the 9% of the /var mount:
Code:
-bash-4.2$ for scf in {20..73} ; do echo;ssh -q -o "StrictHostKeyChecking no" 192.168.210.$scf "uname -n;df -P | awk '\$5>=40 {print}'";done
Remote-VM201scf001
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/vg00-root 8125880 5311460 2378608 70% /
tmpfs 8133628 508544 7625084 7% /run
/dev/vda1 245671 133086 95382 59% /boot
/dev/mapper/vg00-var 3030800 241028 2616104 9% /var
Remote-VM202scf001
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/vg00-root 8125880 5306844 2383224 70% /
/dev/vda1 245671 133107 95361 59% /boot
/dev/mapper/vg00-var 3030800 236148 2620984 9% /var
Remote-VM203scf001
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/vg00-root 8125880 5311452 2378616 70% /
/dev/vda1 245671 133085 95383 59% /boot
/dev/mapper/vg00-var 3030800 235152 2621980 9% /var
Remote-VM204scf001
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/vg00-root 8125880 5311468 2378600 70% /
/dev/vda1 245671 133086 95382 59% /boot
/dev/mapper/vg00-var 3030800 235052 2622080 9% /var
Neat solution, but it only displays column 5 when I need the whole line to identify the partition
Ah sorry,I somehow managed to completely misunderstand your intention. When I think of it now, of course displaying just the percentage makes little sense.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.