Problem with << redirect - Please help!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with << redirect - Please help!
# 8  
Old 01-03-2012
Please post the current version of the script.

Though I don't think that the "." idea above will fix your problem it is still good practice to terminate a sendmail body with a "." .
Your problem is about terminating the Shell "here" document. My first feeling was that we need a space character after <<HERE .

On the off chance. If at any time this script has been edited with a Microsoft editor, please post the output from this command which is designed to make control characters visible:
Code:
sed -n l scriptname



Off topic:
Quote:
if [ $? -eq 1 ]
then
echo 'ERROR while sending email.'
exit 1
fi
Would be much better as:
Code:
if [ $? -ne 0 ]
then
    echo 'ERROR while sending email.'
    exit 1
fi


Last edited by methyl; 01-03-2012 at 04:10 PM.. Reason: ambuguity and addenda
This User Gave Thanks to methyl For This Post:
# 9  
Old 01-03-2012
I am both humbled and thankful for the time you guys have spent for me.

Adding the dot did not help.

Posting the output from the sed command below:

Code:
echo "Input Parameters"\r$
echo "----------------"\r$
P_FROM_ID=$5\r$
P_TO_ID=$6\r$
P_CC_ID=$7\r$
P_SUBJECT=$8\r$
P_BODY1=$9\r$
P_BODY2=${10}\r$
P_BODY=$P_BODY1$P_BODY2\r$
echo 'From ID               :'  $P_FROM_ID\r$
echo 'To ID                 :'  $P_TO_ID\r$
echo 'CC ID                 :'  $P_CC_ID\r$
echo 'Subject\t\t    :'  $P_SUBJECT\r$
echo 'Body1\t\t    :'$P_BODY1\r$
echo 'Body2\t\t    :'$P_BODY2\t\r$
echo 'Body\t\t    :'$P_BODY\r$
echo "Process Output"\r$
echo "--------------"\r$
\r$
cat <<endKat | sendmail -oi -t -f $P_FROM_ID\r$
To: ${P_TO_ID}\r$
From: ${P_FROM_ID}\r$
Subject: ${P_SUBJECT}\r$
\r$
$P_BODY\r$
endKat\r$
if [ $? -eq 1 ]\r$
then\r$
    echo 'ERROR while sending email.'\r$
    exit 1\r$
fi\r$
\r$

# 10  
Old 01-03-2012
Good guess on my part.
Your script is totally corrupted with Microsoft Text format. It will not work in unix and could be driving you nuts. In Microsoft Text format the line terminator is two characters: carriage-return then line-feed \r$ . In unix text format the line terminator is just line-feed $.

To fix the script, we need to remove the carriage-return characters. They are showing as "\r" in the "sed -n l" listing of your script.

Code:
cat oldscript | tr -d "\r" > newscript  # Remove carriage-returns
chmod 755 newscript    # make it executable

When copying a script from a Microsoft platform to a unix platform always use ASCII (not BINARY) mode FTP or convert the file using dos2ux (or dos2unix) or use a Translate "tr" command (above).


Purely for the sake of completeness: endKat does not match endKat\r (i.e. endKat with a trailing carriage-return character). This is why the ensuing Shell commands became part of your email body.
QED.

Last edited by methyl; 01-03-2012 at 09:51 PM.. Reason: perfectionism
This User Gave Thanks to methyl For This Post:
# 11  
Old 01-04-2012
Hi Methyl,
You were right on the dot! When i save the file in Unix mode (from text pad) and FTP'ed in Text mode (i was doing in default mode till now) the following code worked. Thanks everyone for helping. This is a great forum!


Code:
echo "Input Parameters"
echo "----------------"
P_FROM_ID=$5
P_TO_ID=$6
P_CC_ID=$7
P_SUBJECT=$8
P_BODY1=$9
P_BODY2=${10}
P_BODY=$P_BODY1$P_BODY2
echo 'From ID               :'  $P_FROM_ID
echo 'To ID                 :'  $P_TO_ID
echo 'CC ID                 :'  $P_CC_ID
echo 'Subject		    :'  $P_SUBJECT
echo 'Body1		    :'$P_BODY1
echo 'Body2		    :'$P_BODY2	
echo 'Body		    :'$P_BODY
echo "Process Output"
echo "--------------"

cat <<endKat | sendmail -oi -t -f $P_FROM_ID
To: ${P_TO_ID}
From: ${P_FROM_ID}
Subject: ${P_SUBJECT}
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0

$P_BODY

endKat

if [ $? -eq 1 ]
then
    echo 'ERROR while sending email.'
    exit 1
fi

# 12  
Old 01-04-2012
You're welcome.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Htaccess Redirect Problem

Hi, I have this string that I need to match and redirect to an actual live url. I have tried what I know and it won't match. This is the url I want to match. http://www.abc.com/smf_test/?topic=191.0;wap2 here is my attempt at a pattern match RewriteCond %{REQUEST_URI} ^/smf_test/$... (0 Replies)
Discussion started by: sharingsunshine
0 Replies

2. Shell Programming and Scripting

Redirect Problem

Hi, I have perl script which is calling an external command using "system()" with argument. But i am not able to capture the output.Even tried with backtick also with no luck. . . $number=<>; system ("cmd $number >output.txt"); (2 Replies)
Discussion started by: rasingraj
2 Replies

3. Shell Programming and Scripting

redirect stdout and stderr to file wrong order problem with subshell

Hello I read a lot of post related to this topic, but nothing helped me. :mad: I'm running a ksh script with subshell what processing some ldap command. I need to check output for possible errors. #!/bin/ksh ... readinput < $QCHAT_INPUT |& while read -p line do echo $line ... (3 Replies)
Discussion started by: Osim
3 Replies

4. Solaris

Cron redirect problem

Hello all, I have a script that I am trying to execute and redirect the output to a file, but I have trouble in redirection. The cron job is running properly as I see it in the mail. This is what I am doing In crontab file, 0 4 * * * somescript.sh > /some_location/`date '+%m%d%y_%H%M'`.log... (9 Replies)
Discussion started by: grajp002
9 Replies

5. UNIX for Dummies Questions & Answers

Redirect from the Root?

Hello again, What im trying to do is to redirect output from a cmd, from the root, to a file. But i guess thats illegal. I just wanted to know the file size of all files in my system. So: cd / du -k but i need to ouput this information to a 'sysfile.txt' file, or what... (2 Replies)
Discussion started by: oxoxo
2 Replies

6. Shell Programming and Scripting

KSH problem - how do i redirect three times?

i need to output an ls command to a file but also capture any errors from that command and output them to a log file and the screen. if it's only possible to output them to a log file and not the screen then that's fine. this is what i've tried so far, but it won't populate log.txt. i've... (16 Replies)
Discussion started by: mjays
16 Replies

7. Shell Programming and Scripting

Redirect Problem

I am using the time command in a script however the output of the time command will display on my screen but not my output file. Any Ideas on how to fix this? > cat test.sh ############################# #!/usr/bin/sh for COMMAND in pwd do time ${COMMAND} done | sed "s/^/ ... (4 Replies)
Discussion started by: 2dumb
4 Replies

8. UNIX for Advanced & Expert Users

problem with redirect stdout to file

Hi all hope you can help as I am going MAD!!! :eek: The below is in a shell script but the redirection in the sed line does not work and outputs to the screen and the $fname_2 does note get created ????? Can any one help ?? #!/bin/ksh cd /app/ for fname in `ls -1 X*` do sed 1d $fname... (3 Replies)
Discussion started by: mlucas
3 Replies

9. Shell Programming and Scripting

Redirect question

Hi, I need some help to achive the follwoing task: I have a file named test that contain the following line: 'Hellow world','good morning' I want to attach the content of this file to a variable named var , and then rediarect it to a second file bamed test_new. The result should look like... (2 Replies)
Discussion started by: yoavbe
2 Replies

10. IP Networking

Redirect

I'm sittig behind a firewall that doesn't allow ftp. I have a conection to a UNIX system, connecting throug SSH. Is it possible to redirect the ftp through the UNIX to my computer? (1 Reply)
Discussion started by: <Therapy>
1 Replies
Login or Register to Ask a Question