Tuesday, March 06, 2007

Create a Shell Function via the Command Line

On occasion we create shell functions on the command line to facilitate system administration tasks. Their clear advantage is speed because they are stored in a computer's main memory. These functions can also be setup in a script file or in a .profile file.

Here's an example.
#currentusers
{
date
echo Users currently on the system
who
}

Displays the the users who are currently logged on
#currentusers

To unset the function
#unset currentusers

And here's one more example.
#pingtest
{
date
for i in 1 2 3 4 5
do
ping wkstn$i
done
echo pingtest done
}

Shows workstation pings
#pingtest

To unset the function
#unset pingtest

No comments: