Little help with a Bash script
Hello everyone.
First I'd like to say I'm not a programmer or something like that. I made a simple Bash script to get system information. It's working well with my computer [Manjaro] and few others. [Ubuntu and Fedora] So I wanna know is this working with other distributions as well? Anyone can help me? Suggestion are always welcome. Here's my script. Thanks in advance. Code:
#!/bin/bash |
Bump
|
A few comments, although very nice overall :)
1. Does not cater for those of us not using one of the DE's you have listed or maybe just a WM 2. See here for comments on not needing to use cat on any of the lines where you have, ie grep or sed can both read a file 3. You constantly call grep with -i to remove any case sensitivity, yet when calling the sed to remove the same item you make no such requirement. I would suggest that all references with grep to -i are not needed 4. The use of escapes as opposed to simple quoting, ie Product\ Name or just 'Product Name' 5. As grep is not generally doing any heavy lifting, I would simply use sed to search for your item, eg Code:
# current Code:
# current You also the capture the output of your command but never use it?? Maybe you could just test the variables you set if you return what you are looking for? 8. Instead of requiring root, which from a little testing I think (could be wrong) is only needed for the calls to dmidecode, maybe you could put in an if that if not root you get all but dmidecode associated info otherwise you get the lot ... just a thought 9. I notice you have setup 'bold' and 'regular', but then you call the raw form for colours ... why not set that up in a variable to? This way someone else can change to preferred colour in one spot instead of several times throughout your script Hope some of that helps :) |
A few things that come to mind. lsb_release is not installed by default, at least on the Redhat based systems that I use. The same is true for dmidecode. The script will error out on these issues.
|
do not use cat filename | grep whatever, grep whatever filename will work too.
do not use sed pattern1 | sed pattern2 | sed patternX, it can be solved with one single sed for example these lines (8 new processes): Code:
echo "Graphic vendor :" $(glxinfo | grep -i OpenGL\ vendor\ string | sed 's/OpenGL vendor string://g') |
@grail and @pan64 - Got it. Thanks in advance.
|
Here is a quick change up of the same (assuming all applications are installed, as pointed out by Glennzo) and I am unable to change the DE section as I do not currently run
one, ie I use openbox, and don't have a VM with any on: Code:
#!/bin/bash |
Thanks for re-scripting it. I didn't really expect it. As I see linuxquestions.org is very helpful forum. Saying once again THANKS EVERYONE.
@grail - A bit a personal question. As I see you're using Manjaro. Am I know you? |
Can I know output of this command in a computer like i5 or i7?
Code:
sed -n '/cache size/{s/^.*: //p;q}' /proc/cpuinfo Code:
sed -rn '/model name/{s/^.*: |CPU//g;s/G/ &/p;q}' /proc/cpuinfo |
Quote:
I am running on an i7 so here is the output I receive: Code:
$ sed -n '/cache size/{s/^.*: //p;q}' /proc/cpuinfo Code:
$ sed -n '/cores/{s/^.*: //p;q}' /proc/cpuinfo |
I'd like to keep that one. And another one question here. Why did you add same command twice in here? Is it typo?
Code:
Audio card(s) : $(lspci | sed -n '/audio/{s/^.*: //p;q}') $(lspci | sed -n '/Audio/{s/^.*: //p;q}') |
If you look closely you will see that one has a capital A. I was not sure what the first was supposed to return as on my machine your script returned nothing for the first audio item.
|
I would prefer this one:
Code:
lspci | sed -n '/[Aa]udio/{s/^.*: /Audio card(s) : /p}' Code:
# instead of: |
But it did return my audio card twice.
|
Quote:
|
How about this? Is this working?
Code:
#!/bin/bash |
no, at least there is a problem with it (what I found):
it creates 3 files and you ought to use full path for them: XFCE=/tmp/xfce or similar and use $XFCE in the script. Now the execution depends on the current directory. Also instead ps -e | grep you can try pgrep the line: kded4 --version | grep -m 1 'KDE' | awk -F ':' '{print $2}' | awk '{print $1}' is ugly, you can solve it with a single awk kde4 --version | awk ' blabla ' Code:
(I have no kde, so cannot test it, but something like this should do the job) xfce4-session --version | awk '/xfce4-session/{print $2}' |
I would actually still urge against creating any files ... there does not seem to be any point when you could just as easily test a variable within the script as opposed to going
out to a file which you then have to clean up. Plus I find it invasive to have a script create files on my system. I have taken pan64's suggestion about grouping to see if we could help the processing time. See if this helps: Code:
#!/bin/bash |
Thanks for the help everyone. I'll take it.
@pan64, I don't have KDE either. So how can I check is it working or not? Anyway thanks for help. |
I would probably suggest downloading an iso and making a vm with all the different choices you wish to test for and away you go :)
|
Quote:
|
Quote:
Code:
pgrep xfce4-session Code:
#!/bin/bash |
Quote:
Code:
root@host:~$ sed -n '/cache size/{s/^.*: //p;q}' /proc/cpuinfo Code:
root@host:~$ sed -n '/cache size/{s/^.*: //p;q}' /proc/cpuinfo |
Thanks joe_2000.
|
I made it with your help and suggestions. How about this? Any suggestions for this?
Code:
#!/bin/bash |
Bump
|
Please don't 'bump' as everyone is volunteering help so it is perceived as impolite to try and force an answer.
I am still not sure why you persist with using files at all. Also, by using a specific word and not a random name you can hit an issue where you might overwrite a file on someone's system, ie. if /tmp/xfce already exists and you call the following code: Code:
pgrep xfce4-session > /tmp/xfce; XFCE=/tmp/xfce As I have said several times, why not simply store the value in a variable and then test that: Code:
XFCE=$(pgrep xfce4-session) |
Sorry for the "bump".
That's what I want to know. I wanted to store value in a variable too but I stuck at somewhere and I didn't know where it is. So I gave up it. As I see now, I didn't add "[[ .. ]]" before. That's it. Thanks for the help. EDIT : As you see, I'm a noob in this Bash stuff. And I want to say, I didn't refer any Bash/Shell guide to make this so far. So, some of commands may be wrong and stupid. That's why I'm asking for help here. Thanks. |
Well here are a couple to help you investigate further:
http://tldp.org/LDP/abs/html/ http://mywiki.wooledge.org/TitleIndex |
Quote:
To store the result of a command in a variable use: VARIABLE=$(command) - [[ and ]] is used in comparison. Quote:
|
All times are GMT -5. The time now is 07:27 PM. |