ExamplesOS+Sol - svn and exits. When the script receives...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Example of solutions 1. Command w displays all user that are logged to the system, and produces some information related to their activity. An example of command w output is the following: 19:07:39 up 1 day, 8:19, 2 users, load average: 0.00, 0.12, 0.21 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT laface pts/0 :0.0 18:58 9:14m 0.16s 0.16s bash laface pts/1 :0.0 18:58 0.00s 0.26s 0.03s w Implement an shell script that that takes one parameter form the input line, in the format of the LOGIN time, analyzes the command w output, and displays to the administrator all users that have logged at that time, and the names of their processes. example of solution : #!/bin/bash w | tr -s " " | cut -f 1,4,8 -d ' ' | tail -n +3 | grep $1 | cut -f 1,3 -d ' ' 2. Implement a shell script ( runsvn.sh ) that takes one parameter from the input line. The parameter can only assume the start or stop . When the script receives the parameter start it executes in background the program
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: svn and exits. When the script receives the parameter stop it terminates the execution of program svn (it can obtain its PID by means of command ps ) Example: runsvn.sh start runsvn.sh stop example of solution : #!/bin/bash if [ $1 = "start" ] then #echo "start" svn exit 0 fi if [ $1 = "stop" ] then #echo "stop" a=$(ps | cut -s " " -f 2,9 | grep "svn" | cut -d ' ' -f 2) kill -9 $a exit 0 fi echo "Usage error" 3. Implement a shell script that takes one parameter N from the input line, and produces N terms of the Fibonacci series. In the Fibonacci series, the first two terms are equal to 1 . Every successive term can be obtained by summing the two preceding terms: s(0)=1; s(1)=1; s(2)=s(0)+s(1)=2; s(3)=s(1)+s(2)=3; . . . . s(n)=s(n-2)+s(n-1) example of solution : #!/bin/bash if [ $1 -ge 1 ] then a=1 echo $a fi if [ $1 -ge 2 ] then b=1 echo $b fi for((n=3;n<=$1;n++)) do c=$[$a+$b] echo $c; a=$b b=$c done...
View Full Document

This note was uploaded on 11/04/2008 for the course INF EE056K taught by Professor Laface during the Winter '08 term at Politecnico di Torino.

Page1 / 2

ExamplesOS+Sol - svn and exits. When the script receives...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online