at reminder script

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions at reminder script
# 8  
Old 09-30-2011
Wow.

Yes, csh is nothing like a normal shell. I'm surprised your Bourne script worked in any way Smilie

Maybe at on your system can use an alternative shell, see man at

Or you could give at a little csh script that runs your bourne script in a proper shell:

Code:
/bin/sh /path/to/myfile

# 9  
Old 09-30-2011
Quote:
Originally Posted by Corona688
Wow.

Yes, csh is nothing like a normal shell. I'm surprised your Bourne script worked in any way Smilie

Maybe at on your system can use an alternative shell, see man at

Or you could give at a little csh script that runs your bourne script in a proper shell:

Code:
/bin/sh /path/to/myfile

Yes on the alternative shell. I added a -k switch to:
Code:
at -k $TIME << !!

and now the ioctl error is gone.

Sorry about that Corona and I appreciate all your help! Kudos!
# 10  
Old 10-04-2011
Ok, so I got the last problem straightened out and now I have another. It seems I am so close yet so far away. Here is my code;
Code:
#!/usr/dt/bin/dtksh
# Alertme.p1 program, version 0.5
# Author - Clint Sharp
mkdir ~/Msgs
echo "\nEnter your reminder message.
When finished, enter a period (.) at
the beginning of a line and press <ENTER>.
(Or press Ctrl-C to exit the script)\n"
while :
do
        read MESSAGE
        if [ "$MESSAGE" = "." ]
        then
                break
        else
                echo $MESSAGE >> ~/Msgs/message.$$
        fi
done
echo "\nEnter the time and day you want to
receive the message, for example:
0815am Jun 14
8:15am Jun 14
now + 1 day
5 pm Friday
Then press <ENTER>\n"
read TIME 
echo "\nAt $TIME mail or write $LOGNAME ~/Msgs/message.$$\n"
at -k $TIME << !!
who | cut -c1-20 | grep $LOGNAME | cut -c12-20 | cat > ~/tmp
while read inputline
do
        write $LOGNAME $inputline < ~/Msgs/message.$$ #|| mail $inputline < ~/Msgs/message.$$
done < ~/tmp
rm -r ~/Msgs
rm -r ~/tmp
exit 0

What is happening is I will have two terminal sessions opened to test this script and it is sending two messages to the same terminal. The one that originally initiated the script. I also get a mail message that says,
Code:
Your "at" job on admiral
"/var/spool/cron/atjobs/1317758851.a"
produced the following output:
I cannot determine your terminal name. No reply possible.
cs368 is logged on more than one place.
You are connected to "pts/26".
Other locations are:
pts/98Warning: You have your terminal set to "mesg -n". No reply possible.
I cannot determine your terminal name. No reply possible.
cs368 is logged on more than one place.
You are connected to "pts/26".
Other locations are:
pts/98Warning: You have your terminal set to "mesg -n". No reply possible.

On the terminal pts/98 I did change message to "yes" using the -y switch. I do not think this is the problem though. Can anyone help?
# 11  
Old 10-04-2011
"$" variables are likely being substituted before the script is run, so $inputline never changes. You have to escape it with \.

This !! business is strange as well. On my system, that tells it to end the here document on 'man write', since that's the command I ran last.

Code:
at -k $TIME <<EOF
who | cut -c1-20 | grep $LOGNAME | cut -c12-20 | cat > ~/tmp
while read inputline
do
        write $LOGNAME \$inputline < ~/Msgs/message.$$ #|| mail \$inputline < ~/Msgs/message.$$
done < ~/tmp
rm -r ~/Msgs
rm -r ~/tmp
exit 0
EOF

That's a useless use of cat, by the way. Any command can be redirected to file, not just cat -- so leave off the cat and send your last cut into a file, cut -c12-20 > ~/tmp

That's also a useless use of a temp file. You can just feed cut's output directly into the while loop with no intervening file: a | b | c | while read LINE ; do stuff ; done

You never did redirect write's stderr to >dev/null like write ... 2>/dev/null to throw away the messages.

Show me what your who output looks like, and I'll find a more elegant way to get what you want than cut | grep | cut | cat, too.
# 12  
Old 10-13-2011
Ok everyone, I am back. My problem this time is the elm -s in the 2nd if loop is not working. I cannot get it to mail the message to me when I am offline. Here is my code:
Code:
# Alertme.p1 program, version 0.7
# Author - Clint Sharp
# This program is interactive and will alert the user
# if they are online at more than one terminal. It will also mail the
# user at the mail address associated with the user id.
mkdir ~/Msgs
echo "\nEnter your reminder message.
When finished, enter a period (.) at
the beginning of a line and press <ENTER>.
(Or press Ctrl-C to exit the script)\n"
while :
do
        read MESSAGE
        if [ "$MESSAGE" = "." ]
        then
                break
        else
                echo $MESSAGE >> ~/Msgs/message.$$
        fi
done
echo "\nEnter the time and day you want to
receive the message, for example:
0815am Jun 14
8:15am Jun 14
now + 1 day
5 pm Friday
8:15am 6/14/2011
Then press <ENTER>\n"
read TIME 
echo "\nAt $TIME mail or write $LOGNAME ~/Msgs/message.$$\n"
at -k $TIME << EOF
if [ `who | grep -c "$LOGNAME"` -gt 0 ]; then
who | cut -c1-20 | grep $LOGNAME | cut -c12-20 > ~/tmp
while read inputline
do
        write $LOGNAME \$inputline < ~/Msgs/message.$$ > /dev/null 2>&1
done < ~/tmp
exit
fi
if [ `who | grep -c "$LOGNAME"` -eq 0 ]; then
elm -s $LOGNAME < ~/Msgs/message.$$
exit
fi
rm -r ~/Msgs
rm -r ~/tmp
exit 0
EOF

Can anyone see what might be the problem? I appreciate all the help here. I will clean up this script with sed and awk on the next assignment. We are in the process of learning both now.
# 13  
Old 10-17-2011
Got it! Here is the correct code. Still needs some efficiency put into it but it will work for the time being.
Code:
#!/usr/dt/bin/dtksh
# Alertme.p1 program, version 0.7
# Author - Clint Sharp
# This program is interactive and will alert the user
# if they are online at more than one terminal. It will also mail the
# user at the mail address associated with the user id.
mkdir ~/Msgs
echo "\nEnter your reminder message.
When finished, enter a period (.) at
the beginning of a line and press <ENTER>.
(Or press Ctrl-C to exit the script)\n"
while :
do
    read MESSAGE
    if [ "$MESSAGE" = "." ]
    then
        break
    else
        echo $MESSAGE >> ~/Msgs/message.$$
    fi
done
echo "\nEnter the time and day you want to
receive the message, for example:
0815am Jun 14
8:15am Jun 14
now + 1 day
5 pm Friday
8:15am 6/14/2011
Then press <ENTER>\n"
read TIME
echo "\nAt $TIME mail or write $LOGNAME ~/Msgs/message.$$\n"
at -k $TIME << EOF
if ! who | grep ^$LOGNAME > /dev/null; then
mail $LOGNAME < ~/Msgs/message.$$
fi
if [ `who | grep -c "$LOGNAME"` -gt 0 ]; then
who | cut -c1-20 | grep $LOGNAME | cut -c12-20 | while read LINE
#while read inputline
do
    write $LOGNAME \$LINE < ~/Msgs/message.$$ > /dev/null 2>&1
done
fi
rm -r ~/Msgs

exit 0
EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. OS X (Apple)

A simple reminder script for beginners to shell scripting.

(Apologies for any typos.) Well hands up those who have been in the following situation(s):- Your partner, (in my case the missus), sees that you are messing with your machine and says something like, "can you keep an eye on the dinner, I am going out shopping", and you look up glazed eyed... (3 Replies)
Discussion started by: wisecracker
3 Replies

2. Homework & Coursework Questions

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... (11 Replies)
Discussion started by: csharp100
11 Replies
Login or Register to Ask a Question