du -s $I > $TMPfile done (My space web page) sort -rn
du -s $I > $TMPfile done sort -rn $TMPfile rm $TMPfile exit 0 In this script, awk chooses particular bits of information from the /etc/passwd file. Using the colon as a field separator (the -F: option), awk checks whether the third field on each line (the user ID, or UID) is greater than or equal to 500 (by default, the starting point for regular user accounts). If so, that user s home directory (the sixth field) is returned. The for loop cycles through the list returned by awk, and performs a disk usage check on each directory. The results are stored in a unique temporary file (the $$ variable represents the process ID of the running program). The temporary file is numerically sorted and then removed. The results from either of the preceding programs may look like: 936890 /home/jsmith 489349 /home/oracle 20439 /home/wilhelm 748 /home/acorad 8 /home/gandalf 8 /home/johnson 8 /home/cseitz 8 /home/buchanan Cross-Reference The awk command is used to scan a file for particular patterns, based on rules that you provide. It can then output that information in a form that you choose. A script for checking scripts Occasionally, when testing scripts, it s helpful to take a look at what the script has accomplished so far. When called from another shell script, the following script suspends the running program and lets you (via another Terminal window or virtual terminal) look for expected temporary files or altered conditions. This can indicate whether a program is performing as expected, or if it needs a little more work. #!/bin/bash # Count=1 while : do echo -n “$Count Continue? (y/n): ” read ANS case “$ANS” in y|Y) break ;; esac let Count+=1 done exit 0 The colon (:) on the fourth line does absolutely nothing. It functions only as a placeholder, and allows the while loop to repeat until a y or Y is entered (causing the break to exit the loop). The Count variable keeps track of the number of times the loop has run. The -n option to echo suppresses printing the new line and positions the cursor just beyond the Continue? (y/n): prompt to wait for input. A script to kill processes Another example that may be used frequently is the following script to kill processes nicely. This script gives the processes every opportunity to clean up any temporary files, notify the parent process that it is exiting, and terminate quietly. #!/bin/bash
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.