Hello i hope this post is ok! and i hope that i get the point of rules
i made this tasks by my self but few of them arent working.. and i dont know why!?
u think u could help me? to give me some reasons why dont they work.. and remake my code that will work?
hope to get answer soon!
greetz
- Write a shell program which renames the current directory with the given file extension to another extension. The playoffs are given on the command line.
Example usage:
$ Rename *.txt to *.doc
will be renamed:
aaa.txt in aaa.doc
Juhutxt in Juhudoc
...
i have done something like this..
#!/bin/bash
#program preimenuje koncnice datotek: naprimer .dat v .txt
for i in *$1; do
mv "$i" "${i%$1}$2"; ## "$1" je prvi "$2" pa drugi argument
done
exit
- To solve, you can also help with sed or awk commands.
*********************************************************
- Write a shell program to check once every five minutes if the system appears a process and attempt to kill him. Name of the process we give the command line.
Example usage:
$ Kill firefox
computer will be checked every five minutes, if any process running called Firefox, and will try to kill him. Hint: Be sure to use the kill command.
i have done something like this..
#!/bin/bash
while true
do
ps -e | grep $1 ##ps -e "see every process on system using standard syntax:"--
a=$?
if [ $a -eq 0 ];then
kill `pidof $1` ## kill proces with pidof, wich was added like arg1
else
echo "this proces does not exsist"
fi
sleep 300
done
exit 1
fi
*********************************************************
- Write a shell program, which checks the file / etc / passwd and displays the number of processes for each user.
Example output: Processes
45 root
peter 2
Exercise 8
- Look at solving the structure of the file / etc / passwd
i have done something like this..
#!/bin/bash
for k in `cat /etc/passwd|cut -d: -f1`
do
echo "$k" `ps -U $k | wc -l`
done
exit
*********************************************************
- 5.Write a shell program that records the daily availability of computers. As the argument we give him a file containing a list of computers, the program should check every five minutes if they are available. In a file (log) to record, if any of the computers are not reachable, the name and the time was not available.
Example usage:
$ Check list_of_computers.txt
prints in the book:
io.fri.uni-lj.si ni dosegljiv ob 15:31
io.fri.uni-lj.si ni dosegljiv ob 15:36
io.fri.uni-lj.si ni dosegljiv ob 15:41
verbena.fe.uni-lj.si ni dosegljiv ob 15:41
...
i have done something like this..
#!/bin/bash
while true do
for rac in `cat $1` do
ping -c 3 $rac || echo "Ta racunalnik $i ob `date +%T` ni dosegljiv" >>dnevnik_nedosegljivih.txt (kamor se vpi�e njegovo ime in as, ko ni bil dosegljiv)
done
sleep 300 #(5min*60sec=300 sec)
done
exit 0
*********************************************************
- Write a shell program, which scans all files in the specified directory and its poddirektorijih and displays the current file, (the date of last change).
Example output:
The latest $ / usr / etc
/ Usr / etc / httpd / httpd Oct 25 12:16
i have done something like this..
#!/bin/bash
find $1 -not -type d -printf "%p %Aa %Ad %AH:%AM \n" | tail -1
exit
*********************************************************
Faculty of Computer and Information Science
Slovenia, Ljubljana
Prof. Peer
Spletna u?ilnica FRI