Chapter 6


1.

List the complete command lines of all the processes belonging to the root user .

the command ps -auxww lists the complete command lines of all processes running on the system. this output can be filtered using the grep command by piping the output of the grep command to the ps command. the final command line would then be ps -auxww  grep root .

2.

Modify the command prompt to display the current working directory.

the command prompt can be set by modifying the ps1 variable. the macro for indicating the current directory is \w . therefore, the following command will set the prompt to the current working directory: $ export ps1='[\w] '

3.

Use cron to run the date command once every 15 minutes.

using the crontab -e command, edit the crontab entries. add the following line to have the date command executed once every 15 minutes: 0-59/15 * * * * /bin/date - /tmp/date.out the line above will cause cron to execute the date command every 15 minutes and send the output to the file /tmp/date.out .

4.

Write a shell script that will maintain a log of users logged on to the system. Logging should happen every 5 minutes.

the following shell script when saved to a file and executed will log the list of current users of the system every 5 minutes into the file /tmp/users.out . remember to set executable permissions for the shell script file using the chmod command (e.g., chmod +x filename ). while true; do sleep 300; date; who; echo `============`; done --/tmp/users.out

Answers

1.

The command ps -auxww lists the complete command lines of all processes running on the system. This output can be filtered using the grep command by piping the output of the grep command to the ps command. The final command line would then be ps -auxww grep root .

2.

The command prompt can be set by modifying the PS1 variable. The macro for indicating the current directory is \w . Therefore, the following command will set the prompt to the current working directory:

 $ export PS1='[\w] ' 

3.

Using the crontab -e command, edit the crontab entries. Add the following line to have the date command executed once every 15 minutes:

 0-59/15 * * * * /bin/date > /tmp/date.out 

The line above will cause cron to execute the date command every 15 minutes and send the output to the file /tmp/date.out .

4.

The following shell script when saved to a file and executed will log the list of current users of the system every 5 minutes into the file /tmp/users.out . Remember to set executable permissions for the shell script file using the chmod command (e.g., chmod +x filename ).

 while true; do sleep 300; date; who; echo "============"; done       >>/tmp/users.out 



Beginning Fedora 2
Beginning Fedora 2
ISBN: 0764569961
EAN: 2147483647
Year: 2006
Pages: 170

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net