Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only parse a single line from lscpu to get the Cpu(s) count. #879

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Gullumluvl
Copy link

Dear Discourse maintainers,

This is intended to fix an error I was getting with discourse-setup on Debian, from line 261:

bash: 12
scaling*                   2: syntax error in expression (error token is "scaling*                   2")

Caused by the parsing of lscpu command retaining 2 lines instead of just the intended one.

This occurs on my PCs with Debian testing (lscpu from util-linux 2.40.2) and Debian stable (util-linux 2.38.1) because it outputs a line formatted like this (in the "Vendor" section):

CPU(s) scaling MHz:                   20%

(I also checked on a machine with CentOS, there the format is CPU MHz: 2700.000).

To avoid that, I made the regex more specific, but I also added an exit statement in awk. Probably just one of these fixes could be used.

I believe the script would have worked with the version prior to this commit from a month ago: d00c2e7

Best,

@pfaffman
Copy link
Contributor

Maybe this is simpler:

lscpu -p|grep -v "#"|wc -l

Here's one AI recommended:

lscpu | sed -n 's/^CPU(s):\s*//p'

These both work inside of a Debian 12 container and Ubuntu 22.04

@Gullumluvl
Copy link
Author

lscpu -p|grep -v "#"|wc -l

This seems best to me, but we must double check with the people using ARM processors, as the commit I mentioned modified this almost exact same line.

Anything expected from me at this point? Sorry I have little experience with contributing to big projects so let me know.

@Gullumluvl
Copy link
Author

Just rebased my branch on top of main, and amended the commit with a fix for localization.

@tgxworld tgxworld self-assigned this Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants