Article 4V3E7 send output of command to different email address

send output of command to different email address

by
aristosv
from LinuxQuestions.org on (#4V3E7)
I am writing a loop that for each directory name it finds, will run some gcalcli commands and output calendar events. I also have a few if statements in the loop, and depending again on the directory name, it will create a variable for an email address. And then I want to send the output of the command to the correct email address.

The purpose is for each $client to receive the output of the gcalcli command on their $email.

I think I'm close, but it's a bit confusing on how to place everything in the script.

Code:#!/bin/bash

# variables
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

for client in $(/usr/bin/ls -d */ | /usr/bin/sed 's#/##')
do

if [[ $client = client1_name_here ]] ; then email=client1email@ishere ; fi
if [[ $client = client2_name_is_here ]] ; then email=client2emailaddress@ishere ; fi
if [[ $client = client3_name_is_placed_here ]] ; then client3email@isrighthere ; fi

echo
echo reminders for $client on $(date +%d-%m-%y)
echo -------------------------------------------------------
/usr/bin/gcalcli --config-folder $dir/$client/calendar agenda --tsv \
"$(/bin/date -d 'now')" "$(/bin/date -d 'now + 24 hours')"

echo $email
/usr/bin/mail -s "reminders for $(date +%d-%m-%y)" $email

donelatest?d=yIl2AUoC8zA latest?i=9f4vLABYekE:p8PaPMHjpk0:F7zBnMy latest?i=9f4vLABYekE:p8PaPMHjpk0:V_sGLiP latest?d=qj6IDK7rITs latest?i=9f4vLABYekE:p8PaPMHjpk0:gIN9vFw9f4vLABYekE
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments