You are not logged in.
Please move this if required.
I'm not sure if I have a problem with my RAM (there are reasons I may think this that I won't go into), or a problem with conky, but the symptom is that conky's own memory bar will suddenly report either 0% used and the bar will show full, or it will work. As debugging, I decided to replace the internal function with a bash script and see how that goes, but here's the rub. If I enter:
TOT=`free | grep Mem | awk '{print $2}'` ; USED=`free | grep Mem | awk '{print $3}'` ; MEMUSED=`echo $USED/\($TOT/100\) | bc` ; echo $MEMUSED%into a terminal, it works just fine, outputting the used RAM as a percentage of the total.
However, this simple script:
#!/bin/bash
TOT=`free | grep Mem | awk '{print $2}'` ; USED=`free | grep Mem | awk '{print $3}'` ; MEMUSED=`echo $USED/\($TOT/100\) | bc` ; echo $MEMUSED%outputs diddly squat.
Why?
EDIT: even a script with just the #!/bin/bash header and
TEST=`free | grep Mem` ; echo $TESToutputs nothing
Last edited by Roken (2019-09-29 16:26:46)
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
Just a hunch, but I bet it has to do with the back-ticks. Try replacing ` ... ` with $( ... )
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way
Offline
Maybe locale related? Try specifying it in your script:
#!/bin/bash
LANG=C
TOT=`free | grep Mem | awk '{print $2}'` ; USED=`free | grep Mem | awk '{print $3}'` ; MEMUSED=`echo $USED/\($TOT/100\) | bc` ; echo $MEMUSED%Or simplify:
Print all with label:
free | awk 'FNR>1{print $1 $3/($2/100)"%"}'Print only mem without label:
LANG=C free | awk '$1~/Mem/{print $3/($2/100)"%"}'Last edited by Swiggles (2019-09-26 20:21:26)
Offline
Also, awk and grep are redundant: eg.,
free | awk '/Mem/ {print $2}'Offline
Nope. None of the suggested solutions works in a script (but work directly in a terminal).
This has had me stumped for a week. All of my other personal scripts work. I deleted this one and started again, but it just doesn't want to output anything (and since I'm planning on using it in conky, output is kinda required)
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
The script is executable, right?
set -x
Offline
Please give the output of
pacman -Qo /bin/bash
pacman -Qkk bashAlso try some other shell in your shebang.
Edit:
What is the output of "free"?
Last edited by Swiggles (2019-09-26 21:12:33)
Offline
EDIT: even a script with just the #!/bin/bash header and
TEST=`free | grep Mem` ; echo $TESToutputs nothing
run only "free" to see what is actually printed, but I'm w/ Swiggles initial guess and would "export LC_ALL=C", also you should drastically simplify this (as mentioned by everyone ;-)
#!/bin/sh
LC_ALL=C free | awk '/Mem/ {print 100*$3/$2"%"}'Offline
OK, in order:
yes, the script is executable:
-rwxr-xr-x 1 steve 65 Sep 27 06:13 memfree$pacman -Qo /bin/bash
/usr/bin/bash is owned by bash 5.0.011-1
$pacman -Qkk bash
backup file: bash: /etc/bash.bashrc (Modification time mismatch)
backup file: bash: /etc/bash.bashrc (Size mismatch)
warning: bash: /usr/bin (UID mismatch)
bash: 241 total files, 1 altered file
$free
total used free shared buff/cache available
Mem: 16395012 1503444 14112220 154200 779348 14447412
Swap: 18754556 0 18754556I've also tried with one of the simplified options (I would have gotten around to simplifying, the original script was whilst I was working on getting where I wanted to be) with the same result.
I'm not sure about the UID mismatch but other scripts work fine ![]()
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
set -x
Offline
jasonwryan wrote:set -x
This. Your one-liner works for me in a script.
Offline
When
run only "free" to see what is actually printed
seth meant "in the script" - we know it works in the interactive shell.
We know
TEST=`free | grep Mem` ; echo $TESTfails, we know the simplified version w/o variable assignment fail, if "free | grep Mem" produces no output, "Mem" is not in the output of "free" or grep is broken (but the awk only versions alos failed…)
Offline
If I take the original one-liner, place it in a file (broken.sh), change it to executable (chmod +x broken.sh) and execute it from the command line, I get the same results as if I execute the one-liner directly from the command line. I don't think my environment is much different from yours but if I execute 'pacman -Qkk bash' I do not get any errors. Also, my system shows a bash in both /bin and /usr/bin with the same inode number (hard link). Have you tried a shebang of '#!/usr/bin/env bash'?
Offline
Thanks, all. I took a different approach. Since this is to replace the conky builtin memory bar, I simply built it in to conkyrc directly, and it's working fine that way. For info:
${color5}RAM:$color8}${goto 70}${execbar free | awk '$1~/Mem/{print $3/($2/100)}'}${alignr}${color}${exec free | awk '$1~/Mem/{printf "%0.0f\n",$3/($2/100)"%"}'}%Last edited by Roken (2019-09-28 09:58:55)
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
I'm glad you have a solution that worked for you. But you were given several suggested diagnostic tests in this thread, some of them repeated multiple times and you ignored almost every single one of them. Do not ask for help here if you don't want help. If you only intend to track your independent progress ignoring almost all input, then do so on a blog.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
But you were given several suggested diagnostic tests in this thread, some of them repeated multiple times and you ignored almost every single one of them.
My apologies.
ALL of the diagnostic tests had the same result. Absolutely nothing.
Do not ask for help here if you don't want help.
Nice attitude.
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
You got "Absolutely nothing" with either running "free" or "set -x" on top of the script?????
Nothing like is "Absolutely no output"???
Offline
Absolutely nothing. i.e. it returned to the prompt with diddly squat.
steve@Tex:(11:13)~$ cat scripts/memfree
#!/bin/bash
set -x
free
steve@Tex:(11:13)~$ memfree
steve@Tex:(11:13)~$ Oh, and before you ask, the path is in $PATH, and in fact, all the other scripts there work.
Last edited by Roken (2019-09-29 10:15:33)
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
What is
whence memfree?
Offline
And the output of `pacman -Qo bash` and `pacman -Qkk bash` returned absolutely no results? I highly doubt that. And you tried another shell in the shebang? I'm doubting that too. In any case, there's nothing more to be done here so I'll leave it be.
@swiggles, isn't `whence` a zsh-only command?
Last edited by Trilby (2019-09-29 12:35:58)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
@swiggles, isn't `whence` a zsh-only command?
ksh is the origin I think, but you might be right, I am so used to zsh myself. Good catch, sorry!
Use "type" instead for bash (is the same as "whence -v"):
type memfreeOffline
my $0.02
ewaller@odin/home/ewaller % ls -l test
-rwxr-xr-x 1 ewaller ewaller 24 Sep 29 08:40 test
ewaller@odin/home/ewaller % cat test
#!/bin/bash
set -x
free
ewaller@odin/home/ewaller % test
ewaller@odin/home/ewaller[1] % which test
/usr/bin/test
ewaller@odin/home/ewaller % ./test
+ free
total used free shared buff/cache available
Mem: 16328056 1836048 1050568 332740 13441440 13817324
Swap: 46283772 26112 46257660
ewaller@odin/home/ewaller % Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way
Offline
@Trilby
Output of -Qo and -Qkk in post #9
Honestly, whilst I would like to know the reason for this, if people are going to criticize me for not responding to tests, please check that I haven't, first. I was brought up in an age when we learned it's nice to be nice, and to check.
Last edited by Roken (2019-09-29 16:14:23)
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
Check what memfree is actually resolved to because there's no way the script is executed at all.
You may also try to invoke it by its full path.
Offline
Seth, you may have it. Naming it memfree seems to be the problem, and there is a library by the same name. Renaming gets it going.
I have no idea what memfree actually is, but gonna make this solved.
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline