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

CPU load read creating math error #479

Closed
Rycieos opened this issue Oct 31, 2016 · 2 comments
Closed

CPU load read creating math error #479

Rycieos opened this issue Oct 31, 2016 · 2 comments
Labels
bug CPU load Related to the CPU load data or display

Comments

@Rycieos
Copy link
Collaborator

Rycieos commented Oct 31, 2016

Shell: bash
Operating system: SunOS
Liquid Prompt version (tag, commit): latest, 9c1c8a3

Reading error for CPU usage on SunOS. On prompt creation, bash will spit an error:
bash: local: 33,/28: syntax error: operand expected (error token is "/28")

After turning on debug, I was able to trace the error to line 1484, which is doing division on the variable lp_cpu_load. This var is set in the function _lp_cpu_load, specificly at line 204. This runs uptime, and filters through awk.

Output:
4:51pm up 27 day(s), 5:41, 8 users, load average: 0.32, 0.35, 0.40
The problem is that the awk does not remove the comma after the first load number, creating the following command: 33,/28, which bash cannot evaluate with the comma in there.

I have no idea where this problem came from, as my versions of uptime have not changed, and as far as I can tell this version of the code has been running this way for a long time. Regardless, should be an straightforward fix to change the awk command to something smarter.

@dolmen dolmen added CPU load Related to the CPU load data or display bug labels Oct 31, 2016
@Rycieos
Copy link
Collaborator Author

Rycieos commented Nov 1, 2016

Replacing the awk with this sed command fixes the problem (and removes one of the last two uses of awk from liquidprompt! )
sed 's/.*load average: *\([0-9.]*\).*/\1/'

@Rycieos
Copy link
Collaborator Author

Rycieos commented Nov 28, 2016

Fixed in pull #480

@Rycieos Rycieos closed this as completed Nov 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug CPU load Related to the CPU load data or display
Projects
None yet
Development

No branches or pull requests

2 participants