Need assistance is executing unix command

I’m trying to execute a shell script via BigFix, but it’s failing continuously. I’ve tried multiple approaches, directly running the script through BigFix, creating a “.sh” file and executing it, and prefetched the script file before execution, tried with root user, and switch user as werll. However, none of these methods have worked.

Command–free | grep Mem | awk ‘{print $4/$2 * 100.0}’

Tried but failing

  • wait /bin/sh -c “free | grep Mem | awk ‘{print $4/$2 * 100.0}’ > /var/tmp/Memory_report.txt 2>&1”
  • wait /bin/sh -c /bin/free | /bin/grep Mem | /bin/awk ‘{print $4/$2 * 100.0}’ > /var/tmp/Memory_report.txt 2>/var/tmp/memory_error.log

Maybe the open { as they are used in action scripts… try to replace them with {{
If I recall correctly, there is non need to “escape” the closing ones.

1 Like

As @DanieleColi rightly pointed out, you need to escape the curly braces in your command.
Escaping curly brackets in Action Script

In addition, I noticed that the second command is missing the required double quotes around the full shell expression. Please see the corrected version below and give it a try, it should work as expected.

wait /bin/sh -c "free | grep Mem | awk '{{print $4/$2 * 100.0}' > /var/tmp/Memory_report.txt 2>&1" 
wait /bin/sh -c "/bin/free | /bin/grep Mem | /bin/awk '{{print $4/$2 * 100.0}' > /var/tmp/Memory_report.txt 2>/var/tmp/memory_error.log"
3 Likes

@DanieleColi @vk.khurava Thank you both for providing a prompt solution, its working as expected.