Linux scripting - Printable Version +- Linux-Noob Forums (https://www.linux-noob.com/forums) +-- Forum: Linux Noob (https://www.linux-noob.com/forums/forum-3.html) +--- Forum: Tips and Tricks (https://www.linux-noob.com/forums/forum-59.html) +--- Thread: Linux scripting (/thread-3916.html) Pages:
1
2
|
Linux scripting - kZo - 2003-12-18 Simple, yet I'm trying to figure out awk. Maybe someone can help me out here. Code: angry:/home/v702623# df -h now if I wanted to just display the /dev/hda3 8.7G 940M 7.3G 12% / how would I go about doing that? Code: angry:/home/v702623# df -h | grep /dev/hda3 However, what if I wanted to take it a step further? Something more like where it displays the output like this. Filesystem: [/dev/hda3] Size: [8.7G] Used: [940M] Free: [7.3G] %Used: [12%] I'd like to learn how to do that. Linux scripting - Guest - 2003-12-18 df -h |grep /dev |awk '{print "Filesystem: " $1 " Size: " $2 " Used: " $3 " Free: " $4 " Use: " $5}' Linux scripting - kZo - 2003-12-18 Thanks a bunch Grep420. Works like a champ. I added the []'s Code: df -h |grep /dev |awk '{print "Filesystem: [" $1 "] Size: [" $2 "] Used: [" $3 "] Free: [" $4 "] Use: [" $5 "]"}' This prints: Filesystem: [/dev/hda3] Size: [8.7G] Used: [978M] Free: [7.3G] Use: [12%] :) Linux scripting - grep420 - 2003-12-18 glad to help Linux scripting - Ritter - 2003-12-18 or you can create an executable file in case any of those ', &, ", or $ get in the way. Code: #!/bin/bash Linux scripting - anyweb - 2003-12-18 tell us how Ritter ! i'd like to know :) being the noob that i am and all that ;) cheers anyweb Linux scripting - kZo - 2003-12-18 Another one to work with. Code: df -h | grep hda3 | sed 's/\(\/dev\/hda3\)\([ ]\+\)\([0-9.GM]\+\)\([0-9.GM]\+\)\(.*\)/Filesystem: \[\1\] Size: \[\3\] Used: \[\4\]/' Linux scripting - kZo - 2003-12-18 Quote:tell us how Ritter ! All you have to do is Code: angry:/# vi hddinfo.pl Edit the file in VI with the following: Code: #!/bin/bash What I did for irssi is then add it to the directory ~/.irssi/alias/hddinfo.pl Then created the alias in irssi like: /alias hdd /exec -o perl /home/v702623/.irssi/alias/hddinfo.pl That will display "Filesystem: [/dev/hda3] Size: [8.7G] Used: [978M] Free: [7.3G] Use: [12%]" Being that it is my hdd. Else without putting it into a perl script, the $1 $2 $3 are alias characters in irssi causing them to be stripped when executing the script itself. Anyway, thanks for your help guys. Linux scripting - kZo - 2003-12-18 Code: ./exec -o df -h |grep /dev/hd |awk '{print "\00314 Filesystem: [\0034\002" $1 "\002\00314] Size: [\0034\002" $2 "\002\00314] Used: [\0034\002" $3 "\002\00314] Free: [\0034\002" $4 "\002\00314] Use: [\0034\002" $5 "\00314\002]"}' That adds color to the output. :] Linux scripting - Digerati - 2003-12-18 I did this: [user@box user]$ cat >> diskfree #!/bin/bash df -h |grep /dev |awk '{print "Filesystem: [" $1 "] Size: [" $2 "] Used: [" $3 "] Free: [" $4 "] Use: [" $5 "]"}' Then hit ctrl d to save it. Then do: [user@box user]$ chmod u+x diskfree Then: [user@box user]$ ./diskfree Filesystem: [/dev/hdb2] Size: [8.8G] Used: [4.0G] Free: [4.3G] Use: [49%] Filesystem: [/dev/hdb1] Size: [101M] Used: [14M] Free: [81M] Use: [15%] Filesystem: [none] Size: [125M] Used: [0] Free: [125M] Use: [0%] |