Question
Hello, Please edit my Linux BASH script so it runs successfully. DIRECTIONS: Name Your Script mailProcessing Have your script check the mail spool for any
Hello,
Please edit my Linux BASH script so it runs successfully.
DIRECTIONS:
Name Your Script mailProcessing Have your script check the mail spool for any new messages If a message is found: Create a new file Call This File
MY SCRIPT:
#! /bin/bash
# The first token read should be "From" indicating a new message. # We will start a loop that will continue as long as there is a message while read label contents ; do while [ $? -eq 0 -a "$label" == "From" ]; do # Process The Header # Run this loop until we hit a blank line while [ "$label $contents" != " " ]; do # Process the header information using a case statement case "$label" in "From") # Extract userName/sender and Time Stamp from contents email=${contents%% *} sender=${email%@*} timestamp= # example: How to remove blank spaces from a string # var= " lakdjsf lkadsjf "; var=$(echo "$var" | sed 's/[[:space:]]//g') # result will be: lakdjsflkadsjf timpestamp= ;; * ) : # A : is a placeholder so the script continues. ;; esac # Read the next line of the message read label contents done
# At this point, I should be at a blank line. # Let's read the next line to read the beginning of the message body touch _.mesg read label contents # Process The Body # Loop until blank line which indicates end of message while [ "$label $contents" != " " ]; do # ADD Code Here To Append Message Body To .mesg file # HINT: Look at how we echo information in the case statement. # Its the exact same code without the case statement syntax. echo $label $contents >> .mesg # Read next line of the message read label contents done # We have hit the end of the message. We will now close off the loop. If # another message exists, this process will start over. done # Reply to the sender done < /var/mail/$USER
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started