Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mystat.sh Script [SOLVED]
#11
You can use a for loop to display your drive information.  Try this code.

Code:
echo -e "\nHard Disk information:"

for Disk in /dev/sd[a-z]
do
    hdmodel=$(sudo /sbin/hdparm -I "${Disk}" | grep 'Model Number' | cut -c 22-)
    hdserial=$(sudo /sbin/hdparm -I "${Disk}" | grep 'Serial Number' | cut -c 22-)
    hdsize=$(sudo /sbin/hdparm -I "${Disk}" | grep 'GB' | cut -c 38-)

    echo -e "\tModel Number : $hdmodel"
    echo -e "\tSerial Number: $hdserial"
    echo -e "\tCapacity: $hdsize\n"

done
Idea  Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime.

Reply
#12
(06-22-2019, 09:31 AM)deck_luck Wrote: You can use a for loop to display your drive information.  Try this code.

Code:
echo -e "\nHard Disk information:"

for Disk in /dev/sd[a-z]
do
    hdmodel=$(sudo /sbin/hdparm -I "${Disk}" | grep 'Model Number' | cut -c 22-)
    hdserial=$(sudo /sbin/hdparm -I "${Disk}" | grep 'Serial Number' | cut -c 22-)
    hdsize=$(sudo /sbin/hdparm -I "${Disk}" | grep 'GB' | cut -c 38-)

    echo -e "\tModel Number : $hdmodel"
    echo -e "\tSerial Number: $hdserial"
    echo -e "\tCapacity: $hdsize\n"

done

Thanks deck_luck..... That is just what I was wanting...LOL 
I have spent 3 days and so many hours trying to figure this out. It seams to me that there are several way of doing things in scripts that get the same information but looks different...Big Grin I am pulling some stuff from the old DOS Batch days, it helps me to understand some of it... I know that you have to go from point A and end at point B with the answer, and that comes from the she stuff in the middle.... :Smile Lots of dust in there..... 

This fix took you what, 5 minutes to come up with....Lol

I know it all takes time to learn stuff, at 65 that is one thing I know for sure.... I'm going to poke at this and see where I was trying to go an understand how it works...

At a glance, I see you created a variable "drive" and then had "hdpram" use the variable "$drive" in all 3 lines. I got that much figured out just at a glance... 

Most differently need to look at "Loops" and see how they work.... Wink

I assume, you are reading the "/dev/sd" stack from some where and inserting that into the "drive" variable and the "do" has something to do with the "[a-z]"
part of the variable.. Just guessing at this point....   Dodgy 

Looks like I have more homework today... HeHeHe!

Thanks again for the help and the coding fix deck_luck....! I may have more questions later...
I have one more issue that I am working on and may ask for help with that... Thanks again!!!

Bruce
**********************************************************
Taglines of the Day:
Today is the tomorrow you worried about yesterday.  Huh 

Everybody remember where we parked. - Kirk

To Boldly Go Where No BBS Has Gone Before. USS Stargazer BBS, Sheridan In.
Reply
#13
 
The /dev/sda[a-z] is standard globbing.  If you do the ls -d /dev/sda[a-z] command you will see the globbing results.  The "for" statement will assign one of the output(s) from the globbing to the Disk variable during each iteration of the loop until the globbing list is empty. If you know there will only be two disks at the most you may wsnt to change the "[a-z]" to "[a-b]" part of the globbing.

When you get some free time I would encourage you to check the linuxcommand.org web site.  It is a reasonable site for learning the command line and understanding bash.  Also, the site has a free "The Linux Command Line, A Book By William Shotts" pdf book.

For a free formal Linux introduction course,  The Linux Foundation in cooperation with edX.org offers a free "Introduction to Linux" online course.  See the following link:

https://www.edx.org/course/introduction-to-linux

The course is free if you do not wish to gain the certificate of completion.  For new Linux users looking to gain a general insight in to Lunix I highly recommend it.
Idea  Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime.

Reply
#14
(06-22-2019, 09:31 AM)deck_luck Wrote: You can use a for loop to display your drive information.  Try this code.

Code:
echo -e "\nHard Disk information:"

for Disk in /dev/sd[a-z]
do
    hdmodel=$(sudo /sbin/hdparm -I "${Disk}" | grep 'Model Number' | cut -c 22-)
    hdserial=$(sudo /sbin/hdparm -I "${Disk}" | grep 'Serial Number' | cut -c 22-)
    hdsize=$(sudo /sbin/hdparm -I "${Disk}" | grep 'GB' | cut -c 38-)

    echo -e "\tModel Number : $hdmodel"
    echo -e "\tSerial Number: $hdserial"
    echo -e "\tCapacity: $hdsize\n"

done

Thanks for the code, very useful.
Reply
#15
(06-22-2019, 11:14 PM)deck_luck Wrote:  
The /dev/sda[a-z] is standard globbing.  If you do the ls -d /dev/sda[a-z] command you will see the globbing results.  The "for" statement will assign one of the output(s) from the globbing to the Disk variable during each iteration of the loop until the globbing list is empty. If you know there will only be two disks at the most you may want to change the "[a-z]" to "[a-b]" part of the globbing.

When you get some free time I would encourage you to check the linuxcommand.org web site.  It is a reasonable site for learning the command line and understanding bash.  Also, the site has a free "The Linux Command Line, A Book By William Shotts" pdf book.

For a free formal Linux introduction course,  The Linux Foundation in cooperation with edX.org offers a free "Introduction to Linux" online course.  See the following link:

https://www.edx.org/course/introduction-to-linux

The course is free if you do not wish to gain the certificate of completion.  For new Linux users looking to gain a general insight in to Linux I highly recommend it.

Thank you again for your help.

That is interesting, I did not know the "ls" would do that .. Big Grin

I may leave it set at [a-z], the script works great on my video main server which has 6 drives... Ok maybe set it to [a-j]... Lol
What I like is that the script also lists the USB drives that are connected with the "global", that is a Bonus....

I will look at the links for sure. I think I have seen that PDF before somewhere...
Once again thanks for the help!
BTW I will add a comment in the script that you helped with the Global section....
LLAP!!

(06-24-2019, 02:48 PM)rick romig Wrote:
(06-22-2019, 09:31 AM)deck_luck Wrote: You can use a for loop to display your drive information.  Try this code.

Code:
echo -e "\nHard Disk information:"

for Disk in /dev/sd[a-z]
do
    hdmodel=$(sudo /sbin/hdparm -I "${Disk}" | grep 'Model Number' | cut -c 22-)
    hdserial=$(sudo /sbin/hdparm -I "${Disk}" | grep 'Serial Number' | cut -c 22-)
    hdsize=$(sudo /sbin/hdparm -I "${Disk}" | grep 'GB' | cut -c 38-)

    echo -e "\tModel Number : $hdmodel"
    echo -e "\tSerial Number: $hdserial"
    echo -e "\tCapacity: $hdsize\n"

done

Thanks for the code, very useful.

Actually rick romig, I am add this to part of your Info script that I got from your GitHub.
I am expanding your script for my needs... Yep! I made sure to add you to the comments about your code that I used... Lol

I will be using this for my own use and will not be posting it anywhere but still it is the right thing to do... Big Grin
Late and thanks for the great script.....
**********************************************************
Taglines of the Day:
Today is the tomorrow you worried about yesterday.  Huh 

Everybody remember where we parked. - Kirk

To Boldly Go Where No BBS Has Gone Before. USS Stargazer BBS, Sheridan In.
Reply
#16
(06-25-2019, 05:30 PM)bescott9944 Wrote:
(06-24-2019, 02:48 PM)rick romig Wrote: Actually rick romig, I am add this to part of your Info script that I got from your GitHub.
I am expanding your script for my needs... Yep! I made sure to add you to the comments about your code that I used... Lol

I will be using this for my own use and will not be posting it anywhere but still it is the right thing to do... Big Grin
Late and thanks for the great script.....

Glad you found one of my scripts useful and that you could build on it.
Reply
#17
(06-22-2019, 08:58 AM)leon.p Wrote:
(06-22-2019, 07:56 AM)bescott9944 Wrote: What I am trying do do is pull the hard drive information from "lsblk" and pull what drives are mounted
[...]
What I want to display is what hdd drives "sda" "sdb" and so on are on the system... 
[...]
I have manage to get "hdparm" to display the "sda" and "sdb" drives when both are there.

'lsblk' is not easily parsable. And using a non-standard tool
is also unnecessary. You can get information about everything
that is mounted simply with 'mount' or with 'df -aTh' or even
with 'cat /proc/self/mounts'. You will have to filter the output,
but that is rather easy.

To only see drives (physical and virtual) you can grep to filter
out the virtual file systems and show only the file systems which
are represented by a file in '/dev':

Code:
mount | grep '^/dev/'
df -aTh | grep '^/dev/'
grep '^/dev/' /proc/self/mounts

Wow Leon.p!
I totally missed this post and I want to thank you for the information!
I was reading through this post (07/10/19) when I seen your post!
Sorry I did not respond sooner!
This information is some good stuff... I learn something new in Linux all the time...

I appreciate all the help from a GREAT bunch here on this board, your all fantastic!!!!
At 65 and time on my hands, this is such a cool learning experience for me!

Thanks again Leon.p...!
**********************************************************
Taglines of the Day:
Today is the tomorrow you worried about yesterday.  Huh 

Everybody remember where we parked. - Kirk

To Boldly Go Where No BBS Has Gone Before. USS Stargazer BBS, Sheridan In.
Reply
#18
Hello,
To get more info on the other issue with the script, check out this Forum Post...
Both issues have been fixed and it now works. Again, Thanks to everyone that helped!

https://www.ezeelinux.com/talk/showthread.php?tid=1013

Good Luck!
LLAP
**********************************************************
Taglines of the Day:
Today is the tomorrow you worried about yesterday.  Huh 

Everybody remember where we parked. - Kirk

To Boldly Go Where No BBS Has Gone Before. USS Stargazer BBS, Sheridan In.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)