Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)
kde4 --version | awk ' BEGIN { FS="[ :]"} /KDE/ {a++} a{print $2; exit} '
similar to xfce:
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
bold=$(tput bold)
regular=$(tput sgr0)
red=$(echo -en '\e[1;31m')
green=$(echo -en '\e[0;32m')
not_root()
{
echo -e "${red}\t<=As you are not root the below information is not available=>${regular}"
}
IFS=$'\n'
glx_info=($(glxinfo | sed -n '/GL vendor/ s/^.*: //p;
/direct / s/^.*: //p;
/renderer/ s/^.*: //p;
/GL version/ s/^.*: //p'))
cpu_info=($(sed -rn '/model name/{s/^.*: |CPU//g;s/G/ &/p};
/cache size/{s/^.*: //p;q}' /proc/cpuinfo))
(( EUID == 0 )) && dmi_info=($(dmidecode -t 2,0 | sed -rn '/manufacturer|name|vendor|version|date/Is/^.*: //p')) || is_root=false
IFS=
clear && sleep 1
cat <<-EOF
${green}${bold}System information${regular}
Hostname : $(uname -n)
Operating system : $(lsb_release -sdrc)
Kernel name and version : $(uname -srm)
Total RAM : $(sed -n 's/MemTotal: *//gp' /proc/meminfo)
${green}${bold}Machine information${regular}$($is_root || not_root)
Board manufacturer : ${dmi_info[3]}
Model name : ${dmi_info[4]}
BIOS vendor : ${dmi_info[0]}
BIOS version : ${dmi_info[1]}
Released date : ${dmi_info[2]}
${green}${bold}Processor information${regular}
Processor type : ${cpu_info[0]}
Cache size : ${cpu_info[1]}
${green}${bold}Graphics information${regular}
Graphic card(s) : $(lspci | sed -n '/VGA/{s/^.*: //p;q}')
Graphic vendor : ${glx_info[1]}
Direct rendering : ${glx_info[0]}
GLX renderer : ${glx_info[2]}
GLX version : ${glx_info[3]}
Screen resolution : $(xdpyinfo | awk '/dimensions/{print $2}')
${green}${bold}Audio and network information${regular}
Audio card(s) : $(lspci | sed -n '/Audio/{s/^.*: //p;q}')
Network card(s) : $(lspci | sed -n '/Ether/{s/^.*: //p}')
Network interface(s) : $(ip link | awk -F" *: *" 'NR>2 && /UP/{print $2}')
${green}${bold}Hard drive information${regular}
Root disk free space : $(df -h / | awk 'NR>1{print gensub(/(.)$/," \\1B",1,$4)}')
Root disk mounted at : $(df -h / | awk 'NR>1{print $1}')
SWAP partition mounted at : $(swapon -s | awk 'NR>1{print $1}')
${green}${bold}Location information${regular}
External IP address : $(curl -s ifconfig.co)
Connection type : $(curl -s ifconfig.co/connection)
Country : $(curl -s www.iptolatlng.com?ip=$(curl -s ifconfig.co) | awk -F"\"" '/countryFullName/{print $4}')
${green}${bold}Other information${regular}
Uptime : $(uptime -p | cut -d' ' -f2-)
Shell client : $SHELL
EOF
exit 0
I did look at lspci and df but they may return multiple entries which would then add to the array an unknown amount ... hence I left them
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)
kde4 --version | awk ' BEGIN { FS="[ :]"} /KDE/ {a++} a{print $2; exit} '
similar to xfce:
xfce4-session --version | awk '/xfce4-session/{print $2}'
I didn't understand that "XFCE=/tmp/xfce" stuff. Can you please describe it? And, you mean by "pgrep" is this?
Code:
pgrep xfce4-session
Did you mean something like this?
Code:
#!/bin/bash
pgrep xfce4-session > /tmp/xfce; XFCE=/tmp/xfce
pgrep gnome-session > /tmp/gnome; GNOME=/tmp/gnome
pgrep kde4 > /tmp/kde; KDE=/tmp/kde
if [ -s $XFCE ]; then
echo "Window manager : Xfce" $(xfce4-session --version | grep xfce4-session | awk '{print $2}')
fi
if [ -s $GNOME ]; then
echo "Window manager : GNOME" $(gnome-session --version | awk '{print $2}')
fi
if [ -s $KDE ]; then
echo "Window manager : KDE" $(kded4 --version | grep -m 1 'KDE' | awk -F ':' '{print $2}' | awk '{print $1}')
fi
# End script
echo; exit 0
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
This will have just wiped the file and replaced it with whatever you are doing.
As I have said several times, why not simply store the value in a variable and then test that:
Code:
XFCE=$(pgrep xfce4-session)
if [[ -n $XFCE ]]
...
As for uptime, I guess -p may not be standard, but your current solution does not work very well once your machine has been up for days and not just hours and minutes.
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.
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.
No, you do not need to give it up just ask, how to do this or that, how to solve whatever ....
To store the result of a command in a variable use: VARIABLE=$(command) - [[ and ]] is used in comparison.
Quote:
Originally Posted by Enindu
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.
That is ok, there is no stupid question. Try, practice, and learn....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.