Keeping a Diary


It is often useful in troubleshooting and when dealing with the CRC Support staff to have a detailed recording of what you are doing e.g., attempting to compile or run. If the support member has information about what is in your PATH variable etc., they may be able to more quickly help you identify and resolve the problem. To facilitate this information transfer, a script is shown below which will allow the user to create a diary of the actions they have taken including a record of all of the environment variables in their session.

Diary Shell Script


if [ ${#} -ge 1 ]

echo "******************** "${diary}" ********************" | tee $diary
echo "" |tee -a $diary
echo "*** ENVIRONMENT VARIABLES **************************************** BEGIN" | tee -a $diary
printenv |tee -a $diary
echo "*** ENVIRONMENT VARIABLES **************************************** END" |tee -a $diary
echo "" |tee -a $diary

for i in "$@"; do
    if [ "${i}" == "${diary}" ]; then

    echo "" |tee -a $diary
    echo "*** "${i}" **************************************** BEGIN" |tee -a $diary
    ${i} 2>&1 | tee -a ${diary}
    echo "*** "${i}" **************************************** END" |tee -a $diary


There are three primary usages of this script as it is shown above with three similar yet different outcomes:

Usage (1)


This usage prints the environment variables to stdout and to the file DIARY.txt.

Usage (2)

$ Example.txt

This usage prints the environment variables to stdout and to the file Example.txt.

Usage (3)

$ Example.txt exe1 'exe2 <options>' ...

This usage does the same as usage (2) while additionally running exe1 while printing the output to stdout and Example.txt followed by running exe2 with its options and printing its output as well. The script will accept n commands and execute them sequentially with each command's output clearly sectioned by the headers and footers

*** command **************************************** BEGIN
*** command **************************************** END