WARNING: This information might be out of date. Before using the information here, ask your supervisor first.
Valid for summer term 2015/2016
Create a script that:
/tmp
directory (folder) creates a subdirectory named osdtask
,
/tmp/osdtask
directory creates a file named rootdir.txt
containing list of all files and directories of the root directory (not including hidden files),
/tmp/osdtask
creates a symbolic link pointing to a file rootdir.txt
and name it odkaz.txt
so that the link is relative (i.e. the link is valid even in case the link and the referenced file are relocated into different directory),
/tmp
directory deletes a subdirectory smazat
(the directory might contain files and directories)
Except for the last point the script should not produce any output.
Hint: see the following commands man
, echo
, cd
, mkdir
, ls
, ln
and rm
.
WARNING: If you debug your script in a public computer (especially the file-server), remember to clean any files and directories you have created in the /tmp
folder.
Create a script that:
/bin/uname -a
command and reads the output into a variable; then executes the program /tmp/osdwrite
and passes it the value of the variable as an argument.
For testing purposes you can create an empty script /tmp/osdwrite
on your local computer.
Each program output goes to a separate line. The script should produce only the specified output.
You can expect that both arguments are always provided.
Example: Script output: (standard output only)
doe_A2.sh /home/student/john_doe/work bin <possible output of the /tmp/osdwrite program>
Error output of your script executed with the bin
and /
parameters:
bin sbin
Hint: see commands basename
, grep
.
Create a script that:
CHYBA1
onto the standard error output and exits with a return value of 1
.
CHYBA2
onto the standard error output and exits with a return code of 2
.
CHYBA3
message onto the stderr.
Example: Script output
7 1587
Hint: see commands wc
, ps
, cut
, kill
.
You might want to try different parameters of the ps
command.
Create a script that reads standard input line by line. For each line read call a function called typsouboru
(the only argument of the function is the line read) that performs the following operations:
DIR <directory_path>
onto the stdout. Use the path in the same form it has been provided (as an argument).
FILE <file_path>
onto the standard output.
INVALID <line_read>
onto the standard error output.
0
if it is a valid file or directory, 1
otherwise.
If at least one INVALID
line has been output, the script outputs onto standard error output a line # ERRORS
where #
stands for the number of invalid lines encountered till the end of the script run . If there were none such line (everything OK) do not output any line.
Example: Script output (stderr in red)
DIR /bin
FILE /bin/bash
INVALID /bin/bin
DIR /tmp
INVALID /tmp/xfile
FILE /etc/passwd
2 ERRORS
Hint: See the read
command
Note: Do not use global variables in the function as the function is also tested outside the script. Use return value.
Create a script that parses an HTML page and finds references to PDF files. Do not download the HTML page, read it from stdin. Your script:
Moreover, the script receives the URL address of the page as a commandline parameter (the URL contains also the page filename, i.e. ''index.html''). This information is usefull when the PDF link is relative.
The script should not provide any other output than specified. An incorrect script usage should be reported to stderr. Stderr can also be used for debuggin purposes.
- You can expect that the HTML page has maximally one PDF reference per line and that the ''<a ...>'' tag is not divided into multiple lines. - URLs of the PDF files are specified absolutely (including ''http://...'') only.
Example output: (red lines are the standard error output)
http://muj.server.cz/prednaska01.pdf http://muj.server.cz/prednaska02.pdf http://muj.server.cz/prednaska03.pdf http://muj.server.cz/cviceni/cviceni.pdf
Hint: see the commands sed
, grep
.