Append date to an executing script

This works except the date being sent to this script.

Is it because I am trying to write to an executing script?

Is there a better way?

date '+%m-%d-%Y_%I:%M-%p'>> Send_Email.sh
CONTENT="Backup to Maxtor Drive has occured."
echo "Sending email."
/usr/sbin/ssmtp -t << EOF
To: a7@yahoo.com
From: a7@yahoo.com
Subject: Backups to Maxtor Drive


$CONTENT

EOF

------ Post updated at 04:20 PM ------

#Example of a command substitution to put the date into a variable and put that variable in the body of the mail before or after $CONTENT.
NOW=$(date +%m-%d-%Y_%I:%M%p)
#Date_Of_Backup=date +%m-%d-%Y_%I:%M%p
CONTENT="Backup to Maxtor Drive performed on $NOW ."
echo "Sending email."
/usr/sbin/ssmtp -t << EOF
To: a7@yahoo.com
From: a7@yahoo.com
Subject: Backups to Maxtor Drive 

$CONTENT

EOF

There is an error code for this: ETXTBSY (Linux name) which means you are trying to write to an executable file of whatever type while it is busy running.

I would guess that is what is happening.

Note that the C standard requires only three codes (macros actually) be defined:
EDOM
EILSEQ
ERANGE

Your system may have a different name. Or may enforce the error a different way. Read the files /usr/include/errno.h and /usr/include/sys/errno.h They will list all of the available error "conditions" for your system.

1 Like