I've been given a task to gather some information about a number of computers here at work, and while I could manually find out the info I've decided a one liner should be able to do it. I have a list of users, access to an asset database (which has incorrect info about how much RAM is in a machine) and want to print a list where each line lists a username, hostname and amount of RAM. I've managed to get the info I need to output, but it's irritating me I couldn't get it to output as nicely as I would have liked.
The command I would have loved to have worked is below:
"command that outputs user and device info" | grep 'Dell\|HP' | awk '{printf "%-10s %s\n",$1,$NF,system("ssh " $NF " free -m | grep Mem | awk '{print $2}'")}'
It appears to fall over when I try to awk the results of the system call for ssh, with an unterminated string error at the " after $NF... I have no idea if it should fail here, or if I'm not escaping things I should in the system call etc - I've tried inserting random \ everywhere ;)
I can replace the free -m command with a "cat /proc/meminfo | head -n 1" but this puts the output on a separate line or with a "free -m | grep Mem" but this gets the whole line when I want only the second word/total RAM amount. I'd really love to have each result tidily on one line.
Is it possible to awk the output of a system call made from within another awk command? I know I would be able to do this in a script by holding info in variables and building an output line from two separate commands, but my stubborn brain wants to know how to do this as a one-liner if at all possible!
"ssh \$NF free -m ... "instead| awk '{print $2}'from the end. The nested quotations work fine to be able to use $NF as the hostname for the SSH command, my issue only comes about when I try to awk the output from grepping for Mem in the output of the ssh command. If I drop the awk I get a line with username and hostname, then the whoe Mem line from free when I only want the second word/RAM amount