Reminder script not working...

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    We have been tasked to write an at reminder script that will write or echo a message to more than one user. What happens is the script does not write or echo the message to the entered users and sends a message to my inbox stating, "Your at job on admiral produced the following output: pts/62" pts/62 is the tty I am logged into. I never get the message. My message I enter into the script is "hello." While testing the script I have stayed online. Can anyone help me please?

  2. Relevant commands, code, scripts, algorithms:
    Not sure I understand this part.

  3. The attempts at a solution (include all code and scripts):

Enter time: 
now + 1 min
Enter message: 
hello
Enter user(s): 
cs368
commands will be executed using /bin/ksh
job 1320104109.a at Mon Oct 31 18:35:09 2011
137 /accounts/students/c/cs368/alert.p2> more t1
#!/usr/dt/bin/dtksh
# Alert.p2 program, version 0.2
# Author - Clint Sharp
echo "\nEnter time: "
read TIME
echo "\nEnter message: "
read MESSAGE
echo "\nEnter user(s): "
read LOGNAMES
at -k $TIME << EOF
while read LOGNAME      
        do 
        who | grep $LOGNAME | sed 's,.*\(pts/[0-9]*\).*, \1 ,'
                while read tty
                        do
                        echo $MESSAGE | /dev/\$tty
                        done
        done
EOF
  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    UMSL, St Louis, MO, USA; Antognolij; CS2750

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

As this is an assignment I'm only going to suggest that you look at a couple of things.

First, check the syntax of your echo statement. Think redirection.

Secondly, when at runs your script, what is the standard input? That might be a bit cryptic, so think about where the input to the while might be coming from. Remember, the script given to at doesn't have any variables that are in the script that you use to submit the job.

I corrected this with a ">" and appreciate that.

I'm not really quite sure what you are telling me here. Are you saying that the message is not getting into the at command?

No, the contents of MESSAGE should be expanded as the here doc is read by at. Rereading, I see that my statement is confusing -- trying not to give away the store :slight_smile:

No, in this case I'm trying to get you to see that the script executed by at has nothing to read. Unless I'm missing something, the user list that is input will never make it into your script. Think about how you might expand the contents of LOGNAMES as the script is written to at.

The only thing I can think of is to write the message to the disk and then have the message read off the disk when the job is executed. I have done that before but my professor was not to keen on writing to the disk even though I made a directory for the user of the at job and then removed the directory and its contents. I am not sure how else to do it.

My bad, I mis-read your message. But then again, the only thing I can think of is the same thing I wrote above about the message. Writing the names of the users to the disk and have them read into the at job at execution.

Right, there's nothing to prevent the file from being deleted, so if you can avoid it you should. Most cases aren't as simple and writing out a state file is acceptable, but I see where your prof is coming from and agree.

Ok, so you know that the contents of MESSAGE will be expanded into the script as it is written to stdin when at is executed. You also know that your list of users is known when you invoke at, and that you could cause that list to be expanded into your script. So, is there another looping construct that you might be able to use in place of the while that would allow you to loop through the list of names?

Sure, the for loop but I could not get it to work either. i.e.

echo "\nEnter time: "
read TIME
echo "\nEnter message: "
read MESSAGE
echo "\nEnter user(s): "
read LOGNAMES
at -k $TIME << EOF
for NAME in $LOGNAMES
     do
     echo $MESSAGE | write $NAME$
     DONE
EOF

This code was sending me an email telling me how to use the write command. I am at my wits end here and about to give up. Of course I won't but it is getting old and getting frustrating. :wall:

Good -- you were there!!

NAME needs to be a variable in the script and not expanded when the script is written to at. So, if you escape it /$NAME that will put it literally in the script ($NAME) and not what name contains (which is nothing). Drop the last dollar sign.

The only other problem I see is that DONE should be lower case. That might just be a cut/paste issue; hard to say from this end.

With those changes it should send you mail with the list of names (I'd use echo to avoid errors if the list is empty).

Have a go with those changes -- you're a lot closer than you think!

1 Like

Thanks and I got it, but I believe the $NAME should be \$NAME. That is the way it worked for me. I appreciate your help!

Clue:
How are you going to get the $tty ?
Portion corrected

who | grep $LOGNAME | sed 's,.*\(pts/[0-9]*\).*, \1 ,' |
while read tty
do
  echo $MESSAGE | /dev/$tty
done

#
execution:
#
an12:/home/vbe $ who | grep $LOGNAME | sed 's,.*\(pts/[0-9]*\).*, \1 ,'|
> while read tty
> do
>   echo $MESSAGE | /dev/$tty
> done
/usr/bin/ksh[4]: /dev/pts/14: 0403-006 Execute permission denied.
/usr/bin/ksh[4]: /dev/pts/24: 0403-006 Execute permission denied.
/usr/bin/ksh[4]: /dev/pts/27: 0403-006 Execute permission denied.

You carry on now...

I believe I know where you are going. I used the above for loop instead but I think you are pointing out the fact that some users might have there tty's turned off for receiving messages. Is that correct? My time was limited on getting the assignment done. I had thought of that though.

Ack!! I've been typing too many HTML tags by hand!

Glad it worked.