Ftp web hosting - then mkdir $DIR cp /home/grd/proj/template $DIR/file_def fi let
then mkdir $DIR cp /home/grd/proj/template $DIR/file_def fi let Count+=1 done The preceding loop creates a directory, if the directory doesn t already exist, and copies a template file to it. This repeats until the value of the COUNT variable is equal to 34 (requiring 33 iterations). Trying some simple shell scripts Sometimes the simplest of scripts can be the most useful. If you type the same sequence of commands repetitively, it makes sense to store those commands (once!) in a file. Here are some examples of simple, but useful, shell scripts. A simple backup script If you ve been collecting data for a research project for the past two years, you ll want to keep backup copies of your work in case something should happen to the original files. Rather than type out the full command each time you d like to make a backup, simply store the commands in a shell script: #!/bin/bash # mt /dev/rft0 rew cd /home/rp008a/data tar cvf /dev/rft0 mt /dev/rft0 rewoffl exit 0 This script runs the mt command with the rew option to rewind the tape in the tape drive, attached to the floppy controller (/dev/rft0). Next, the cd command changes the current directory to /home/rp008a/data. The tar command creates the archive (c) from files in the current directory, verbosely (v) describes what it is doing, and outputs the archive file to the tape device (f /dev/rft0). Then the mt command rewinds and ejects the tape (rewoffl) from the tape device (/dev/rft0). For further automation, see the section on the cron facility later in this chapter. Cross-Reference It is just as important to back up the operating system. See Chapter 13 for details on backing up and restoring files. Scripts to check disk space Another common administrative issue is disk space, a resource that always seems to be in short supply. If you find yourself regularly checking the size of users home directories, the following script may be handy: #!/bin/bash # cd /home ; du -s * | sort -rn Cross-Reference Use the -h option with du to make the output of du friendlier. This script looks at all directories in /home and reports on their size in kilobytes. The output is sorted numerically, with the largest directory at the top of the list. If you have users with home directories other than the /home directory, the following (slightly more complex) script is more useful: #!/bin/bash # TMPfile=/tmp/sh$$tmp for I in `awk -F: { if ($3 >= 500) print $6 } /etc/passwd` do
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.