Answer to Homework 2 of 6 October 1997 Call a program from your .profile file. Below are several solutions. * * * * * * * * * First a simple one. Write the following shell script: #!/bin/ksh typeset account="`logname`@`uname -n`" typeset destined=wimr echo "Login at time " `date` " into account " $account | \ elm -s $account $destined Put this shell script in a file, say called fff. Make sure that it is executable. Call the file from .profile. Redefine the destined parameter to send email to another account. * * * * * * * * * Second example. I essentially copied this one from Brian Cain. Write the shell script hour=`date +%H` if test $hour -gt 12 then DAY_NIGHT='am' else DAY_NIGHT='pm' fi CURR_TIME=`date +%-I:%M$DAY_NIGHT` CURR_DATE=`date +%D` if test $hour -gt 22 then mail cainjr << __EOF__ Someone logged in at $CURR_TIME, on $CURR_DATE. __EOF__ else if test $hour -lt 8 then mail cainjr << __EOF__ Someone logged in at $CURR_TIME on $CURR_DATE. __EOF__ fi fi Put this shell script in a file, say called fff. Make sure that it is executable. Call the file from .profile. Rename from cainjr to send email to another account. * * * * * * * * * Third example. I essentially copied this one from Royce Dsouza. Write the shell script #!/bin/ksh typeset hour=`date +%H` typeset time=`date +%T` typeset date=`date +%D` typeset user=`whoami` if (( hour<=7 )) then echo "$user logged in on $date at $time." | mail rdsouza elif ((hour>=23 )) then echo "$user logged in on $date at $time." | mail rdsouza fi Put this shell script in a file, say called fff. Make sure that it is executable. Call the file from .profile. Rename from rdsouza to send email to another account. * * * * * * * * * Fourth example. I essentially copied this one from Tanya Ershova. Write the shell script hour=`date | cut -c12-13` if [ $hour -le 7 -o $hour -ge 23 ] then echo You logged in on ` date` | mail ershova fi Put this shell script in a file, say called fff. Make sure that it is executable. Call the file from .profile. Rename from ershova to send email to another account. * * * * * * * * * Fifth example. I essentially copied this one from Reginald Tauro. Write the shell script date > datefile awk '{if ($4 >= 23 || $4 <= 7 ) mail rtauro < intruder}' datefile Put this shell script in a file, say called fff. Make sure that it is executable. Call the file from .profile. Rename from rtauro to send email to another account. * * * * * * * * * Wim Ruitenburg