My professor wants us to write a script that will do the following:
-Catch him online and output the time/day
-Where did he login, ie College or Home (ip address provided is ok too)
-What was he doing

The crontab should run every 30 mins and automatically email him all the results at sunday 11:59 PM.

I'm really confused about this as i'm new to scripting, thanks.

Recommended Answers

All 5 Replies

How does he propose that you catch him? Are you allowed to install applications on his machine, or will he be hitting a webserver and you need to grep the logs for a page he will visit?

I think what he means by catching him is that the crontab should run every 30 minutes; he'll be logging on at every 29th minute for a duration of 5-6 minutes.

Sounds fun. Try something like this:

#!/bin/bash
prof_acct_name="sk"

x=`w`
echo "${x}" | while read line;
do
  if echo ${line} | egrep "^${prof_acct_name}\b.*" >> /dev/null 2>&1; then
    ip_addr=`echo ${line} | awk '{ print \$3 }'`
    process=`echo ${line} | awk '{ print \$9 }'`
    echo -e "\nI got you Dr. Evil!"
    echo "Login Line: ${line}"
    echo "Your process: ${process}"
    echo -e "IP Addr: ${ip_addr}\n"
    #echo ${line} | /bin/mail -s your_subject prof@univ.edu
  fi
done

Calling it:

sk@sk:/tmp$ ./ba.sh

I got you Dr. Evil!
Login Line: sk       pts/0    work             03Dec09  0.00s  0.44s  0.01s /bin/bash ./ba.
Your process: ./ba.
IP Addr: work

In my case it says "work" instead of the IP address because I have an entry in /etc/hosts . It should work fine.

You may also consider creating a temporary file after the email mechanism is tripped. This will be useful in that if the script runs amok it won't send your professor an email every 5 minutes, pissing him off.

Sounds fun. Try something like this:

#!/bin/bash
prof_acct_name="sk"

x=`w`
echo "${x}" | while read line;
do
  if echo ${line} | egrep "^${prof_acct_name}\b.*" >> /dev/null 2>&1; then
    ip_addr=`echo ${line} | awk '{ print \$3 }'`
    process=`echo ${line} | awk '{ print \$9 }'`
    echo -e "\nI got you Dr. Evil!"
    echo "Login Line: ${line}"
    echo "Your process: ${process}"
    echo -e "IP Addr: ${ip_addr}\n"
    #echo ${line} | /bin/mail -s your_subject prof@univ.edu
  fi
done

Calling it:

sk@sk:/tmp$ ./ba.sh

I got you Dr. Evil!
Login Line: sk       pts/0    work             03Dec09  0.00s  0.44s  0.01s /bin/bash ./ba.
Your process: ./ba.
IP Addr: work

In my case it says "work" instead of the IP address because I have an entry in /etc/hosts . It should work fine.

You may also consider creating a temporary file after the email mechanism is tripped. This will be useful in that if the script runs amok it won't send your professor an email every 5 minutes, pissing him off.

This is very good. Now I have to setup the job for crontab to run this script every 30 minutes and email him the results on Sunday 11:59PM.

Sounds good.

Please mark this thread as solved if you have found an answer to your question and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.