[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

Looking for a Linux wrapper script

Hello,
This may be difficult but what I'm looking for is a linux shell script that I can use as a wrapper to notify me when something completes. I realize I will have to adjust script to key off a certain word for script to notice completion. I also would like a section to key off of for failure so that I can be notified of completion or failure.
As for notification we currently use /etc/alias and I can just use my account already setup in there.
Does anyone have a wrapper already created I could have? Or could someone point me in the direction of how to create my own?
Im also wondering how the wrapper works? Do I call the program or command I want notification from within the wrapper?

Thanks!
0
k3vsmith
Asked:
k3vsmith
1 Solution
 
TintinCommented:
Assuming you are using the wrapper to launch the script, then use something like:

#!/bin/bash
CMD="$*"

$CMD

if [ $? -eq 0 ]
then
     echo "$CMD completed successfully" | mail -s "Command completed" user@example.com
else
     echo "$CMD failed" | mail -s "Command failed" user@example.com
fi

Open in new window


Then call the wrapper script with the appropriate command and arguments, eg:

wrapper.sh /path/to/command arg1 arg2
0
 
k3vsmithAuthor Commented:
Ok this will most likely work for what I need it for. Thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now