-
Notifications
You must be signed in to change notification settings - Fork 0
/
smail.sh
65 lines (55 loc) · 1.7 KB
/
smail.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
function smail
{
TO=$1;
FROM=$2;
cmd=$3;
add=false;
declare -A to_info;
declare -A from_info;
while read -r line
do
if echo "$line" | grep -q "$TO:"; then
add=true;
fi;
if $add; then
key=$(echo $line | cut -d':' -f 1);
key="$(echo -e "${key}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" #trim string
value=$(echo $line | cut -d':' -f 2);
value="$(echo -e "${value}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" #trim string
to_info+=([$key]=$value);
fi
if echo "$line" | grep -q "port"; then
add=false;
fi
done < "mail.config"
while read -r line
do
if echo "$line" | grep -q "$FROM:"; then
add=true;
fi;
if $add; then
key=$(echo $line | cut -d':' -f 1);
key="$(echo -e "${key}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" #trim string
value=$(echo $line | cut -d':' -f 2);
value="$(echo -e "${value}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" #trim string
from_info+=([$key]=$value);
fi
if echo "$line" | grep -q "port"; then
add=false;
fi
done < "mail.config"
subject="Results run $cmd";
echo -n "Password ${from_info["address"]}:"
read -s password;
echo
myLog="./log.txt"
msg="$($cmd > $myLog 2>&1)"
mail -s "$subject" -r "${from_info["address"]}" -S smtp="${from_info["smtp"]}"\
-S smtp-auth=login \
-S smtp-auth-user="${from_info["address"]}" \
-S smtp-auth-password="$password" \
-S sendwait \
"$myLog" "${to_info["address"]}" <<< "$msg"
}
smail "to" "from" "ls"