Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail << ! problem

Status
Not open for further replies.

bitterrob

Technical User
Apr 29, 2002
8
GB
I cannot get this to work inside a korn shell script, if I type the commands in then it does it but if I put it in a script and run it it doesnt work. the code I am trying to use is:
mail <<! <- open the mail program for using prompts
s nextmail <- save mail into nextmail file
q <-quit out
! <- end

unfortunately when I put this into a script it doesnt appear to do anthing inside the mail file.
Thank you in advance for any help.
 
Rob,

The following works on my home system (HPUX 11i) using ksh.

mail <<!
s /tmp/myfile
q
!

Are you getting an error message? Mike
______________________________________________________________________
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
it works when I paste it in just not when I put it into a script, so that I can read the mail do some processing then, read the next one besause the save command removes the email.
 
so my script starts with
mail <<!
s /users/tec/csm/wh00/cam10682/nextmail
q
!
#then do this to the files
tmp=`grep -c unixassessment2002 nextmail`
if tmp > 0 then
emailaddy=`grep Reply-To: nextmail |sed -e &quot;s/Reply-To: //&quot;`
name=`grep NameToAdd nextmail |sed -e &quot;s/NameToAdd: //&quot;`
session=`grep Session nextmail |sed -e &quot;s/Session: //&quot;`
echo $session | cat > session
echo $name | cat > name
echo $emailaddy | cat > emailaddy
count='grep -c session table'
if $count < 4 then
paste $emailaddy $session $name > table
count=`grep -c @ emailaddy`
if $count = 1 then
echo Dear $name, you have been added to our list at time $session. Thank you | cat > mail
sendmail $emailaddy < mail
echo $session $name $emailaddy | cat >> table
fi
fi
fi
#dont know whether the syntax is totally correct but....
 
try just this in a script, see if you can isolate the problem

mail <<!
s /users/tec/csm/wh00/cam10682/nextmail
q
!
cat /users/tec/csm/wh00/cam10682/nextmail Mike
______________________________________________________________________
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
oh -- and no leading spaces on the ! line... Mike
______________________________________________________________________
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
ok ive spent a lot of time re-writing it
mail <<!
s /users/tec/csm/wh00/cam10682/bin/nextmail
q
!
tmp=`grep -c unixassessment2002 nextmail`
if [tmp = 1] then
emailaddy=`grep Reply-To: nextmail |sed -e &quot;s/Reply-To: //&quot;`
name=`grep NameToAdd nextmail |sed -e &quot;s/NameToAdd: //&quot;`
session=`grep Session nextmail |sed -e &quot;s/Session: //&quot;`
echo $session | cat > session
echo $name | cat > name
echo $emailaddy | cat > emailaddy
count='grep -c session table'
if [$count < 4] then
paste $emailaddy $session $name > table
count=`grep -c @ emailaddy`
if [$count = 1] then
echo Dear $name, you have been added to our list at time $session. Thank you | cat > mail
sendmail $emailaddy < mail
echo $session $name $emailaddy | cat >> table
else
fi
#wait and repeat script
else
echo Dear $name, unfortunately $session is fully booked please select another. Thank you |

cat > mail
sendmail $emailaddy < mail
fi
else
#put email back in mail file with cat >> mail file wait and repeat script
cat nextmail >> mbox
fi

I found out what I was doing wrong, I had to type ksh (script name) then it works.

I have another problem now though, its says unexpected else and fi's, when I try to compile it.
 
ok, this syntax checks ok - whether it does what you want is another matter :) but it looks ok
[tt]
#!/usr/bin/ksh

set -n # syntax check only, comment this line out to run the script

mail <<!
s /users/tec/csm/wh00/cam10682/bin/nextmail
q
!

tmp=`grep -c unixassessment2002 nextmail`
if [[ $tmp -eq 1 ]]
then
emailaddy=`grep Reply-To: nextmail |sed -e &quot;s/Reply-To: //&quot;`
name=`grep NameToAdd nextmail |sed -e &quot;s/NameToAdd: //&quot;`
session=`grep Session nextmail |sed -e &quot;s/Session: //&quot;`
echo $session | cat > session
echo $name | cat > name
echo $emailaddy | cat > emailaddy
count=`grep -c session table`
if [[ $count -lt 4 ]]
then
paste $emailaddy $session $name > table
count=`grep -c @ emailaddy`
if [[ $count -eq 1 ]]
then
echo Dear $name, you have been added to our list at time $session. Thank you | cat > mail
sendmail $emailaddy < mail
echo $session $name $emailaddy | cat >> table
else
#wait and repeat script
echo Dear $name, unfortunately $session is fully booked please select another. Thank you | cat > mail
sendmail $emailaddy < mail
fi
else
#put email back in mail file with cat >> mail file wait and repeat script
cat nextmail >> mbox
fi
fi
[/tt]

Mike
______________________________________________________________________
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top