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?

  • Really interesting question. If it is no secret what purpose of this script: enforce users to use vi?
    – IBr
    Apr 29, 2013 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, 2013 at 18:29

1 Answer 1

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"
  • 2
    Hopefully there aren't too many other processes around with names containing the sequence "vi" ;)
    – goldilocks
    Apr 29, 2013 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, 2013 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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