How to pass subject,mailbody and filename as parameters to function?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass subject,mailbody and filename as parameters to function?
# 1  
Old 04-13-2017
How to pass subject,mailbody and filename as parameters to function?

Hi Experts,
how to pass subject,mailbody and filename as parameters to function.

Code:
 
 mode=$1
file=/db/files/uniq.txt
 mail_send() {
export MAILPART=$(uuidgen)
export MAILPART_BODY=$(uuidgen)
{
  echo "TO:nalu.d@hes.com"
        echo "Subject:$subject"
        echo "MIME-Version: 1.0"
        echo "Content-Type: multipart/mixed; boundary=\"$MAILPART\""
        echo "--$MAILPART"
  echo ""
        echo "Hi"
  echo "$subject"
  echo ""
     cat $file
  echo ""
  echo "*****END*****"
} | /usr/sbin/sendmail -t
}

In the below case I want send an email "Incorrect path".
I don't want to send the file(file=/db/files/uniq.txt).
Issue: It's sending the file as well .
Code:
check=$(ls -d ${path} | wc -l )
if [[ $check -eq 0 ]]; then
subject="Incorrect path"
mail_send $Subject $subject
exit 0
fi

Code:
 
 if [[ $mode -eq 1 ]]
then
mcount=0
day_count=0
while [[ $bback -ne 0 ]]; do
finalFormat=$(echo "$finalFormat" | sed -r 's/[H]+//g;s/_*$//g;s/%*$//g;s/-*$//g')
start=`date +${finalFormat} -d "$bback day ago"`
mcount=`expr $mcount + 1`
file_name="${start}"
printf "$file_name\n"
fi
bback=`expr $bback - 1`
done >>$file
 if [[ $mode -eq 2 ]]
then
mcount=0
day_count=0
while [[ $bback -ne 0 ]]; do
finalFormat=$(echo "$finalFormat" | sed -r 's/[HMS]+//g;s/_*$//g;s/%*$//g;s/-*$//g')
start=`date +${finalFormat} -d "$bback month ago"`
mcount=`expr $mcount + 1`
file_name="${start}"
printf "$file_name\n"
fi
bback=`expr $bback - 1`
done >>$file

Requirement : mail should send the file(/db/files/uniq.txt) and based on the mode subject has to be changed.
Issue: Always it's send same subject.
If mode is 1 subject should be commerce file .If mode is 2 subject should be economics file
Code:
if [[ $missing_count -gt 0 ]]; then
mail_send $Subject $subject $file
fi

In the file(/db/files/uniq.txt) data is as below
Code:
201704-12
201704-11
201704-23

Issue: In the mail it's coming as 201704-12201704-11201704-08.
Even if I add it as attachment same issue.

Please help me.
Thanks in Advance.

---------- Post updated at 07:52 AM ---------- Previous update was at 03:22 AM ----------

Hi All,

I have fixed all other could you please help me on this piece.
I am unable to fix.

In the file(/db/files/uniq.txt) data is as below

Code:
 
 201704-12 
 201704-11
 201704-23

Issue: In the mail it's coming as 201704-12201704-11201704-08.
Even if I add it as attachment same issue.

Thanks in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

To invoke pass parameters in Oracle file

Hi Guys, I am having a sql script file which does below operations ALTER TABLE M1 EXCHANGE PARTITION FOR (TO_DATE('&1','dd-MON-yyyy')) WITH TABLE &2 INCLUDING INDEXES; i need to pass variables in such a way that if i pass start date and end date as parameter , something like my... (2 Replies)
Discussion started by: rohit_shinez
2 Replies

2. Shell Programming and Scripting

Pass parameters to a function and running functions in parallel

Hi , I have a script which is using a text file as I/P. I want a code where it reads n lines from this file and pass the parameters to a function and now this script should run in such a way where a function can be called in parallel with different parameters. Please find below my script, it... (1 Reply)
Discussion started by: Ravindra Swan
1 Replies

3. Shell Programming and Scripting

Pass Parameters to awk command

I need to pass values at runtime for the below awk command where l is the length and partial.txt is the file name. awk -v l=285 '{s="%-"l"s\n";printf(s,$0);}' partial.txt > temp1.txt; (5 Replies)
Discussion started by: Amrutha24
5 Replies

4. Emergency UNIX and Linux Support

Pass two parameters

Hi I have a batch file aaa.exe which needs two input parameters: Usually the command's format likes aaa 555 10000 But I want to use parameters to do it. aaa $1 $2 These two parameters come from a text file list.txt 41800497 41801375 41814783 41816135 41814930 41816135 41819987 41820843... (4 Replies)
Discussion started by: zhshqzyc
4 Replies

5. Shell Programming and Scripting

pass shell parameters to awk does not work

Why does this work for myfile in `find . -name "R*VER" -mtime +1` do SHELLVAR=`grep ^err $myfile || echo "No error"` ECHO $SHELLVAR done and outputs No error err ->BIST Login Fail 3922 err No error err ->IR Remote Key 1 3310 err But... (2 Replies)
Discussion started by: alan
2 Replies

6. Shell Programming and Scripting

Can't get shell parameters to pass properly to sqlplus

Gurus, The issue I'm having is that my Shell won't accept SQL parameters properly...... Here's they way I'm running it.... applmgr@ga006hds => sh CW_MigrationDeployScript.sh apps <appspwd> <SID> '01-JAN' '31-MAR' The process just hangs not submitting the SQL job... ... (3 Replies)
Discussion started by: WhoDatWhoDer
3 Replies

7. Shell Programming and Scripting

Pass parameters to function

Hi, for example I have this function: function get_param () { test=echo "some string" test2=echo "someother string" } I want to call this function and get test or test2 result, how do I do that ? Thank you (2 Replies)
Discussion started by: ktm
2 Replies

8. Shell Programming and Scripting

How to pass parameters transparently into a sub script

Hi, I am trying to write a script like this: #!/bin/ksh #script name: msgflow #The awk commands for Solaris and Linux are incompatible if ] then msgflow-solaris $* elif ] then msgflow-linux $* fi This script is shared by a file system which is visible to both... (3 Replies)
Discussion started by: danielnpu
3 Replies

9. Shell Programming and Scripting

How to pass parameters to an awk file?

I have an awk file where I need to pass a filename and a value as a parameter from a sh script. I need to know how to pass those values in the sh script and how to use the same in the awk file. Thanks in advance!!! Geetha (3 Replies)
Discussion started by: iamgeethuj
3 Replies

10. UNIX for Dummies Questions & Answers

How to pass two or more parameters to the main in shell script

Hey Guys from the below script what I understood is we are sending the the first parameter as input to the main (){} file main > $LOGFILE 2>&1 but can we send two or three parameter as input to this main file as main > $LOGFILE 2>&1 2>&2 like this Can any one plz help I need to writ a... (0 Replies)
Discussion started by: pinky
0 Replies
Login or Register to Ask a Question