ksh and mail problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh and mail problem
# 1  
Old 05-31-2012
ksh and mail problem

Script A:
Code:
#!/bin/ksh
/usr/bin/mail -s "case 4" g@f.com <testF5Email.inp

Script B:
Code:
#!/bin/ksh
qq="-s \"case 4\" cstsang@hko.hksarg" 
/usr/bin/mail $qq<testEmail.inp

Script A working properly where Script B cannot.

The error message as the following:

Code:
There is a missing '"' character
4"... User unknown

Would you tell me what's going on?
And how to fix it?


thank you very much
Moderator's Comments:
Mod Comment Please view this link to learn the use of code tags.

Last edited by Scrutinizer; 05-31-2012 at 07:17 AM.. Reason: code tags
# 2  
Old 05-31-2012
can you try with double quotes

Code:
/usr/bin/mail "$qq" < testEmail.inp
 
or
 
use single quote
 
qq='-s "case 4" cstsang@hko.hksarg'

# 3  
Old 05-31-2012
I suspect that ScriptB contains some funny characters, possibly from a non-unix editor:
Please post the output from these commands which are designed to make non-printable characters visible:
Code:
sed -n l ScriptA
sed -n l ScriptB

# 4  
Old 06-01-2012
This is output of sed -n l ScriptB
Code:
#!/bin/ksh $
. /home/util/f5ScriptLib$
#LOG_FILE=$LOG_PATH/f5mail.`date '+%y%m%d'`$
LOG_FILE=$HOME/f5mail.`date '+%y%m%d'`$
DEBUG=true$
initLogFile $LOG_FILE$
echo "#####################################################">>$LOG_FILE$
echo "#Process ID=$$               #">>$LOG_FILE  \t$
echo "#f5mail started at `date`#">>$LOG_FILE$
echo "#####################################################">>$LOG_FILE$
while read data1; do   #read data from input stream$
\techo $data1 >>/tmp/$$ $
done$
mailCmd=$1$
i1=1$
for p1 in "$@" ; do$
\t\tif [[ $i1 -gt 1 ]] then$
\t\t\t$
\t\t\techo $p1|grep " ">/dev/null$
\t\t\tif [[ $? -eq 0 ]] then$
\t\t\t\tparameters1=`echo "$parameters1\\"$p1\\" "`$
\t\t\telse$
\t\t\t\tparameters1=`echo "$parameters1$p1 "`$
\t\t\tfi\t$
\t\tfi$
\t\ti1=$((i1+1))$
done$
echo "/usr/bin/mail $parameters1 </tmp/$$"$
/usr/bin/mail $parameters1 </tmp/$$ $
rm /tmp/$$$
find $LOG_PATH -name "f5mail*" -mtime +7 -exec rm {} \; #log file house\
keeping$
echo "#####################################################">>$LOG_FILE$
echo "#Process ID=$$               #">>$LOG_FILE  \t$
echo "#f5mail ended at `date`#">>$LOG_FILE$
echo "#####################################################">>$LOG_FILE$

---------- Post updated at 09:26 AM ---------- Previous update was at 09:18 AM ----------

In fact, I need to write a mail program wrapper.

---------- Post updated at 09:40 AM ---------- Previous update was at 09:26 AM ----------

When I execute the following command:
Code:
f5mail mail -s "case 4" gg@lliv.com <testF5Email.inp

then ps, I got the following output:
Code:
      PID    TTY  TIME CMD
  9241010 pts/10  0:00 -ksh
 11731232 pts/10  0:00 send-mail -i -x 4' gg@lliv.com
 14942488 pts/10  0:00 ps

Here is my script source code:
Code:
#!/bin/ksh 
. /home/util/f5ScriptLib
#LOG_FILE=$LOG_PATH/f5mail.`date '+%y%m%d'`
LOG_FILE=$HOME/f5mail.`date '+%y%m%d'`
DEBUG=true
initLogFile $LOG_FILE
echo "#####################################################">>$LOG_FILE
echo "#Process ID=$$               #">>$LOG_FILE      
echo "#f5mail started at `date`#">>$LOG_FILE
echo "#####################################################">>$LOG_FILE
while read data1; do   #read data from input stream
    echo $data1 >>/tmp/$$ 
done
mailCmd=$1
i1=1
for p1 in "$@" ; do
        if [[ $i1 -gt 1 ]] then
            
            echo $p1|grep " ">/dev/null
            if [[ $? -eq 0 ]] then
                parameters1=`echo "$parameters1'$p1' "`
            else
                parameters1=`echo "$parameters1$p1 "`
            fi    
        fi
        i1=$((i1+1))
done
echo "/usr/bin/mail $parameters1 </tmp/$$"
exec /usr/bin/mail $parameters1 </tmp/$$ 
rm /tmp/$$
find $LOG_PATH -name "f5mail*" -mtime +7 -exec rm {} \; #log file housekeeping
echo "#####################################################">>$LOG_FILE
echo "#Process ID=$$               #">>$LOG_FILE      
echo "#f5mail ended at `date`#">>$LOG_FILE
echo "#####################################################">>$LOG_FILE

---------- Post updated at 01:46 PM ---------- Previous update was at 09:40 AM ----------

replace statement:
exec /usr/bin/mail $parameters1 </tmp/$$ to
eval /usr/bin/mail $parameters1 </tmp/$$
it works

Last edited by cstsang; 05-31-2012 at 10:42 PM.. Reason: something wrong
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: Send a mail in case grep finds something

I want to search a file if it contains special strings and if yes, the records found should be mailed. I can either do it with a temporary file: /usr/bin/grep somestring somefile > /tmp/tempfile && /usr/bin/mail -s "Found something" email@mycomp.com < /tmp/tempfile... or by running the grep... (10 Replies)
Discussion started by: Cochise
10 Replies

2. Shell Programming and Scripting

HTML Report from mail in ksh 88

Hi Team, I'm trying to send HTML Report from email using the below script (Using ksh 88 version) #!/bin/ksh set -x SUB="Test Email" Mail_Body="This is for testing" Send_Mail_HTML() { ( echo "FROM: abcd@test.com" echo "To: abcd@test.com" echo "Subject:... (2 Replies)
Discussion started by: smile689
2 Replies

3. Shell Programming and Scripting

AIX .ksh script freezes when using the mail -s command

Hello I am trying to send an email when a .KSH script is run on an AIX Machine. This email will only include a subject line that is made up of variables from within the script, and is as follows: CURRENT_DATE=`date +%Y%m%d` TIME=`date` ADMIN="myname@domain.com" date block () { ... (4 Replies)
Discussion started by: jimbojames
4 Replies

4. Shell Programming and Scripting

KSH - mailx - Redirect the undelivered mail

Hi, I need to create one KSH which will send mail to set of recipients using "mailx" command like below. mailx -s "Test mail" "test@yahoo.com, test@gmail.com" <$output.txt The recipients are in different domains (like yahoo, gmail, etc.). My requirement is, if any mail is undelivered,... (1 Reply)
Discussion started by: Matrix2682
1 Replies

5. Shell Programming and Scripting

KSH Programming to read and mail fields

I have a file with the following values: File name à a.log (bulk file with 100+ lines with the similar format) aaaa|bbbb|cccc|dddd|eeee|ffff|gggg|hhhh|iiii| aaaa|bbbb|cccc|dddd|eeee|ffff|gggg|hhhh|iiii| aaaa|bbbb|cccc|dddd|eeee|ffff|gggg|hhhh|iiii|... (3 Replies)
Discussion started by: shivacbz
3 Replies

6. Shell Programming and Scripting

Mail to: cc: How can i acheive this with ksh

Hi All, I have to write a script to send mail, in that i have to dynamically add the recepient in TO and my cc is a common one. For all mails my cc recepients are same. Only problem with TO recepient. Please i am looking for your inputs. (1 Reply)
Discussion started by: Arunprasad
1 Replies

7. Shell Programming and Scripting

Send an e-mail using ksh

Hi, I have a small script that outputs to a text file. I need to e-mail the contents of the text file to a mail alias. However, I cannot seem to get the script to print the 'subject', my script just leaves it blank. Has anybody any ideas what is wrong? if then (echo "\nHere is the report... (3 Replies)
Discussion started by: asulli01
3 Replies

8. UNIX for Dummies Questions & Answers

help on sending mail in ksh

folks, I wrote a script like follow for sending notification email, but the problem is cannot pass the multiple words to the subject line, any help: ======================================= send_msg () { send_email $1 exit 1; } send_email () { mail -s $1 $mail_address << MAIL... (2 Replies)
Discussion started by: ting123
2 Replies

9. Shell Programming and Scripting

Using $MAIL in ksh

I'm trying to write a menu script in ksh to allow a user to find his/her mail path. Display the mail file path") print -n "Mail File Path: " $MAIL It's not working although it works when I'm simply doing it from the command line. Also, I'm using the same formula to find the shell path... (2 Replies)
Discussion started by: r0mulus
2 Replies

10. UNIX for Dummies Questions & Answers

mail problem (NOT Mail or Mail.app)

When I try to use the CLI mail, I get the following error. What's wrong? Welcome to Darwin! % mail root Subject: test test . EOT % /etc/mail/sendmail.cf: line 81: fileclass: cannot open /etc/mail/local-host-names: Group writable directory Do I just need to change the... (1 Reply)
Discussion started by: chenly
1 Replies
Login or Register to Ask a Question