Sponsored Content
Homework and Emergencies Homework & Coursework Questions i made this tasks. and i need some explenation or just remake my code. Post 302426088 by pseudocoder on Monday 31st of May 2010 09:21:24 PM
Old 05-31-2010
Check this: https://www.unix.com/unix-dummies-que...-strength.html Smilie

---------- Post updated at 23:17 ---------- Previous update was at 23:09 ----------

Quote:
Originally Posted by eclip
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
# in the next line Kill stands for this script name
ps -e | grep $1 | grep -v grep | grep -v Kill ##ps -e "see every process on system using standard syntax:"--
# this is not needed, see next line why	a=$?
if [ $? -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

# this is not needed, since the stuff above is an infinite loop exit 1

# this is not needed, bcs. there is only one if statement fi



---------- Post updated 06-01-10 at 03:21 ---------- Previous update was 05-31-10 at 23:17 ----------

5.
Code:
#!/bin/sh

find $1 -type f -exec stat -f "%m%Sm %N" '{}' 2>/dev/null + | \
sort -nr | head -1 | \
sed 's/[0-9]*//;s/:[0-9 ]*\// \//;s/\([^/]*\)\(.*\)/\2 \1/'

Test run:
Code:
$ ./Findlatest.sh ~/code
/home/coder/code/sh/Findlatest.sh Jun  1 03:43 
$ ./Findlatest.sh /usr/local/etc
/usr/local/etc/gimp/2.2/unitrc May 13 20:21 
$

I'm not sure if this will work for you, since I tried it with a non-gnu version of stat.

Last edited by pseudocoder; 05-31-2010 at 10:54 PM..
 

6 More Discussions You Might Find Interesting

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

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

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

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

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

6. 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
All times are GMT -4. The time now is 11:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy