Search
WARNING: This information might be out of date. Before using the information here, ask your supervisor first. Valid for summer term 2015/2016
WARNING: This information might be out of date. Before using the information here, ask your supervisor first.
Create a script that:
/tmp
osdtask
/tmp/osdtask
rootdir.txt
odkaz.txt
smazat
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.
man
echo
cd
mkdir
ls
ln
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.
/bin/uname -a
/tmp/osdwrite
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
/
bin sbin
Hint: see commands basename, grep.
basename
grep
CHYBA1
1
CHYBA2
2
CHYBA3
Example: Script output
7 1587
Hint: see commands wc, ps, cut, kill.
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:
typsouboru
DIR <directory_path>
FILE <file_path>
INVALID <line_read>
0
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.
INVALID
# ERRORS
#
Example: Script output (stderr in red)
DIR /bin FILE /bin/bash INVALID /bin/bin DIR /tmp INVALID /tmp/xfile FILE /etc/passwd 2 ERRORS
DIR /bin
FILE /bin/bash
INVALID /bin/bin
DIR /tmp
INVALID /tmp/xfile
FILE /etc/passwd
2 ERRORS
Hint: See the read command
read
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.
sed