1

I have written the below script to automate email notification.

#!/bin/bash

TO_ADDRESS="[email protected]"
FROM_ADDRESS="[email protected]"
SUBJECT="November 2016 Step"
BODY="Hi All,\n\n Product Mapping Check is done.\n\n Regards, \n\n Pratik"
echo ${BODY}| mail -s ${SUBJECT} ${TO_ADDRESS} -- -r ${FROM_ADDRESS}

Requirement : A unix script when executed should send an email from [email protected] to [email protected] with above subject and body. When the script is run it should ask for month year parameter. For example register.sh is the script name. the run command should look like

> register.sh November 2016

When the above script is executed, it should take the month and year input and copy it to the subject line . Then send out the email.

Let me know if i need to config anything or call any server details in the script.

2

2 Answers 2

0

You can use the shell's positional parameters, $1, $2, ... to refer to arguments of your script:

SUBJECT="$1 $2 Step"

With register.sh November 2016 this makes $1 contain November and $2 contain 2016.

Sign up to request clarification or add additional context in comments.

2 Comments

Do I need to declare $1 and $2 anywhere....or simply putting SUBJECT="$1 $2 Step" will work?
@PratikFouzdar No declaration necessary. As for your error, I have no idea because you don't provide any context.
0

The shell script is having a concept of runtime arguments which can be added by the below command

$1, $2 etc

$1 is the first argument $2 is the second argument from runtime

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.