Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8411309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:23:50+00:00 2026-06-10T00:23:50+00:00

I am having difficulty getting this shell script to run. I decided to start

  • 0

I am having difficulty getting this shell script to run. I decided to start using simple functions in my scripts as it’s more readable and maintainable. This is my first attempt, and everything runs great, but the mail function hangs. I know that mail waits for EOF, but I am piping my body into it using echo.

I imagine I’ve done something wrong with quoting or some part of passing arguments in shell scripts that I don’t fully understand. I’ve tried every combination of quotes I can think of, but it still hangs every time.

#!/bin/bash

if [ -f /tmp/imports ]
then
        echo "Script Off"
        exit
fi

OLDIFS=$IFS
IFS=$'\n'
IFS=$OLDIFS
LOGFILE="/var/log/file.log"

log(){
        DATE=`date "+%m-%d-%Y %H:%M"`
        MESSAGE="$DATE - $@"

        echo $MESSAGE
        echo $MESSAGE >>$LOGFILE
}

mail(){
        BODY="$1"
        SUBJECT="$2"

        echo "$BODY" |  mail -s "$SUBJECT" my@email.com
}

log "Script Started"

TodayFiles=`find /ftpfiles/incoming/ -type f -mmin +60`
Count=`find /ftpfiles/incoming/ -type f -mmin +60 | wc -l`

log "$Count Files Found"

if [ $Count -gt 4 ]; then
        log "Too Many Files!!!\n"
        mail "There were 5 or more files found by the script. I have not moved any files at this time. There is likely something very wrong. Please check things out immediately." "ATTN: TOO MANY FILES!"

fi

if [ $Count -gt 0 ]; then
        log "Scanning Files..."
        for Source in $TodayFiles
        do
                log "Found file: $Source"
                #mv "$Source" "/ftpfiles/rejected$Source"
                log "Moved file to: /ftpfiles/rejected$Source"
                mail "The file $Source has been moved to rejected. Please find out why and send the proper rejection. Thank You." "ATTN: Stranded Import file Found"
        done
fi
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:23:51+00:00Added an answer on June 10, 2026 at 12:23 am

    Your mail() function has the same name as the mail command.
    Rename mail() to something like mymailwrapper() otherwise it’s just calling itself recursively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some difficulty getting this script to execute properly. The create_rss function does
I am using MonoDevelop on MacOS and I am having difficulty getting AjaxControlToolkit's TabContainer
I am using NHibernate for an ecommerce site and am having difficulty getting what
I am having difficulty getting this scoring function to work. The objective of my
I'm having difficulty getting the awk command inside a bash script to work. The
I'm following a tutorial on php, and am having difficulty getting this to work.
I am having difficulty getting my Monodroid application retrieve a location when I run
I am having difficulty getting started with interfacing my PHP script to Moodle 2.0
I'm using Devise to set up user authentication, but I'm having difficulty getting users
I am creating a Windows service using Apache's procrun, and I'm having difficulty getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.