O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

16.3. Running a script

Here’s an example of what we have just discussed. Here is a file called cleanup.

						$ pg cleanup 
#!/bin/sh 
# name: cleanup 
# this is a general cleanup script 
echo "starting cleanup...wait" 
rm /usr/lcoal/apps/log/*.log 
tail -40 /var/adm/mesages >/tmp/messages 
rm /var/adm/messages 
mv /tmp/messages /var/adm/messages 
echo "finished cleanup" 

The above script cleans up var/adm/ messages by truncating the file, and deletes all log files in /usr/local/apps/log.

To make the script executable we use the chmod command:

						$ chmod u+x cleanup.
					

Now to run the script, just type the script name

						$ cleanup
					

If you get an error back like this:

						$ cleanup 
sh: cleanup: command not found
					

try this:

						$./cleanup
					

If you have to type a pathname ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required