OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Summing Up

We started this chapter with a question. How could we make our sys_info_page script detect if the user had permission to read all the home directories? With our knowl- edge of if, we can solve the problem by adding this code to the report_home_space function:


report_home_space () {

if [[ $(id -u) -eq 0 ]]; then cat <<- _EOF_

<H2>Home Space Utilization (All Users)</H2>

<PRE>$(du -sh /home/*)</PRE>

_EOF_

else

cat <<- _EOF_

<H2>Home Space Utilization ($USER)</H2>

<PRE>$(du -sh $HOME)</PRE>

_EOF_

fi return

}

report_home_space () {

if [[ $(id -u) -eq 0 ]]; then cat <<- _EOF_

<H2>Home Space Utilization (All Users)</H2>

<PRE>$(du -sh /home/*)</PRE>

_EOF_

else

cat <<- _EOF_

<H2>Home Space Utilization ($USER)</H2>

<PRE>$(du -sh $HOME)</PRE>

_EOF_

fi return

}


We evaluate the output of the id command. With the -u option, id outputs the numeric user ID number of the effective user. The superuser is always zero and every other user is a number greater than zero. Knowing this, we can construct two different here docu- ments, one taking advantage of superuser privileges, and the other, restricted to the user’s own home directory.

We are going to take a break from the sys_info_page program, but don’t worry. It will be back. In the meantime, we’ll cover some topics that we’ll need when we resume our work.


Top OS Cloud Computing at OnWorks: