Sponsored Content
Full Discussion: at reminder script
Homework and Emergencies Homework & Coursework Questions at reminder script Post 302561633 by Corona688 on Tuesday 4th of October 2011 04:23:26 PM
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.
 

2 More Discussions You Might Find Interesting

1. 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

2. 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
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 01:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy