shell script that send email before exiting


i am trying to write a shell script that will send me an email before exiting itself


as i am running this on an amazon ec2 DEBAIN spot request and it should send me an email before the instances is terminated

#!/bin/bash sendEmailLog() { emailLog=true if [ $emailLog = "true" ];then /usr/bin/mpack -s "emailed log" -a "/srv/log.html" "emailid@gmail.com"; fi exit 0; } trap sendEmailLog INT TERM EXIT KILL QUIT aws ec2 terminate-instances instances ID

i tried the above code it doesnot send me an email before its terminated i am using DEBAIN 7


I think you might have a couple issues. I'm not super-familiar with mpack, but it looks like your syntax is correct (except the ";" at the end). Make a couple changes, below, and see if it helps.

I would use quotes define your emailLog string, although it's not really clear why you're using a string for a boolean statement that, as far as I can tell, you want to ALWAYS run. Unless you want to get an error code.


To check for equality, use two ==:

if [ $emailLog == "true" ]; then

And as I said, the ';' is superfluous.

If I were to re-write it, I would write it like this:

sendEmailLog() { /usr/bin/mpack -s "emailed log" -a "/srv/log.html" "emailid@gmail.com" && exit 1 exit 0 } trap sendEmailLog SIGINT SIGTERM SIGKILL aws ec2 terminate-instances instances ID


  • Excel VBA: Secure way to get user's database login/password for connection string?
  • list.files() doesn't find all the files in a folder
  • JBoss Enterprise Application Platform vs JBoss Enterprise SOA Platform
  • mySQL INSERT IGNORE doesn't “ignore”
  • Docker daemon and DNS
  • Getting CouchDB to work with node.js
  • “Internal Server Error” with Hello World Python App
  • Sending signal to thread from annother non-process and logging stack not happening
  • Chart js - Draw center of each bubbles of a bubble chart
  • Pasting URLs That Have Been Scraped From a Webpage
  • Pass pointer array to function
  • Modifying files nested in tar archive
  • Laravel 5.1 + PHPunit - API test returns always invalid argument error foreach
  • Function calling incorrect values
  • How can I filter REST calls results based on Roles and current user context in Loopback (server side
  • Is there a way to get the process ID of a console program I've just started in the background?
  • TCameraComponent and TVideoCaptureDevice do not initialize in Win32
  • cordova build android throws error on Ubuntu 12.04
  • ASP.NET MVC - Detect Time Spent on Page
  • Excel 2007: Format of email address from Outlook 2007
  • How to debug Shell command after customization
  • pygame.init() shows as undefined variable after installing Pygame
  • Pythons argparse default value doesn't work
  • Are there any issues with placing image as background on an extended JFrame?
  • Java making confirming exit
  • Magento get URL before current
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • Ubuntu and bcrypt
  • cygwin cannot exec 'git-add--interactive' permission denied
  • Using JRuby with Rails 3.2
  • Code in Job's Script Block after Start-Process Does not Execute
  • error importing numpy
  • Obtain ObjectIdHex value from mgo query
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Upload files with Ajax and Jquery
  • AngularJs get employee from factory
  • Proper way to use connect-multiparty with express.js?
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?