You are on page 1of 17

Setting priority on new processes

At this point you are probably wondering how you can set
your own priority levels on processes. To change the priority
when issuing a new command you do nice -n [nice value]
[command]:
nice -n 10 apt-get upgrade
This will increment the default nice value by a positive 10
for the command, ‘apt-get upgrade‘ This is often useful for
times when you want to upgrade apps but don’t want the
extra process burden at the given time. Remember a
positive number is gives less priority for a process.

Setting Priority on Existing Processes
Obviously at some point you are going to want to alter the
nice value of something that is already running. Just the
other day I was doing an upgrade to Ubuntu Jaunty and
Firefox started to become unusably slow. A quick renice
command rescheduled the upgrade to a lower priority and I
was back to surfing in no time.
To change the priority of an existing process just do renice
[nice value] -p [process id]:
renice 10 -p 21827
This will increment the priority of the process with an id of
21827 to 10.

 For eg: $ date Case-esac program in shell scripting: Syntax: case word in . $. Shell prompt:  The prompt. is issued by the shell. While the prompt is displayed.Note: Only root can apply negative nice values. Shell scripting:  The shell provides you with an interface to the UNIX system. which is called command prompt.  It gathers input from you and executes programs based on that input. and shell scripts. you can type a command.  A shell is an environment in which we can run our commands. There are different flavors of shells. programs.

... 3)echo “THREE”. 4)echo “FOUR”. ...pattern1) Statement(s) to be executed if pattern1 matches . Esac Example 1: echo ‘Enter any value between 1 to 5’ read num case $num in 1)echo “ONE” . pattern2) Statement(s) to be executed if pattern2 matches.. *)echo “INVALID VALUE”... 5)echo “FIVE”. pattern3) Statement(s) to be executed if pattern3 matches.. esac Note: * indicates default value. 2)echo “TWO”.

If…else: Comparisons: -eq equal to -ne not equal to -lt less than -le less than or equal to -gt greater than -ge greater than or equal to If-else program: Syntax: if [ expression ] then Statement(s) to be executed if expression is true else Statement(s) to be executed if expression is not true fi Example 2: valid_password=”welcome” .

Echo “Enter your password” read PSWD if [ “$PSWD” = “$valid_password” ] then echo “Valid password” else echo “Access denied” fi Example 3: Echo “Enter the number” Read num If test $num –le 30 Then echo “Number is less than equal to 30” else echo “Number is greater than 30” fi if… then… elif: .

Syntax: if [ expression 1 ] then Statement(s) to be executed if expression 1 is true elif [ expression 2 ] then Statement(s) to be executed if expression 2 is true elif [ expression 3 ] then Statement(s) to be executed if expression 3 is true else Statement(s) to be executed if no expression is true fi Example 4: echo “enter the value of a” read a echo “enter the value of b” read b .

if [ $a = $b ] then echo “a is equal to b” elif [ $a –gt $b ] then echo “a is greater than b” elif [ $a –lt $b ] then echo “a is less than b” else echo “INVALID VALUE” fi While loop: Syntax: while command do Statement(s) done Example 5: .

EXP3 )) do command1 command2 command3 done Example 6: for((c=1. EXP2.c++)) do echo “Welcome to STC” .c<=5.echo “Enter the value of a” read a while [ $a -lt 5 ] do a=`expr $a + 1` echo $a done For loop: Syntax: for (( EXP1.

done Until loop: Syntax: until command do Statement(s) Done Example 7: a=1 until [ $a –ge 5 ] do echo “ $a .Welcome to STC” a=$(($a + 1)) done PASSING PARAMETERS: Example 8: (inside a shell program) Echo “First value is $1” .

Echo “Second value is $2” Echo “Third value is $3” (outside shell program. It then steps down to the code following the end of the loop. after completing the execution of all of the lines of code up to the break statement. during execution) sh name. Syntax: Break Example 9: a=0 while [ $a –lt 10 ] do echo $a if [ $a –eq 5 ] then break .sh 10 20 30 Breaking out of loops: The break statement is used to terminate the execution of the entire loop.

except that it causes the current iteration of the loop to exit.fi a=`expr $a + 1` done The continue statement: The continue statement is similar to the break command. rather than the entire loop. Syntax: Continue Example 10: NUMS="1 2 3 4 5 6 7" for NUM in $NUMS do Q=`expr $NUM % 2` if [ $Q -eq 0 ] then echo "Number is an even number!!" . This statement is useful when an error has occurred but you want to try to execute the next iteration of the loop.

[ $a -lt 20 -a $b -gt . This is logical AND. This is logical OR. [ $a -lt 20 -o $b -gt 100 ] is true. If both Example [ ! false ] is true.> Returns “True”. if both condition1 and condition2 are “True” (Like AND operator) || -------. If any one condition is “True” (Like OR operator) Boolean Operators: There are following boolean operators supported by Bourne Shell.> Returns “True”. This inverts a true condition into false and vice versa. Assume variable a holds 10 and variable b holds 20 then: Operator ! -o -a Description This is logical negation.continue fi echo "Found odd number" done LOGICAL OPERATORS: && -------. If one of the operands is true then condition would be true.

otherwise it would be false. Example 11: (For “||” operator) echo “Enter the value of a” read a echo “Enter the value of b” read b if (( a == 1 )) | | (( b == 8 )). b : True if the file exists and is a block special file.the operands are true then condition would be true 100 ] is false.then echo “Enable!!!” else echo “Disable” fi FILE TEST OPERATORS: The different file test operators are listed below: a : True if the file exists. .

f : True if the file exists and is a regular file. s : True if the file exists and has a size greater than zero. h : True if the file exists and is a symbolic link. O : True if the file exists and is owned by the effective user ID. r : True if the file exists and is readable. e : True if the file exists. x : True if the file exists and is executable. t : True if file descriptor is open and refers to a terminal.c : True if the file exists and is a character special file. G : True if the file exists and is owned by the effective group ID. w : True if the file exists and is writable. . k : True if the file exists and its sticky bit is set. p : True if the file exists and is a named pipe (FIFO). d : True if the file exists and is a directory. g : True if the file exists and its SGID bit is set. L : True if the file exists and is a symbolic link. u : True if the file exists and its SUID (set user ID) bit is set.

S : True if the file exists and is a socket. Syntax: (mostly used in “if-loop”) if [ -option filename ] then do something else do something fi Example 12: (bud. for write “ if [ -w $file ]” and for execute “ if [ -x $file ] “) Then Echo “Read access” Else Echo “Read permission denied” fi .sh is an already existing file) file=”bud.N : True if the file exists and has been modified since it was last read.sh” If [-r $file ] (similarly.

.sh Use of set built in command Bash shell offers debugging options which can be turn on or off using set command.Example 13: File=”directory1” If [ -d $file ] Then Echo “Directory is present” Else Echo “Directory is not present” fi Debugging Shell Scripts: -x option to debug a shell script Run a shell script with -x option. $ Bash -x script-name $ bash -x domains. Set -x: Display commands and their arguments as they are executed.

sh . How to execute: Bash –x filename.Set -v: Display shell input lines as they are read.sh Bash –v filename.