Welcome to the Linux Foundation Forum!

Need help with script

Posts: 1
edited January 2015 in Red Hat Enterprise

Hi,

I am using red hat enterprise linux server release 5.7

I am trying to send an email from one directory called bin.I am trying to run a shell script from that location. The output file is located in the directory named temp.

I am able to send file if it is hardcoded. But if it is having a timestamp on the end of the file. I am not able to send it.

TSTAMP ='date + %Y%m%d%H%M%S'
filename=/temp/testfile.$TSTAMP


the syntax what i am using is mentioned below.

cat $filename | mail -s "test email" test@testemail.com

The above cat command is in if condition.

what i need is the content of the $filename should be displayed in the body of the email.

The below command works for a hard coded file for me.

echo $filename
cat /temp/filename.20150101171152 | mail -s "test email" test@testemail.com


Can you help me please

Thank You

Comments

  • Posts: 2,177
    Have you considered adding the timestamp on the subject to simplify output and using the -q option to send the file contents?

    Another option would be to output the timestamp into a file in tmp, then append the testfile on the end, send the file as the message and then delete the temp file.

    The second option is below:
    1. TSTAMP ='date + %Y%m%d%H%M%S'
    2. filepath=/temp/
    3. temppath=/tmp/
    4. filename=testfile.$TSTAMP
    5.  
    6. cat ${TSTAMP}>\tmp\${filename}
    7. cat ${filepath}${filename}>>${temppath}${filename}
    8.  
    9. mail -q ${temppath}${filename} -s "test email" test@testemail.com
    10.  
    11. rm ${temppath}${filename}

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training