You are not logged in.
Pages: 1
Hoi lads,
I've a script that generally checks a host's health. The output might be (partly) something like this:
x.laptop.x.com
15:31:12 up 4:34, 4 users, load average: 1.31, 1.30, 1.27
===> Checking DMI:
OK: Dell/Lenovo S/N found, x
OK: Asset tag, x
!!=> ipmitool not found, unable to check BMC/console.
!!=> ipmitool not found, unable to check sensor data.
===> Checking SATA HDDs with smartctl:
Port S/N / FW Size Pending sct Reall_sct Uncor_sct Offline_sct End2end CRC MZONE RAW SMART
/dev/sda x 320 GB 0 0 0 0 n/a 0 OK
/dev/sdb OCZ-x 60 GB 0 0 0 0 n/a 0 OK
INFO: 2 HDDs found
===> Checking NICs with magic:
WARN: eth0 up@100, 0 collisions, 0 dropped RX, 0 dropped TX, 0 RX err, 0 TX err
x@x:~/dev/checkhost$
Look at checking SATA HDDs, I used to have tabs separate the headers and all values, but it gets way too wide. I can stick with having Port, S/N & Size separated by tabs, but the rest of the values are either 0 (1 character) or something up to 4 characters (like 2047 reallocated sectors, yikes).
It looks ugly if I separate the values by spaces, because to get a nice "tabbed" output I'd have to hack it together so I know the length of the string, adjust the output depending on that all the time. Is there an easier way?
Cheers,
Last edited by Fackamato (2012-01-08 01:22:33)
Offline
Pipe the output to 'column', e.g..
[karol@black ~]$ echo -e "foo\tbar\tbaz\n1\t12\t123"
foo bar baz
1 12 123
[karol@black ~]$ echo -e "foo bar baz\n1 12 123" | column -t
foo bar baz
1 12 123
Offline
Pipe the output to 'column', e.g..
[karol@black ~]$ echo -e "foo\tbar\tbaz\n1\t12\t123" foo bar baz 1 12 123 [karol@black ~]$ echo -e "foo bar baz\n1 12 123" | column -t foo bar baz 1 12 123
Jesus, how could I have missed this. Thanks a lot, I'll give it a try and report back!
Offline
Another idea:
$ while read -r line; do
printf "%3s %3s %3s\n" $line
done < <(echo -e "foo bar baz\n1 12 123")
foo bar baz
1 12 123
Remember not to quote your var (ie $line).
Last edited by steve___ (2012-01-05 16:57:44)
Offline
Pipe the output to 'column', e.g..
[karol@black ~]$ echo -e "foo\tbar\tbaz\n1\t12\t123" foo bar baz 1 12 123 [karol@black ~]$ echo -e "foo bar baz\n1 12 123" | column -t foo bar baz 1 12 123
Don't mean to bumb in here, but thanks karol that column command is really helpful.
Offline
Thanks guys. SATA check:
x@x:~/dev/checkhost$ sudo ./checkhost.sh --sata
x.laptop.x.com
10:07:47 up 1:03, 4 users, load average: 0.02, 0.13, 0.43
===> Checking SATA HDDs with smartctl:
Port SN/FW Size Pending_sct Reall_sct Uncor_sct Offline_sct End2end CRC MZONE RAW SMART
/dev/sda 12341234123413223423 320GB 0 0 0 0 n/a 0 0 0 OK
/dev/sdb OCZ-1234123412413233 60GB 0 0 0 0 n/a 0 0 0 OK
INFO: 2 HDDs found
Obviously I had to output all text to a file, which I run column on afterwards. Not run column on a per-line basis (stupid me)
Offline
Please remember to mark the thread as solved :-)
Offline
Please remember to mark the thread as solved :-)
Cheers
Offline
Pages: 1