i made this tasks. and i need some explenation or just remake my code.

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions i made this tasks. and i need some explenation or just remake my code.
# 1  
Old 05-31-2010
i made this tasks. and i need some explenation or just remake my code.

Hello i hope this post is ok! and i hope that i get the point of rules Smilie
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


1. 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
...
Code:
 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.

*********************************************************

2. 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.

Code:
 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

*********************************************************

3. 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

Code:
 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

*********************************************************

4. 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
...
Code:
 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

*********************************************************

5. 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
Code:
 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
# 2  
Old 05-31-2010
This User Gave Thanks to pseudocoder For This Post:
# 3  
Old 05-31-2010
tywm for that..
but i was wondering if u can make something like that?

Code:
 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

# 4  
Old 05-31-2010
3. https://www.unix.com/homework-coursew...processes.html

---------- Post updated at 19:26 ---------- Previous update was at 19:20 ----------

Quote:
Originally Posted by eclip
tywm for that..
but i was wondering if u can make something like that?
Yep, but don't forget to comment the comment, see red mark:

Quote:
Originally Posted by eclip
Code:
 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

and don't forget the semicolon in the for line, also see red mark.

---------- Post updated at 20:08 ---------- Previous update was at 19:26 ----------

1. Can you accept usage like rename .txt .doc Smilie If yes, check this:

Code:
#!/bin/sh

for i in *$1; do
mv "$i" "${i%.*}$2"
done

Test run:
Code:
$ ls
gport.py	label.py	monk.py		rename.sh	test.py
$ ./rename.sh .py .pl
$ ls
gport.pl	label.pl	monk.pl		rename.sh	test.pl
$


Last edited by pseudocoder; 05-31-2010 at 02:36 PM..
This User Gave Thanks to pseudocoder For This Post:
# 5  
Old 05-31-2010
Code:
#!/bin/sh

for i in *$1; do
mv "$i" "${i%.*}$2"
done

Test run:

this one makes this

mv: `new file' and `new file' are the same file
mv: `vaja1' and `vaja1' are the same file

so this just deletes extensions..?
# 6  
Old 05-31-2010
How did you exactly call it?
Are you sure you have also supplied the second arg Smilie
I also run this script with only one argument and it deleted the extensions.
# 7  
Old 05-31-2010
Quote:
Originally Posted by pseudocoder
How did you exactly call it?
Are you sure you have also supplied the second arg Smilie
I also run this script with only one argument and it deleted the extensions.
i name it preimenuj.sh..

and i dont know about 2nd arg :S
u have any idea?
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

[Tip] Housekeeping Tasks Made Easy - User Home directories and Leftover Files

We have regularly questions about how to create users and user accounts. But regularly user accounts need to be deleted too. It is quite easy to delete the user account itself but usually the HOME directory of the user remains. It is good style to remove these directories but simply deleting... (3 Replies)
Discussion started by: bakunin
3 Replies

2. Homework & Coursework Questions

Hello.. can someone help my with this tasks?

1. 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 doc will be renamed: aaa.txt in aaa.doc Juhutxt in Juhudoc ... * To solve, you can also help with... (5 Replies)
Discussion started by: eclip
5 Replies

3. Shell Programming and Scripting

schedule tasks

As far as I know Crontab is the utulity to schedule tasks to run at specific times.Is there any utility to perform the same task (4 Replies)
Discussion started by: tjay83
4 Replies

4. AIX

Junior SA Tasks?

I've been given more responsibility at work and was basically told to take junior system admin responsibilities over our aix box. The catch is, I need to learn on my own. I know basics, but what are some task that I could perform on a daily basis for starters? We have a support group, but not so... (2 Replies)
Discussion started by: NycUnxer
2 Replies

5. UNIX for Dummies Questions & Answers

Need help with tasks!

Hi guys! I have a dummy question for u :p I cant find a solution for these tascks...tried everything (i know :cool: ). 1 Issue the following command sleep 1000 Note that sleep 1000 waits 1000 seconds!!! You cannot do anything now!!! 2 Open another terminal window and enter the tty... (1 Reply)
Discussion started by: RomeO
1 Replies

6. UNIX for Dummies Questions & Answers

Repetitive Tasks

Could someone tell me how I can simplify the script that follows!!! I know that there must be a way how to grep Average from sar01.................. sar02 ....................... sar03....................... sar04... (3 Replies)
Discussion started by: JairGuerra
3 Replies
Login or Register to Ask a Question