Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Reveal Bash Script Development Thread


  • Please log in to reply
322 replies to this topic

#31 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 24 May 2015 - 12:54 AM

[DISCUSSION #4: How to get and output the CPU details?]
 
Just thought I'd take a moment to share what what I've been trying so far. Right now I'm focusing on getting the model names so don't pay much attention to the rest of the code I've got going on. At the moment I'm using a set maximum number of supported CPUs, which is disappointing, but I still can't figure out a way to support an unlimited quantity. While it easy enough to get the number using "wc -l" to count lines from a pipe, and then assigning it to a variable, I have no idea how to proceed beyond that. Perhaps something will come to me in time...
 
On a side note, if you need a multi-cpu machine to test on check out Qemu. It's a virtual machine program that can emulate multiple CPUs even if your host has 1 CPU, but make sure to use kvm support or it will be excessively slow. Personally I've been testing in VMware Player, but when I need to verify the multiple CPU parts then I temporary run Qemu (with some graphics issues). The command I'm using is:
 


qemu-system-x86_64 -cpu qemu64 -smp 2 -enable-kvm -cdrom /home/example1/disc.iso -m 1024 -boot d

- REF: Search UUID: -q%FZOs3agVaFpClGTYdk4ieDvVCZ2Y1TNg2D79YXAt0$CbmkoiEkTimpZYq
 
 

#!/bin/bash
#My Workfile Of Reveal For DISCUSSION #4: How to get and output the CPU details?
#To run the script type "bash /locationofscript/reveal.sh".
#COLLECTS INFO ABOUT CPUS
#-Collects CPU models and makes a variable for the first 4 (still trying to figure out a way to support an unlimited number of CPUs)
#--Collects the model name lines from /proc/cpuinfo
raw_cpu_models=$(cat /proc/cpuinfo | grep -a "model name")
#--Assigns data from line 1 to variable
raw_cpu_model_1=$(echo $raw_cpu_models | head --lines=1 | tail --lines=1)
#--Removes extra text and creates new variable with just the model name
cpu_model_1=${raw_cpu_model_1:13}
#--Assigns data from line 2 to variable
raw_cpu_model_2=$(echo $raw_cpu_models | head --lines=2 | tail --lines=1)
#--Removes extra text and creates new variable with just the model name
cpu_model_2=${raw_cpu_model_2:13}
#--Assigns data from line 3 to variable
raw_cpu_model_3=$(echo $raw_cpu_models | head --lines=3 | tail --lines=1)
#--Removes extra text and creates new variable with just the model name
cpu_model_3=${raw_cpu_model_3:13}
#--Assigns data from line 4 to variable
raw_cpu_model_4=$(echo $raw_cpu_models | head --lines=4 | tail --lines=1)
#--Removes extra text and creates new variable with just the model name
cpu_model_4=${raw_cpu_model_4:13}
#-Collects CPU architecture (this isnt done yet its just some initial code, ignore it)
raw_cpu_arch_1=$(lscpu | grep -a "Architecture")
cpu_arch_1=${raw_cpu_arch_1:23}
#-Collects CPU rated clock rate (needs to be made CPU specfic and duplicated per CPU)
raw_cpu_rcr_1=$(lscpu | grep -a "CPU MHz")
cpu_rcr_1=${raw_cpu_rcr_1:23}
#-Collects CPU running clock rate
#
#-Collects number of cores (needs to be made CPU specfic and duplicated per CPU)
raw_cpu_cps_1=$(lscpu | grep -a "Core(s) per socket")
cpu_cps_1=${raw_cpu_cps_1:23}
#-Detects PAE support (needs to be made CPU specfic and duplicated per CPU)
raw_cpu_pae_1=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "pae")
if [[ "$raw_cpu_pae_1" == "pae" ]]; then
    cpu_pae_1=Yes
else
    cpu_pae_1=No
fi
#-Detects virtualization support
#
#DISPLAYS RESULTS (needs if else rules to decide how many cpu entries need to be displayed)
echo System Information
echo CPUs:
echo "-$cpu_model_1 $cpu_rcr_1 MHz $cpu_cr_1 MHz $cpu_cps_1 core $cpu_arch_1"
echo " -Supports PAE: $cpu_pae_1"
echo " -Virtualization Support: $cpu_vs_1"
echo "-$cpu_model_2 $cpu_rcr_2 MHz $cpu_cr_2 MHz $cpu_cps_2 core $cpu_arch_2"
echo " -Supports PAE: $cpu_pae_2"
echo " -Virtualization Support: $cpu_vs_2"
echo "-$cpu_model_3 $cpu_rcr_3 MHz $cpu_cr_3 MHz $cpu_cps_3 core $cpu_arch_3"
echo " -Supports PAE: $cpu_pae_3"
echo " -Virtualization Support: $cpu_vs_3"
echo "-$cpu_model_4 $cpu_rcr_4 MHz $cpu_cr_4 MHz $cpu_cps_4 core $cpu_arch_4"
echo " -Supports PAE: $cpu_pae_4"
echo " -Virtualization Support: $cpu_vs_4"

Edited by hollowface, 24 May 2015 - 12:55 AM.


BC AdBot (Login to Remove)

 


#32 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 31 May 2015 - 11:58 PM

[DISCUSSION #4: How to get and output the CPU details?]

 

Well, here's what I have so far:

#!/bin/bash
#My Workfile Of Reveal For DISCUSSION #4: How to get and output the CPU details?
#To run the script type "bash /locationofscript/reveal.sh".
#COLLECTS CPU DETAILS
#-Detects the number of CPUs
cpu_count=$(cat /proc/cpuinfo | grep -a "processor" | wc -l)
#-Collects CPU models and makes a variable for the first 4
#--Collects the model name lines from /proc/cpuinfo
raw_cpu_models=$(cat /proc/cpuinfo | grep -a "model name")
#--Assigns data from line 1 to variable
raw_cpu_model_1=$(echo $raw_cpu_models | head --lines=1 | tail --lines=1)
#--Removes extra text and creates new variable with just the model name
cpu_model_1=${raw_cpu_model_1:13}
#--Assigns data from line 2 to variable
raw_cpu_model_2=$(echo $raw_cpu_models | head --lines=2 | tail --lines=1)
#--Removes extra text and creates new variable with just the model name
cpu_model_2=${raw_cpu_model_2:13}
#--Assigns data from line 3 to variable
raw_cpu_model_3=$(echo $raw_cpu_models | head --lines=3 | tail --lines=1)
#--Removes extra text and creates new variable with just the model name
cpu_model_3=${raw_cpu_model_3:13}
#--Assigns data from line 4 to variable
raw_cpu_model_4=$(echo $raw_cpu_models | head --lines=4 | tail --lines=1)
#--Removes extra text and creates new variable with just the model name
cpu_model_4=${raw_cpu_model_4:13}
#-Collects CPU architecture
raw_cpu_arch_1=$(lscpu | grep -a "Architecture")
cpu_arch_1=${raw_cpu_arch_1:23}
#-Collects CPU rated clock rate (needs to be made CPU specfic and duplicated per CPU)
raw_cpu_rcr_1=$(lscpu | grep -a "CPU MHz")
cpu_rcr_1=${raw_cpu_rcr_1:23}
#-Collects CPU running clock rate
#
#-Collects number of cores (needs to be made CPU specfic and duplicated per CPU)
raw_cpu_cps_1=$(lscpu | grep -a "Core(s) per socket")
cpu_cps_1=${raw_cpu_cps_1:23}
#-Detects PAE support (needs to be made CPU specfic and duplicated per CPU)
raw_cpu_pae_1=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "pae")
if [[ "$raw_cpu_pae_1" == "pae" ]]; then
    cpu_pae_1=Yes
else
    cpu_pae_1=No
fi
#-Detects virtualization support
#
#DISPLAYS RESULTS
echo System Information
echo CPUs:
if [[ "$cpu_count" == "4" ]]; then
    echo "-$cpu_model_1 $cpu_rcr_1 MHz $cpu_cr_1 MHz $cpu_cps_1 core $cpu_arch_1";
    echo " -Supports PAE: $cpu_pae_1";
    echo " -Virtualization Support: $cpu_vs_1";
    echo "-$cpu_model_2 $cpu_rcr_2 MHz $cpu_cr_2 MHz $cpu_cps_2 core $cpu_arch_2";
    echo " -Supports PAE: $cpu_pae_2";
    echo " -Virtualization Support: $cpu_vs_2";
    echo "-$cpu_model_3 $cpu_rcr_3 MHz $cpu_cr_3 MHz $cpu_cps_3 core $cpu_arch_3";
    echo " -Supports PAE: $cpu_pae_3";
    echo " -Virtualization Support: $cpu_vs_3";
    echo "-$cpu_model_4 $cpu_rcr_4 MHz $cpu_cr_4 MHz $cpu_cps_4 core $cpu_arch_4";
    echo " -Supports PAE: $cpu_pae_4";
    echo " -Virtualization Support: $cpu_vs_4";
elif [[ "$cpu_count" == "3" ]]; then
    echo "-$cpu_model_1 $cpu_rcr_1 MHz $cpu_cr_1 MHz $cpu_cps_1 core $cpu_arch_1";
    echo " -Supports PAE: $cpu_pae_1";
    echo " -Virtualization Support: $cpu_vs_1";
    echo "-$cpu_model_2 $cpu_rcr_2 MHz $cpu_cr_2 MHz $cpu_cps_2 core $cpu_arch_2";
    echo " -Supports PAE: $cpu_pae_2";
    echo " -Virtualization Support: $cpu_vs_2";
    echo "-$cpu_model_3 $cpu_rcr_3 MHz $cpu_cr_3 MHz $cpu_cps_3 core $cpu_arch_3";
    echo " -Supports PAE: $cpu_pae_3";
    echo " -Virtualization Support: $cpu_vs_3";
elif [[ "$cpu_count" == "2" ]]; then
    echo "-$cpu_model_1 $cpu_rcr_1 MHz $cpu_cr_1 MHz $cpu_cps_1 core $cpu_arch_1";
    echo " -Supports PAE: $cpu_pae_1";
    echo " -Virtualization Support: $cpu_vs_1";
    echo "-$cpu_model_2 $cpu_rcr_2 MHz $cpu_cr_2 MHz $cpu_cps_2 core $cpu_arch_2";
    echo " -Supports PAE: $cpu_pae_2";
    echo " -Virtualization Support: $cpu_vs_2";
elif [[ "$cpu_count" == "1" ]]; then
    echo "-$cpu_model_1 $cpu_rcr_1 MHz $cpu_cr_1 MHz $cpu_cps_1 core $cpu_arch_1";
    echo " -Supports PAE: $cpu_pae_1";
    echo " -Virtualization Support: $cpu_vs_1";
else
    echo "error1: Either no CPUs were detected, or an unsupported number of CPUs are present."
fi

It's overly bulky right now, I still can't support an unlimited number of CPUs, nore can I figure out how to get some of the other details for each CPU in part because I'm using Qemu to simulate a multi-CPU machine, but it only works if the CPUs are identical which makes it difficult to tell if the sources of info I'm using aren't detecting all CPUs or if they are just combining the information. Take "lscpu" for example, it will list 2 CPUs, but then isn't listing their details seperately, is this due to the fact that the details are identical, or because lscpu doesn't support

displaying details for more than one cpu? I have no way to determine this, because when I attempt to simulate 2 different CPUs only 1 shows up under Linux Mint.

 

Perhaps support for multiple CPUs should be dropped from Reveal for now, unless anyone has any ideas?


Edited by hollowface, 31 May 2015 - 11:58 PM.


#33 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 03 June 2015 - 05:22 PM

[DISCUSSION #4: How to get and output the CPU details?]

 

I'm not sure how others feel, but at this point in time I am finding that supporting multiple CPUs is putting too much strain on development. I would still eventually like to see it implemented, but for now I think it's harming this project's ability to move forward, and for that reason I'm calling a vote to decide if the feature should be implemented. I think that if multiple CPU support is dropped this section of the project could be completed relatively quickly.

 

Should support for multiple CPUs be dropped from Reveal? (Yes / No)

 

I vote YES.



#34 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 05 June 2015 - 02:40 PM

[DISCUSSION #4: How to get and output the CPU details?]

 

End of vote. Support for multiple CPUs is now dropped.



#35 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 08 June 2015 - 12:41 AM

[DISCUSSION #4: How to get and output the CPU details?]

 

Well here's my work thus far. I dropped multiple CPU support, and things seem to be working good. I also added in some code specific to my CPU model. Some CPUs tend to have extra info tacked onto the CPU model so I added in some code for mine that excludes that for my model. This makes for a cleaner output. It's also occured to me that given this release of Reveal will be for Linux Mint Cinnamon 64bit that detecting the architecture is kind of a joke, because the user will obviously have to be using one :P, but anyways I've got that working. I also added in some code that if the architecture is detected as x86_64 it will be re-written as X86-64. I still need to do a bit of looking into CPU virtualization, currently the script determines if the user has such using cpu flags, but I'm not sure how many different flags there are out there, currently only vmx and svm are being used in the script. Anyways my submission isn't quite ready, but it's almost done.

 

#!/bin/bash
#My Workfile Of Reveal For DISCUSSION #4: How to get and output the CPU details?
#To run the script type "bash /locationofscript/reveal.sh".
#This script only supports single CPU systems.
#Get CPU model and trim excess text
cpu_model=$(cat /proc/cpuinfo | grep -a "model name" | sed 's/^.............//' | head --lines=1 | tail --lines=1)
if [[ "$cpu_model" == "AMD A10-4600M APU with Radeon(tm) HD Graphics" ]]; then
    cpu_model="AMD A10-4600M"
fi
#Get CPU clock-rate and trim excess text
cpu_clock_rate=$(lscpu | grep -a "CPU MHz" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
#Get CPU rated-clock-rate and trim excess text the front
cpu_rated_clock_rate=$(cat /proc/cpuinfo | grep -a "cpu MHz" | sed 's/^...........//' | head --lines=1 | tail --lines=1)
#Get CPU core count and trim excess text
cpu_core=$(lscpu | grep -a "Core(s) per socket" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
#Detect CPU architecture (The user will always be running an X86-64 CPU, because that's what Linux Mint Cinnamon 64bit requires)
cpu_arch=$(lscpu | grep -a "Architecture" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
if [[ "$cpu_arch" == "x86_64" ]]; then
    cpu_arch=X86-64
fi
#Detect if CPU supports PAE
cpu_pae_raw=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "pae" | head --lines=1 | tail --lines=1)
if [[ "$cpu_pae_raw" == "pae" ]]; then
    cpu_pae=Yes
else
    cpu_pae=No
fi
#Detect if CPUs have virtualization support
cpu_virt_raw_1=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "vmx" | sed 's/vmx/Yes/' | head --lines=1 | tail --lines=1)
cpu_virt_raw_2=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "svm" | sed 's/svm/Yes/' | head --lines=1 | tail --lines=1)
if [[ "$cpu_virt_raw_1" == "Yes" ]]; then
    cpu_virt=Yes
elif [[ "$cpu_virt_raw_2" == "Yes" ]]; then
    cpu_virt=Yes
else
    cpu_virt=No
fi
#Display results
echo System Information
echo CPU:
echo "-$cpu_model $cpu_rated_clock_rate MHz rated $cpu_clock_rate MHz running $cpu_core core $cpu_arch"
echo " -Supports PAE: $cpu_pae"
echo " -Virtualization Support: $cpu_virt"


#36 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 11 June 2015 - 08:23 PM

[DISCUSSION #4: How to get and output the CPU details?]

 

Well, from what I can tell, no additional flags are needed in regards to virtualization support, so I didn't need to do anything there. I added in more detailed comments. This is my submission.

 

#!/bin/bash
#My Submission Of Reveal For DISCUSSION #4: How to get and output the CPU details?
#To run the script type "bash /locationofscript/reveal.sh".
#Get CPU model and trim excess text.
##Cat reads data to a pipe, grep finds lines starting with "model name", sed trims text from the beginning of the line so that just the actual model name remains, and lastly head and tail trim the output to a single line as on mult-CPU systems there will be more than one line. This output is set to the variable "cpu_model". An if statement specific to AMD A10-4600M cpus is then run to trim excess text from the model name.
cpu_model=$(cat /proc/cpuinfo | grep -a "model name" | sed 's/^.............//' | head --lines=1 | tail --lines=1)
if [[ "$cpu_model" == "AMD A10-4600M APU with Radeon(tm) HD Graphics" ]]; then
    cpu_model="AMD A10-4600M"
fi
#Get CPU clock-rate and trim excess text.
##The command lscpu is run, grep is used to detect the CPU clock rate line, sed trims text from the beginning so just the clock-rate is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_clock_rate".
cpu_clock_rate=$(lscpu | grep -a "CPU MHz" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
#Get CPU rated-clock-rate and trim excess text the front.
##Cat reads from a file to get the CPUs listed clock-rate, grep is used to detect the CPU clock rate line, sed trims text from the beginning so just the clock-rate is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_rated_cock_rate".
cpu_rated_clock_rate=$(cat /proc/cpuinfo | grep -a "cpu MHz" | sed 's/^...........//' | head --lines=1 | tail --lines=1)
#Get CPU core count and trim excess text.
##The command lscpu is run, grep is used to detect the CPU cores line, sed trims text from the beginning so just the number is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_core".
cpu_core=$(lscpu | grep -a "Core(s) per socket" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
#Detect CPU architecture. (The user will always be running an X86-64 CPU, because that's what Linux Mint Cinnamon 64bit requires.)
##The command lscpu is run, grep is used to detect the architecture line, sed trims text from the beginning so just the architecture is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_arch". The variable is then checked using an if statement to see if the architecture is "x86_64", if it is the variable is reset to say "X86-64".
cpu_arch=$(lscpu | grep -a "Architecture" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
if [[ "$cpu_arch" == "x86_64" ]]; then
    cpu_arch=X86-64
fi
#Detect if CPU supports PAE.
##Cat reads from a file, grep is used to detect the flags entry, grep is used to search for the "pae" flag, sed trims text from the beginning so just the flag is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_pae_raw". The variable is then checked using an if statement to see if the variable is empty or pae. If it is pae then the variable "cpu_pae" is set to "Yes", if it isn't then it's set to "No".
cpu_pae_raw=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "pae" | head --lines=1 | tail --lines=1)
if [[ "$cpu_pae_raw" == "pae" ]]; then
    cpu_pae=Yes
else
    cpu_pae=No
fi
#Detect if CPUs have virtualization support
##Cat reads from a file, grep is used to detect the flags entry, grep is used to search for the "vmx" flag, sed replaces "vmx" with "Yes", and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_virt_raw_1". The same process is done for the "svm" flag, and assigned to "cpu_virt_raw_2". An if else statement is then used to set the variable "cpu_virt" as "Yes" if either of the other 2 variables is "Yes", or "No" if they aren't. Vmx is for Intel CPUs (VT-x), and svm is for AMD CPUs (AMD-V). This only indicates whether the CPU has virtualization support, not whether it's currently enabled.
cpu_virt_raw_1=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "vmx" | sed 's/vmx/Yes/' | head --lines=1 | tail --lines=1)
cpu_virt_raw_2=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "svm" | sed 's/svm/Yes/' | head --lines=1 | tail --lines=1)
if [[ "$cpu_virt_raw_1" == "Yes" ]]; then
    cpu_virt=Yes
elif [[ "$cpu_virt_raw_2" == "Yes" ]]; then
    cpu_virt=Yes
else
    cpu_virt=No
fi
#Display results
##Echo is used to display the necessary text, in an organized manner, along with the gathered variables.
echo System Information
echo CPU:
echo "-$cpu_model $cpu_rated_clock_rate MHz rated $cpu_clock_rate MHz running $cpu_core core $cpu_arch"
echo " -Supports PAE: $cpu_pae"
echo " -Virtualization Support: $cpu_virt"
 

 

Concerns, questions, or other input are welcome regarding my submission. We want it perfect before it is finalized as a candidate for the vote. At this point I'm assuming no-one else has any submissions for this discussion? So unless there is opposition to mine to work through, this discussion will be ended soon, and no vote will be needed. I'm really excited about the first testing release approaching, and look forward to the eventual first stable release.



#37 NickAu

NickAu

    Bleepin Grumpy Aussie


  •  Avatar image
  • Members
  • 26,114 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Australia

Posted 11 June 2015 - 10:49 PM

 

I'm really excited about the first testing release approaching, and look forward to the eventual first stable release.

Me too.


"When God shuts a Window, he opens a Linux." —Linus 8:7

 

 

 

 


#38 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 12 June 2015 - 05:35 PM

[DISCUSSION #4: How to get and output the CPU details?]
 
End of discussion. There is no need to call vote.

Results:
This is the code we'll implement for getting CPU details. Please note that only code is being used, extra stuff like "to run the script" will be excluded, as it's not been discussed yet.
 
#!/bin/bash
#My Submission Of Reveal For DISCUSSION #4: How to get and output the CPU details?
#To run the script type "bash /locationofscript/reveal.sh".
#Get CPU model and trim excess text.
##Cat reads data to a pipe, grep finds lines starting with "model name", sed trims text from the beginning of the line so that just the actual model name remains, and lastly head and tail trim the output to a single line as on mult-CPU systems there will be more than one line. This output is set to the variable "cpu_model". An if statement specific to AMD A10-4600M cpus is then run to trim excess text from the model name.
cpu_model=$(cat /proc/cpuinfo | grep -a "model name" | sed 's/^.............//' | head --lines=1 | tail --lines=1)
if [[ "$cpu_model" == "AMD A10-4600M APU with Radeon(tm) HD Graphics" ]]; then
    cpu_model="AMD A10-4600M"
fi
#Get CPU clock-rate and trim excess text.
##The command lscpu is run, grep is used to detect the CPU clock rate line, sed trims text from the beginning so just the clock-rate is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_clock_rate".
cpu_clock_rate=$(lscpu | grep -a "CPU MHz" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
#Get CPU rated-clock-rate and trim excess text the front.
##Cat reads from a file to get the CPUs listed clock-rate, grep is used to detect the CPU clock rate line, sed trims text from the beginning so just the clock-rate is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_rated_cock_rate".
cpu_rated_clock_rate=$(cat /proc/cpuinfo | grep -a "cpu MHz" | sed 's/^...........//' | head --lines=1 | tail --lines=1)
#Get CPU core count and trim excess text.
##The command lscpu is run, grep is used to detect the CPU cores line, sed trims text from the beginning so just the number is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_core".
cpu_core=$(lscpu | grep -a "Core(s) per socket" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
#Detect CPU architecture. (The user will always be running an X86-64 CPU, because that's what Linux Mint Cinnamon 64bit requires.)
##The command lscpu is run, grep is used to detect the architecture line, sed trims text from the beginning so just the architecture is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_arch". The variable is then checked using an if statement to see if the architecture is "x86_64", if it is the variable is reset to say "X86-64".
cpu_arch=$(lscpu | grep -a "Architecture" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
if [[ "$cpu_arch" == "x86_64" ]]; then
    cpu_arch=X86-64
fi
#Detect if CPU supports PAE.
##Cat reads from a file, grep is used to detect the flags entry, grep is used to search for the "pae" flag, sed trims text from the beginning so just the flag is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_pae_raw". The variable is then checked using an if statement to see if the variable is empty or pae. If it is pae then the variable "cpu_pae" is set to "Yes", if it isn't then it's set to "No".
cpu_pae_raw=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "pae" | head --lines=1 | tail --lines=1)
if [[ "$cpu_pae_raw" == "pae" ]]; then
    cpu_pae=Yes
else
    cpu_pae=No
fi
#Detect if CPUs have virtualization support
##Cat reads from a file, grep is used to detect the flags entry, grep is used to search for the "vmx" flag, sed replaces "vmx" with "Yes", and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_virt_raw_1". The same process is done for the "svm" flag, and assigned to "cpu_virt_raw_2". An if else statement is then used to set the variable "cpu_virt" as "Yes" if either of the other 2 variables is "Yes", or "No" if they aren't. Vmx is for Intel CPUs (VT-x), and svm is for AMD CPUs (AMD-V). This only indicates whether the CPU has virtualization support, not whether it's currently enabled.
cpu_virt_raw_1=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "vmx" | sed 's/vmx/Yes/' | head --lines=1 | tail --lines=1)
cpu_virt_raw_2=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "svm" | sed 's/svm/Yes/' | head --lines=1 | tail --lines=1)
if [[ "$cpu_virt_raw_1" == "Yes" ]]; then
    cpu_virt=Yes
elif [[ "$cpu_virt_raw_2" == "Yes" ]]; then
    cpu_virt=Yes
else
    cpu_virt=No
fi
#Display results
##Echo is used to display the necessary text, in an organized manner, along with the gathered variables.
echo System Information
echo CPU:
echo "-$cpu_model $cpu_rated_clock_rate MHz rated $cpu_clock_rate MHz running $cpu_core core $cpu_arch"
echo " -Supports PAE: $cpu_pae"
echo " -Virtualization Support: $cpu_virt"

Edited by hollowface, 12 June 2015 - 05:39 PM.


#39 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 12 June 2015 - 05:42 PM

Reveal For Linux Mint 17.1 Cinnamon 64bit 0.1 Testing

This is a testing release, and should only be used by devs, in a testing environment.

#!/bin/bash
#Reveal For Linux Mint 17.1 Cinnamon 64bit 0.1 Testing
#Get CPU model and trim excess text.
##Cat reads data to a pipe, grep finds lines starting with "model name", sed trims text from the beginning of the line so that just the actual model name remains, and lastly head and tail trim the output to a single line as on mult-CPU systems there will be more than one line. This output is set to the variable "cpu_model". An if statement specific to AMD A10-4600M cpus is then run to trim excess text from the model name.
cpu_model=$(cat /proc/cpuinfo | grep -a "model name" | sed 's/^.............//' | head --lines=1 | tail --lines=1)
if [[ "$cpu_model" == "AMD A10-4600M APU with Radeon(tm) HD Graphics" ]]; then
    cpu_model="AMD A10-4600M"
fi
#Get CPU clock-rate and trim excess text.
##The command lscpu is run, grep is used to detect the CPU clock rate line, sed trims text from the beginning so just the clock-rate is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_clock_rate".
cpu_clock_rate=$(lscpu | grep -a "CPU MHz" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
#Get CPU rated-clock-rate and trim excess text the front.
##Cat reads from a file to get the CPUs listed clock-rate, grep is used to detect the CPU clock rate line, sed trims text from the beginning so just the clock-rate is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_rated_cock_rate".
cpu_rated_clock_rate=$(cat /proc/cpuinfo | grep -a "cpu MHz" | sed 's/^...........//' | head --lines=1 | tail --lines=1)
#Get CPU core count and trim excess text.
##The command lscpu is run, grep is used to detect the CPU cores line, sed trims text from the beginning so just the number is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_core".
cpu_core=$(lscpu | grep -a "Core(s) per socket" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
#Detect CPU architecture. (The user will always be running an X86-64 CPU, because that's what Linux Mint Cinnamon 64bit requires.)
##The command lscpu is run, grep is used to detect the architecture line, sed trims text from the beginning so just the architecture is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_arch". The variable is then checked using an if statement to see if the architecture is "x86_64", if it is the variable is reset to say "X86-64".
cpu_arch=$(lscpu | grep -a "Architecture" | sed 's/^.......................//' | head --lines=1 | tail --lines=1)
if [[ "$cpu_arch" == "x86_64" ]]; then
    cpu_arch=X86-64
fi
#Detect if CPU supports PAE.
##Cat reads from a file, grep is used to detect the flags entry, grep is used to search for the "pae" flag, sed trims text from the beginning so just the flag is left, and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_pae_raw". The variable is then checked using an if statement to see if the variable is empty or pae. If it is pae then the variable "cpu_pae" is set to "Yes", if it isn't then it's set to "No".
cpu_pae_raw=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "pae" | head --lines=1 | tail --lines=1)
if [[ "$cpu_pae_raw" == "pae" ]]; then
    cpu_pae=Yes
else
    cpu_pae=No
fi
#Detect if CPUs have virtualization support
##Cat reads from a file, grep is used to detect the flags entry, grep is used to search for the "vmx" flag, sed replaces "vmx" with "Yes", and then head and tail trim the output to a single line in case multiple matches are found. This output is set to the variable "cpu_virt_raw_1". The same process is done for the "svm" flag, and assigned to "cpu_virt_raw_2". An if else statement is then used to set the variable "cpu_virt" as "Yes" if either of the other 2 variables is "Yes", or "No" if they aren't. Vmx is for Intel CPUs (VT-x), and svm is for AMD CPUs (AMD-V). This only indicates whether the CPU has virtualization support, not whether it's currently enabled.
cpu_virt_raw_1=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "vmx" | sed 's/vmx/Yes/' | head --lines=1 | tail --lines=1)
cpu_virt_raw_2=$(cat /proc/cpuinfo | grep -a "flags" | grep -a -o "svm" | sed 's/svm/Yes/' | head --lines=1 | tail --lines=1)
if [[ "$cpu_virt_raw_1" == "Yes" ]]; then
    cpu_virt=Yes
elif [[ "$cpu_virt_raw_2" == "Yes" ]]; then
    cpu_virt=Yes
else
    cpu_virt=No
fi
#Display results
##Echo is used to display the necessary text, in an organized manner, along with the gathered variables.
echo System Information
echo CPU:
echo "-$cpu_model $cpu_rated_clock_rate MHz rated $cpu_clock_rate MHz running $cpu_core core $cpu_arch"
echo " -Supports PAE: $cpu_pae"
echo " -Virtualization Support: $cpu_virt"


#40 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 12 June 2015 - 05:48 PM

DISCUSSION #5: Are there any issues present in the testing release?

Okay, so the first testing release for the primary Reveal script is posted. Remember, testing releases are basically a summary of work to date (on a particular script). Meaning, we take the previous testing release (in this case there isn't one, because this is the first), and add in anything developed in the last discussion (in this case CPU details). Now that the testing release is out, it needs to be tested a bit, if issues are found they need to be addressed during this discussion so that a new testing release can be produced. If no issues are present, then this discussion will be short, and development can move on.

To get a copy of the testing release see the previous post.



#41 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 12 June 2015 - 11:53 PM

[DISCUSSION #5: Are there any issues present in the testing release?]

 

I've tested it on the same virtual-machine I've been developing on, and I haven't noticed any issues.

example1@example ~ $ bash ~/reveal.sh
System Information
CPU:
-AMD A10-4600M 2295.713 MHz rated 2295.713 MHz running 1 core X86-64
 -Supports PAE: Yes
 -Virtualization Support: Yes
example1@example ~ $


#42 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 18 June 2015 - 05:26 PM

[DISCUSSION #5: Are there any issues present in the testing release?]

 

End of discussion. Voting is not applicable to this discussion.

Results:
There do not appear to be any issues present.



#43 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 18 June 2015 - 05:30 PM

DISCUSSION #6: How to get and output the GPU details?

Okay, so we've got the CPU details, now lets get the GPU details. For CPUs we ended up dropping multi-CPU support, currently for GPUs we are still aiming for multi-GPU support, if issues arise we can always call a vote to drop support, or limit support to a specific number.

The details that need to be collected are model-name, and amount of dedicated memory (if applicable), nothing else.

GPU model(s), amount of dedicated GPU memory
- REF: http://www.bleepingcomputer.com/forums/t/575611/reveal-bash-script-development-thread/#entry3702790

Make sure to use proper formatting.

GPUs:
- GPU Model Name (and some details like the amount of dedicated memory)
  - N/A
- REF: http://www.bleepingcomputer.com/forums/t/575611/reveal-bash-script-development-thread/#entry3703764

Some people may prefer to collaboratively develope code within this thread, some may prefer to work on their own but post their ideas along the way to spark ideas in others, while others may prefer to develope on their own and then submit the final result to the thread for discussion and voting. What-ever works for you. I'm hoping we can move through this discussion fairly quickly.

#44 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 18 June 2015 - 06:38 PM

[DISCUSSION #6: How to get and output the GPU details?]

 

Just wanted to share what I've got so far. I'm not sure I'm collecting the correct information so I'll need to test that a bit further, and I haven't started to implement dynamic support yet (so that multiple-GPUs can be detected).

 

#!/bin/bash
#My Workfile For DISCUSSION #6 How to get and output the GPU details?
#Get GPU models and trim excess text.
gpu_models_raw=$(lshw -C display | grep -a "product" | sed 's/^................//')
#Get GPUs dedicated memory, and trim excess text.
gpus_memory_raw=$(dmesg | grep -a "Max dedicated hypervisor surface memory is" | sed 's/^................................................................//')
#Display results
##Echo is used to display the necessary text, in an organized manner, along with the gathered variables.
echo System Information
echo GPUs:
echo "-$gpu_model_1 $gpu_memory_1"


#45 Guest_hollowface_*

Guest_hollowface_*

  •  Avatar image
  • Guests
  • OFFLINE
  •  

Posted 18 June 2015 - 11:08 PM

[DISCUSSION #6: How to get and output the GPU details?]

 

Okay, so here's what I've got so far. I'm currently testing in a vm so I only have 1 gpu, but this code, in theory, will hopefully work to detect an unlimited number of GPUs. I don't like using lshw, it's slow, and adds extra stuff to the output that can't be trimmed off, but haven't found a better way yet. Still not sure if I'm getting memory data from the right entry, as it might be the wrong line.

 

When I run "dmesg | grep drm" I get a few promising lines:

Max dedicated hypervisor surface memory is 0 kiB
[    3.581216] [drm] Maximum display memory size is 32768 kiB
[    3.581218] [drm] VRAM at 0xf0000000 size is 32768 kiB

 

My code so far:

#!/bin/bash
#My Workfile For DISCUSSION #6 How to get and output the GPU details?
#Get GPU models and trim excess text.
#NOTE: I don't like getting the model-name from this source because it causes other stuff to be added to the Reveal output that can't be blocked.
gpu_models_raw=$(lshw -C display | grep -a "product" | sed 's/^................//')
#Get GPUs dedicated memory, and trim excess text.
gpus_memory_raw=$(dmesg | grep -a "Max dedicated hypervisor surface memory is" | sed 's/^................................................................//')
#Merge results from variables (not from files) and add text.
gpu_results=$(pr -tmJ <(echo -$gpu_models_raw) <(echo $gpus_memory_raw) <(echo " dedicated video memory"))
#Display results
##Echo is used to display the necessary text, in an organized manner, along with the gathered variables.
echo System Information
echo GPUs:
echo $gpu_results

 

Here's my test result when using it:

example1@example ~ $ bash ~/reveal.sh
WARNING: you should run this program as super-user.
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.
System Information
GPUs:
-SVGA II Adapter 0 kiB dedicated video memory
example1@example ~ $





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users