Regular expression and tools
I hope I'm posting this message to the correct group.
I need to find the amount of disk space currently occupied in percentages. This is relatively easy: /bin/df -k / It outputs the following: Filesystem 1K-blocks Used Available Use% Mounted on /dev/hda1 60476036 9084940 48319068 16% / From within a bash shell script, I have to get the number 16. Meaning, I have to look for digits before a percent sign. I know I have to use regular expressions and something called a backreference but I haven't been able to accomplish that. Please provide good links if you know about and a code sample for a solution if possible. |
#!/bin/bash
diskSpace=`/bin/df -k / | perl -ne '/ (\d+)% /; print $1'` echo "diskSpace=$diskSpace" if [ $diskSpace -gt 90 ]; then echo "Disk space is running low." fi |
Without Perl, this is one way of doing the above:
Code:
#!/bin/bash Håkan |
All times are GMT -5. The time now is 10:10 PM. |