ubuntu stress

Associate
Joined
22 Jan 2008
Posts
2,218
hi all

i have a test comin up in 2 weeks on ubuntu and i havent a clue how to pass it, i have taken this test now 3 times and i cannot pass it. u must think i am stupid but the teacher is hopeless and i just dont understand his notes. if i fail this test again i will be kick out and i wongt be able to finsh my degree.

i starting to panic now as i been tryin to get my head around it for a month now but i am getting now-where. all i understand is basic command lines such as ls, cp, rm.

if you think i'm thick just take a look at the teacher website for this module.

http://www.copsewood.net/tic/sectheory/weeks1to12.html

i need help of the following topics

-unix pipes
- mounting drives
- grep
- bash
- shell scripting
-awk

thanks in advanced
 
You need to know just the basics of using those tools, or do you need to know the guts of how they work?

Pipes are fairly simple at face value, for instance. Shell scripting is a huge topic. Thick books have been written on the subject. I think you'd get the best responses if you asked specific questions to which you could receive answers on the order of one or two paragraphs; bite size chunks for people who want to help.

Have you read the Wikipedia articles on each to begin with.
 
Looks very easy for a degree module. All these things are easily looked up. Huge areas though, better if you ask a specific question.

Unix pipes:
Everything in *nix is pretty much a file. Now to do communication between processes one can pipe the standard output (stdout) to the standard input pipe of another processes (stdin). This is implemented at a low level using file descriptors.. You can pipe output to files, redirect I/O streams around and generally do lots of useful stuff.

An example of piping stdout from one process to stdin of another processes is doing something like
Code:
ls | grep regex

Mounting drives:
This is trivial.. google it - its also very implementation specific.

Grep:
Ok... regular expressions are based on finite state automata. (I hope you have done an FSM course else this is gonna not make a lot of sense). You craft a pattern which is used to match whatever you want. There called regular expressions because you can only use regular languages for this. Actually crafting regular expressions to be used with grep is easy, understanding the theory behind them is not. If you want this then its gonna take a lot of explaining :p Then you just use "grep regex" on whatever your piping to it (for example like above).

Bash:
Bash is a shell, you type stuff into your terminal emulator and this gets passed off to your shell. Greatly simplified this is really just a big loop which looks something like this.
Code:
   while (command = read_command())
   { 
           execute_command(command); 
           update_prompt(whatever); 
   }
You got loads and loads of different types of shells, bash, fish, dash, tsh, csh etc.. They all basically do the same thing just provide different types of scripting/features/performance.

Shell scripting:
You write scripts which are executed by the shell. Typically you write a shebang line at the top e.g. #!/bin/bash, make your script executable, run it .. then the interpreter (kinda like
above) reads your script line by line and executes it.

Awk: awk is a programming language and a tool which uses that programming language in order to process text (typically). Its used for text manipulation, lots of regex's, search/replace etc..
 
Last edited:
these are the questions that came up in the mock test.

1- write down a command pipeline including use of ls and wc commands with appropriate flags, which count the number of files in the current directory ?


2- write down one or more chmod commands which set the read/write-execute permissions on the file f1 to the following as displayed using ls -l f1 :
-rwxr-w---


3a-write the command you would use to display information from which you could obtain the identity and the name of the parent process of a shell script called your_menu which you have written and which is currently running

3b- how would you read the information displayed by this command to obtain this value



4a- how would you check the current value of the $PATH enviroment variable?


4b- how would you add the working directory "." to this enciroment variable so that programs in the working directory can be executed without needing to put ./ in front of their names ?


5- write a pipelined command making use of grep and awk to print out the UID (numeric userid which is in the 3rd column) of the userid peter in the file /etc/passwd. this file is column delimited using colons "." and the userid is the first column?



q6- write a shell script which checks if the file book.txt exists and is readable.if it is readable your script outputs the numbers of the times each of the 4 following words are used: and, or, if, then in book.txt . your script must also output the total of these 4 numbers. if the file is not readable, the script should output an error message.


Q7-n explain briefly the purpose of a setuid program ?



Q7b- give an example of a system program which runs setuid and explain why it needs setuid?




Q7c- how can you know whether a particular program is a setuid program. which command would you use to find out ?





Q8- how do you run a program in the background ? give an example


Q8b- how do you make an interactive program running in the foregroud stop running without it ending ?



Q8c- how do you cause a program stopped from running to continue running in the background ?




Q8d- how do you casue a program running in the background to go to the foreground ?


i havent a clue how to answer these question nor do i know where to start, the teacher notes are pants and i am stressing out!!!!!!!!!!!11
 
these are the questions that came up in the mock test.

1- write down a command pipeline including use of ls and wc commands with appropriate flags, which count the number of files in the current directory ?

Code:
ls | wc -l

2- write down one or more chmod commands which set the read/write-execute permissions on the file f1 to the following as displayed using ls -l f1 :
-rwxr-w---

3a-write the command you would use to display information from which you could obtain the identity and the name of the parent process of a shell script called your_menu which you have written and which is currently running

Code:
ps -ef | grep your_menu | head -n 1 | awk '{print $3}'

3b- how would you read the information displayed by this command to obtain this value
Using my eyes.

4a- how would you check the current value of the $PATH enviroment variable?

Code:
echo $PATH

4b- how would you add the working directory "." to this enciroment variable so that programs in the working directory can be executed without needing to put ./ in front of their names ?

Code:
export PATH=:$PATH:.

5- write a pipelined command making use of grep and awk to print out the UID (numeric userid which is in the 3rd column) of the userid peter in the file /etc/passwd. this file is column delimited using colons "." and the userid is the first column?

Code:
cat /etc/passwd | grep peter | awk -F: '$0 { print $3 }'

q6- write a shell script which checks if the file book.txt exists and is readable.if it is readable your script outputs the numbers of the times each of the 4 following words are used: and, or, if, then in book.txt . your script must also output the total of these 4 numbers. if the file is not readable, the script should output an error message.

Code:
echo ' #!/bin/sh if [ -r books.txt ]; then count = $(cat books.txt | egrep "and|or|if|then" | wc -l) elif [ -f books.txt ]; then echo "The file 'books.txt' exists but is not readable." else echo "The file 'books.txt' does not exist." fi' > bookexists && chmod +x bookexists && ./bookexists

Q7-n explain briefly the purpose of a setuid program ?

Setuid allows you to execute the program under the access rights of another user/group.. The purpose of this is so that a normal user may perform certain actions which would normally require superuser or the access rights of another user/group.

Q7b- give an example of a system program which runs setuid and explain why it needs setuid?

An example setuid program is /usr/bin/passwd. Allows users to change their own password... reason it needs setuid is so that it can write to the password file (/etc/passwd).

Q7c- how can you know whether a particular program is a setuid program. which command would you use to find out ?

Code:
ls -al /path/filename

Then use my eyes ;-).

Q8- how do you run a program in the background ? give an example

Code:
echo "int main() { while(1) { printf("LECTURER IS A FAG!"}; } } " > program.c && gcc program.c -o program && ./program &

;]

Q8b- how do you make an interactive program running in the foregroud stop running without it ending ?

Send it a SIGSTOP - typically ctrl-z.

Q8c- how do you cause a program stopped from running to continue running in the background ?

Send it a SIGCONT.

Q8d- how do you casue a program running in the background to go to the foreground ?

Same as above really, but noobs want:

Code:
fg

Just read your notes and man pages and stuffz!
 
Last edited:
thats for ** help, i have a look and see what i can do.
that amazing how u can answer those question when u are high!!!!!!!!!!!

anyone else that can give me tips/advice for my exam would be most welcome
 
Back
Top Bottom