Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have to write a shell-script that have to do the following tasks:
-in every 5 seconds it saves:
    -how many users are using joe and/or vi;
    -if someone was using vi at the last examination, but now he isn't using it anymore, the program should print something about that user and if he is your group that you should send him a mail;

-in every minute it prints:
    -the last minute`s statistics about the usage of joe and vi;
    -the change by the average of usage (increased or decreased);

Any suggestions?

share|improve this question
 
Really interesting question. If it is no secret what purpose of this script: enforce users to use vi? –  IBr Apr 29 '13 at 18:18
 
no, it's just a hometask, but I have no idea how to start solving it. I know that scheduling can be managed by using sleep, but here I have to schedule 2 main tasks. And there's the infinite loop that I have to use. –  Adorjan Apr 29 '13 at 18:29
add comment

1 Answer

up vote 0 down vote accepted
a=`ps -ef | grep "joe" |wc -l`  
b=`ps -ef | grep "vi" | wc -l`  

echo `date +"%Y%M%D %T"` $a $b >> somelogfile  

put them under crontab

also, in /etc/profile put the something like following:

alias vi "vi; mail -s "some message" mailbox"
share|improve this answer
2  
Hopefully there aren't too many other processes around with names containing the sequence "vi" ;) –  goldilocks Apr 29 '13 at 20:18
1  
ps -eo user,comm | grep "[[:space:]]vi$" | uniq | wc -l ([[:space:]] is a POSIX character class, the dollar is regex speak for "end of line") –  ignis Apr 30 '13 at 19:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.