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 ...
Get Linux and Unix Shell Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.