1

Code Explanation: The below code is a simple script written by me to send a Installation status alert mail. It will be sent after completion of a linux software installation. In this code, If the user accept the mail notification he will be asked to enter his mail id. Then the mail will be send to him after installation completed.

#!/bin/bash

#######################################
# Independent Variables and  Properties Here
#######################################
PL_EMAIL_ALERT=""
#######################################
# User to get Email Alert
#######################################
echo "This will help user to get an email of an installation status."
verify -s "Do want to send Email"
if [ "$VerAns" = "y" ]
then
    read -e -p "Enter Email ID: " PL_EMAIL_ALERT
fi
#######################################
# Sending Email Alert
#######################################
echo "Sending Mail"
if [ ${#PL_EMAIL_ALERT} -ne 0 ]
then
    mail -s "software INSTALLATION MAIL ALERT" $PL_EMAIL_ALERT <<< "message1"
fi
echo ""
echo "Final step"
echo ""

Problem: My problem is when I try to execute the code I am getting the following error. verify: command not found As I am very new to linux I am unable to fix this issue. Can you please help me to understand what exactly I missed.

1

You can execute commands into Script if those commands are available in system.

In your case verify command is unavailable. Hence the error.

Either install the relevant package OR write a program/script/function by name verify

0

An error message on the form x: command not found occurs if the x command is not installed or found in your system. But there real problem here is that you seem to confuse the function of verify with the read shell builtin. Looking at its man page you should see that it doesn't do what you expect it to do: it's a tool for verifying certificates.

Use read -p as you already have done in the other part of the script to prompt for an answer. You could shorten your script by putting the e-mail sending part inside the if block:

# ...   

read -ep "Do you want to send Email? " alert
if [[ $alert =~ [Yy] ]]; then
    read -ep "Enter Email ID: " addr
    if (( ${#addr} )); then 
        echo "Sending Email"
        mail -s "software INSTALLATION MAIL ALERT" $addr <<< "message1"
    fi
fi

# ...
0

The VerAns, Y/N is never read, code below helps on that. Verify Function is not in your library, you should write of your own as SHW told,

    #!/bin/bash

#######################################
# Independent Variables and  Properties Here
#######################################
PL_EMAIL_ALERT=""
VerAns=""
#######################################
# User to get Email Alert
#######################################
echo "This will help user to get an email of an installation status."
#verify "Do want to send Email"
read -e -p "Y/N" VerAns
if [ "$VerAns" = "y" ]
then
    read -e -p "Enter Email ID: " PL_EMAIL_ALERT
fi
#######################################
# Sending Email Alert
#######################################
echo "Sending Mail"
if [ ${#PL_EMAIL_ALERT} -ne 0 ]
then
    mail -s "software INSTALLATION MAIL ALERT" $PL_EMAIL_ALERT <<< "message1"
fi
echo ""
echo "Final step"
echo ""

This works perfectly...

  • In Bash there's no need to initialize variables before assigning to them: echo $non_explicitly_inited_var just expands to nothing and read foo will read something into a variable foo whether it is used before or not. – user13742 Dec 19 '13 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.