Oozie shell action doesn't send mail notification - shell

I am running a shell script through oozie. A piece of my shell script has below code. I receive an email when I run this shell script through unix Command line but when I run this shell script through oozie Job it will succeed but I dont get any mail. How can I resolve this? Or is there any alternative way I can get email with attachment once string matches in unix filesystem?
if [ "$Var" = "Error" ]
then
echo "Data error" | mail -v -s "Data Error" -a error.csv -S smtp=smtp://mail-gateway -S from=localhost#gmail.com" Kevin#gmail.com
exit

Related

Email the output of a shell script

I have a shell script (script.sh) in which I run a simple python web scraper
python3 script.py
As I run this shell script in a cron job, I want to be notified by email if something goes wrong. I found this code on stackoverflow, which I put at the bottom of my .sh script:
./script.sh 2>&1 | tee output.txt | mail -s "Script log" email#address.com
The problem is that the script now seems to be looping; where it should only take a few seconds, it now takes a few minutes to run and I receive 10-20 emails in my mailbox. The content of these emails differs, most of the times the emails are empty, but sometimes they contain messages such as:
./script.sh: 4: ./script.sh: Cannot fork
or:
mail: Null message body; hope that's ok
I'm not sure what goes wrong here. What can I do to fix this?
The script runs, runs the python, then calls itself again, until it runs out of resources and fails to fork.
The .sh should contain:
python3 script.py 2>&1 | tee output.txt | mail -s "Script log" email#address.com
Assuming you actually want to create output.txt in whatever folder pwd is... otherwise you could leave that out entirely.
Alternatively you could just configure your MAILTO in your crontab (see https://www.cyberciti.biz/faq/linux-unix-crontab-change-mailto-settings/)

how to send an email when creating a bash script

I'm trying to create a bash script that will send me an email every time it pings an IP address.
When I run the script I get and error saying
bash: sendmail: command not found
Here is my code
while true; do
ping my_ip_address
echo "some message" | sendmail -s "test" "test#test.com"
sleep 20
done
and this is my sendmail.ini file
smtp_server=smtp.mailtrap.io
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
auth_username=f1e1ea69338455
auth_password=97ce281bfdb99f
pop3_server=pop3.mailtrap.io
pop3_username=f1e1ea69338455
pop3_password=97ce281bfdb99f
force_sender=
force_recipient=
hostname=
I have my sendmail.ini saved in C:\sendmail\
Looks like sendmail is not in your $PATH.
Try to either add directory with sendmail to your $PATH or use full path to sendmail.
Edit:
Also remove credentials from your question.

Mutt bash script sends email fine from command line but not from motioneye notification hook

So I'm about ready to pull my hair out on this one. I am running ssmtp and mutt on a freeBSD jail. I have a bash script called notify that contains the following line.
mutt -s "$subject" "$email" -a "$attachment" < "$logfile3"
When I run
bash notify.sh
The email will send just fine, but if I run that exact same command from inside motioneye I receive an extremely non-descript error from mutt
Could not send the message
I have tried using a daemon but that hasn't had any effect. I wish the mutt error message was more descriptive.
My script did not have access to the "sent" mailbox and therefore mutt was failing to send. -e "set copy=no" added to the mutt call corrected the issue.
For a better walkthrough: https://gitlab.com/muttmua/mutt/issues/119
Make sure you have bash installed (it isn't by default on FreeBSD) and try using absolute path to it (/usr/local/bin/bash).

mail (postfix) not running in launchAgent unless followed by another command

I'm running a user LaunchAgent in El Cap that is supposed to call postfix to send me an email when a certain automatically generated file is 0 length, meaning that something went wrong. Here's the line from the bash script where $me is my username:
echo 'Darn it' | mail -s 'Export failed' "$me"
It works fine if I run the script manually, but mail won't send anything when the agent runs.
By dumb luck I found that if I follow this command with the following command, the message will get sent:
/usr/local/bin/terminal-notifier -message "File export failed." -title "Alert"
Other following commands won't do it (like echo, for example).
Any idea what's going on there?

Execute a read command

I have a little script that I use to send bash commands to several web servers under a load balancer. I'm able to send the command successfully, but I also want to execute it locally.
#!/bin/bash
echo "Type commands to be sent to web servers 1-8. Use ctrl+c to exit."
function getCommand() {
read thisCmd
echo "Sending '$thisCmd'..."
if [ ! -z "$thisCmd" ]; then
# Run command locally
echo "From web1"
cd ~
command $thisCmd
# Send to remotes
for i in {2..8}
do
echo "From web$i..."
ssh "web$i" "$thisCmd"
done
fi
echo Done
getCommand
}
getCommand
But this is resulting in
user#web1:~$ ./sshAll.sh
Type commands to be sent to web servers 1-8. Use ctrl+c to exit.
cd html; pwd
Sending 'cd html; pwd'...
From web1
./sshAll.sh: line 11: cd: html;: No such file or directory
From web2...
/home/user/html
How do I get this working?
When expanding a variable as a command like this:
$thisCmd
Or this
command $thisCmd
Bash would only parse it as a single command so ; and the likes would be just considered as an argument or part of it e.g. html;
So one basic solution to that is to use eval:
eval "$thisCmd"
But it's a little dangerous. Still it's just the same as those you send to the remote servers. You still execute them like how eval does it.

Resources