• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Some (probably easy) bash scripting help

finalgt

Supreme [H]ardness
Joined
Aug 3, 2002
Messages
5,506
Okay, I feel like I need to bow to the Linux gods on this one. Been at it for 2 hours now with no luck, and my Google Fu is spectacularly unhelpful. Here's the deal:

I have a bunch of different servers that have a bunch of LSI RAID controllers that I need to run a command on to output SMART data. The problem with LSI is that it assigns the individual drives totally random 'id' numbers; anywhere from 7 up to the high 30s. I know that I can do:

Code:
for i in seq '0 40'`; do echo; echo "Port $i:"; sudo ./smartctl -a -d megaraid,$

But the problem is that I then get a bunch of completely meaningless lines for drive ids that *aren't* on that system. Is there any way to filter those out completely? For instance, have it check the entire sequence, but not output all of the drive ids that are not in the system? Or, I guess even more ideally, somehow coming up with a command that only checks the drive ids that ARE in the system (i.e., that don't return an error for "megaraid,$i")? I looked up using sed to accomplish it, but damned if I can get it working.
 
Tiny amount of progress:

Code:
censored$ devid=$(/opt/MegaRAID/MegaCli/MegaCli -LdPdInfo -aALL|awk '/Device Id/ {print$0}'); echo $devid
Device Id: 29 Device Id: 17 Device Id: 20 Device Id: 21 Device Id: 18 Device Id: 19 Device Id: 22 Device Id: 28 Device Id: 24 Device Id: 25 Device Id: 26 Device Id: 27
How do I get the instances of "Device Id:" out of there and make the numbers the values of a sequence? Is there any way?
 
Code:
censored$ devid=$(/opt/MegaRAID/MegaCli/MegaCli -LdPdInfo -aALL|sed -n -e "s/Device Id: //p"); echo -e "$devid"
29
17
20
21
18
19
22
28
24
25
26
27
Alright, just a little bit further...now, the question is, how do I get the system to run ./smartctl -a -d megaraid,$devid for each of those values?
 
Code:
devid=$(/opt/MegaRAID/MegaCli/MegaCli -LdPdInfo -aALL|sed -n -e "s/Device Id: //p") | xargs ./smartctl -a -d megaraid,$i /dev/sda | awk '/Device|Serial|^read|^write|^verify|^Non-medium/ {print $0}';
Looks like it's stopping after the first running device id. How do I get it to repeat for all the device IDs it finds on the system?
 
By default, xargs is meant to be used for something like cat that can take multiple files as input. You might have some luck with the --max-args flag.
Alternately, there's always looping.
 
Code:
for i in $(/opt/MegaRAID/MegaCli/MegaCli -LdPdInfo -aALL|sed -n -e "s/Device Id: //p");do ./smartctl -a -d megaraid,$i /dev/sda | awk '/Device|Serial|^read|^write|^verify|^Non-medium/ {print $0}'; done

Whats wrong with looping it?
 
either stick them into an array and loop them or implicitly define them in a loop.
 
Back
Top