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
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
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
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
---------- 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 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:
How did you exactly call it?
Are you sure you have also supplied the second arg
I also run this script with only one argument and it deleted the extensions.
How did you exactly call it?
Are you sure you have also supplied the second arg
I also run this script with only one argument and it deleted the extensions.
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)
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)
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)
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)
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)