Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
The problem statement, all variables and given/known data:
Hi everyone, The script I did below works just fine. My problem is when the script is executed, I receive 2 emails. One is from the script and the other is from our Sun OS system named admiral. The Sun os is ver. 5.10. The mail message I receive is:
"Your "at" job on admiral
"/var/spool/cron/atjobs/1317352641.a"
produced the following output:
stty: : Inappropriate ioctl for device
stty: : Inappropriate ioctl for device
I cannot determine your terminal name. No reply possible.
Warning: You have your terminal set to "mesg -n". No reply possible."
I am trying to figure out what "stty: :In appropriate ioctl for device" means. Can anyone help? Thanks!
Relevant commands, code, scripts, algorithms:
at command
The attempts at a solution (include all code and scripts):
# Alertme.p1 program, version 0.3
# Author - Clint Sharp
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 $TIME << !!
write $LOGNAME < ~/Msgs/message.$$ || mail $LOGNAME < ~/Msgs/message.$$
rm -f ~/Msgs/message.$$
exit 0
Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
UMSL, St Louis, MO, USA, Antonogli, 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).
That did not solve my problem. I may not have explained it correctly so I will try again. The script is to send a reminder to me using the at command. If I am online, then it will write to me. If I am offline, then it will email me. If I am online, the script will "interrupt me" with the reminder but it also sends a mail message with the aforementioned, "stty: :Inappropriate ioctl for device". If I am offline, the script mails me two messages. The original reminder and the "stty: :Inappropriate ioctl for device" message.
When I tried the above code suggested by Corona688, I got no message and received a mail message, "Ambiguous output redirect." Therefor I am stuck.
---------- Post updated at 02:02 PM ---------- Previous update was at 02:00 PM ----------
I think I understood in the first place.
write is trying to terminal commands on a non-terminal device(being run from 'at', it has no terminal!) which isn't the end of the world, but also blabs error messages when it does, which isn't what you want.
The redirection I showed you ought to work, but may have gone into the wrong place, can you show me exactly what you tried?
on both tries.
When I tried both, I got the same message mailed to me and did not get my write message at all. It also included an "Ambiguous redirection" in the mail messages as well.
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;
#!/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,
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?
"$" 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.
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.
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:
# 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.
Got it! Here is the correct code. Still needs some efficiency put into it but it will work for the time being.
#!/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