0

I need to run a program with a bash script. This program may require a larger than default message queue.

I know I can increase it with:

sudo sysctl fs.mqueue.msg_max=3000

And I could, for instance, check it with:

echo  "$(sysctl fs.mqueue.msg_max)"

which would print, for instance fs.mqueue.msg_max = 100"

I need to create a conditional if to increase the size if it is less than a threshold value (and do nothing otherwise).

I expected it to look like:

queue_size=$(sysctl fs.mqueue.msg_max)

if (($queue_size < 3000))
then
    sudo sysctl fs.mqueue.msg_max 3000
else
    echo "message queue large enough at $queue_size"
fi

But this returns:

((: fs.mqueue.msg_max = 200 < 3000: syntax error: invalid arithmetic operator (error token is ".mqueue.msg_max = 200 < 3000")

As queue_size received an object which is not the queue size, but something I don't understand nor know how to manipulate.

1 Answer 1

1

You need to extract only the number from your output. You can do this with awk:

queue_size=$(sysctl fs.mqueue.msg_max | awk -F= '{print $2}')

or cut:

queue_size=$(sysctl fs.mqueue.msg_max | cut -d= -f2)

or simply with bash parameter expansion:

queue_size=$(sysctl fs.mqueue.msg_max)
queue_size=${queue_size#*=}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .