I have the following shell script:
#!/bin/bash
top -n 1 -p $(pgrep -d',' -f R) | grep R | awk '{if ($2 != "PID" && int($10) > 50)
{
kill_cmd = "echo kill " $1 " | bash -";
system(kill_cmd);
}}'
If I change the system call to a print statement the resulting output looks as I expect: echo kill <some_pid> | bash - I am also able to run the output from the print statements without error.
The system call errors out stating: syntax error near unexpected token `('
The intent of the script is to use top to look at running R processes and kills them if they are using more than 50% of the system memory.
print "<" kill_cmd ">"before the system() call then runcat -v script; ./scriptand copy/paste the result into your question so we can see exactly the command you are running and the output plus error message it produces.