No,
když už jsem se tady do hoffmanna pustil s tím, že to přece nemůže být nic složitého (trochu ho podezřívám z lenosti), tak jsem si to nakonec také raději ověřil. Předesílám, že v bashi jsem v životě nenapsal ani řádku, neboť jsem to zatím k ničemu nepotřeboval a ten včerejší "fragment" byl první pokus. Jedinými pomocníky mi byli dva osvědčení staří braši: UTFG a RTFM.
A opravdu, nic složitého to nebylo:
#!/bin/bash
function stfm()
{
echo "Posílám na adresu $address zprávu: $message"
}
days=(7 15 30)
itms=${#days[*]}
amsg=("Máš to už jen za ${days[0]}" "Tak ještě ${days[1]} dní" "Počkej si ještě celých ${days[2]} dní.")
adat=(`date --date="${days[0]} day" +%-d.%-m.%Y` `date --date="${days[1]} day" +%-d.%-m.%Y` `date --date="${days[2]} day" +%-d.%-m.%Y`)
patt=""
for dat in ${adat[*]}
do
if [ $patt ]; then
patt="$patt|$dat"
else
patt=$dat
fi
done
patt="(${patt})"
rows=(`grep -E "${patt}" ./test.txt`)
message=""
for item in ${rows[*]}
do
dfnd=0
for (( i=0; i<$itms; i++ ))
do
if [ $item = ${adat[$i]} ]; then
dfnd=1
message=${amsg[$i]}
fi
done
if [ $dfnd -eq 0 ] && [ ${#message} -gt 0 ]; then
address=$item
stfm
fi
done
Komentáře jsem záměrně vynechal pro případ, že to je domácí úloha z informatiky; pokud ten kód nepochopí, těžko ho pak ve škole vysvětlí :-)
Ještě dodám, že do těla funkce stfm (SendTheFuckinMail) si může hoffmann dopsat to, co potřebuje, neboť - jak uvádí - s tím problém nemá.
Script je možná trochu neučesaný a zdejší bashisté by to jistě zvládli lépe (o NTZ nemluvě; ten by to jistě byl schopen rovnou diktovat :-), ale funguje. Alespoň mě. Testovací soubor je zde:
1.3.2010 1000@test.com 2000@test.com 3000@test.com
2.3.2010 1001@test.com 2001@test.com 3001@test.com
3.3.2010 1002@test.com 2002@test.com 3002@test.com
4.3.2010 1003@test.com 2003@test.com 3003@test.com
5.3.2010 1004@test.com 2004@test.com 3004@test.com
6.3.2010 1005@test.com 2005@test.com 3005@test.com
7.3.2010 1006@test.com 2006@test.com 3006@test.com
8.3.2010 1007@test.com 2007@test.com 3007@test.com
9.3.2010 1008@test.com 2008@test.com 3008@test.com
10.3.2010 1009@test.com 2009@test.com 3009@test.com
11.3.2010 1010@test.com 2010@test.com 3010@test.com
12.3.2010 1011@test.com 2011@test.com 3011@test.com
13.3.2010 1012@test.com 2012@test.com 3012@test.com
14.3.2010 1013@test.com 2013@test.com 3013@test.com
15.3.2010 1014@test.com 2014@test.com 3014@test.com
16.3.2010 1015@test.com 2015@test.com 3015@test.com
17.3.2010 1016@test.com 2016@test.com 3016@test.com
18.3.2010 1017@test.com 2017@test.com 3017@test.com
19.3.2010 1018@test.com 2018@test.com 3018@test.com
20.3.2010 1019@test.com 2019@test.com 3019@test.com
21.3.2010 1020@test.com 2020@test.com 3020@test.com
22.3.2010 1021@test.com 2021@test.com 3021@test.com
23.3.2010 1022@test.com 2022@test.com 3022@test.com
24.3.2010 1023@test.com 2023@test.com 3023@test.com
25.3.2010 1024@test.com 2024@test.com 3024@test.com
26.3.2010 1025@test.com 2025@test.com 3025@test.com
27.3.2010 1026@test.com 2026@test.com 3026@test.com
28.3.2010 1027@test.com 2027@test.com 3027@test.com
29.3.2010 1028@test.com 2028@test.com 3028@test.com
30.3.2010 1029@test.com 2029@test.com 3029@test.com
31.3.2010 1030@test.com 2030@test.com 3030@test.com
1.4.2010 1031@test.com 2031@test.com
2.4.2010 1032@test.com 2032@test.com
3.4.2010 1033@test.com 2033@test.com
4.4.2010 1034@test.com 2034@test.com
5.4.2010 1035@test.com 2035@test.com
6.4.2010 1036@test.com 2036@test.com
7.4.2010 1037@test.com 2037@test.com
8.4.2010 1038@test.com 2038@test.com
9.4.2010 1039@test.com 2039@test.com
10.4.2010 1040@test.com 2040@test.com
11.4.2010 1041@test.com 2041@test.com
12.4.2010 1042@test.com 2042@test.com
13.4.2010 1043@test.com 2043@test.com
14.4.2010 1044@test.com 2044@test.com
15.4.2010 1045@test.com 2045@test.com
16.4.2010 1046@test.com 2046@test.com
17.4.2010 1047@test.com 2047@test.com
18.4.2010 1048@test.com 2048@test.com
19.4.2010 1049@test.com 2049@test.com
20.4.2010 1050@test.com 2050@test.com
21.4.2010 1051@test.com 2051@test.com
22.4.2010 1052@test.com 2052@test.com
23.4.2010 1053@test.com 2053@test.com
24.4.2010 1054@test.com 2054@test.com
25.4.2010 1055@test.com 2055@test.com
26.4.2010 1056@test.com 2056@test.com
27.4.2010 1057@test.com 2057@test.com
28.4.2010 1058@test.com 2058@test.com
29.4.2010 1059@test.com 2059@test.com
30.4.2010 1060@test.com 2060@test.com
1.3.2010 1061@test.com 2061@test.com
2.3.2010 1062@test.com 2062@test.com
3.3.2010 1063@test.com 2063@test.com
4.3.2010 1064@test.com 2064@test.com
5.3.2010 1065@test.com 2065@test.com
6.3.2010 1066@test.com 2066@test.com
7.3.2010 1067@test.com 2067@test.com
8.3.2010 1068@test.com 2068@test.com
9.3.2010 1069@test.com 2069@test.com
10.3.2010 1070@test.com 2070@test.com
11.3.2010 1071@test.com 2071@test.com
12.3.2010 1072@test.com 2072@test.com
13.3.2010 1073@test.com 2073@test.com
14.3.2010 1074@test.com 2074@test.com
15.3.2010 1075@test.com 2075@test.com
16.3.2010 1076@test.com 2076@test.com
17.3.2010 1077@test.com 2077@test.com
18.3.2010 1078@test.com 2078@test.com
19.3.2010 1079@test.com 2079@test.com
20.3.2010 1080@test.com 2080@test.com
21.3.2010 1081@test.com 2081@test.com
22.3.2010 1082@test.com 2082@test.com
23.3.2010 1083@test.com 2083@test.com
24.3.2010 1084@test.com 2084@test.com
25.3.2010 1085@test.com 2085@test.com
26.3.2010 1086@test.com 2086@test.com
27.3.2010 1087@test.com 2087@test.com
28.3.2010 1088@test.com 2088@test.com
29.3.2010 1089@test.com 2089@test.com
30.3.2010 1090@test.com 2090@test.com
31.3.2010 1091@test.com 2091@test.com
1.4.2010 1092@test.com 2092@test.com
2.4.2010 1093@test.com 2093@test.com
3.4.2010 1094@test.com 2094@test.com
4.4.2010 1095@test.com 2095@test.com
5.4.2010 1096@test.com 2096@test.com
6.4.2010 1097@test.com 2097@test.com
7.4.2010 1098@test.com 2098@test.com
8.4.2010 1099@test.com 2099@test.com
9.4.2010 1100@test.com 2100@test.com
10.4.2010 1101@test.com 2101@test.com
11.4.2010 1102@test.com 2102@test.com
12.4.2010 1103@test.com 2103@test.com
13.4.2010 1104@test.com 2104@test.com
14.4.2010 1105@test.com 2105@test.com
15.4.2010 1106@test.com 2106@test.com
16.4.2010 1107@test.com 2107@test.com
17.4.2010 1108@test.com 2108@test.com
18.4.2010 1109@test.com 2109@test.com
19.4.2010 1110@test.com 2110@test.com
20.4.2010 1111@test.com 2111@test.com
21.4.2010 1112@test.com 2112@test.com
22.4.2010 1113@test.com 2113@test.com
23.4.2010 1114@test.com 2114@test.com
24.4.2010 1115@test.com 2115@test.com
25.4.2010 1116@test.com 2116@test.com
26.4.2010 1117@test.com 2117@test.com
27.4.2010 1118@test.com 2118@test.com
28.4.2010 1119@test.com 2119@test.com
29.4.2010 1120@test.com 2120@test.com
30.4.2010 1121@test.com 2121@test.com
1.3.2010 1122@test.com
2.3.2010 1123@test.com
3.3.2010 1124@test.com
4.3.2010 1125@test.com
5.3.2010 1126@test.com
6.3.2010 1127@test.com
7.3.2010 1128@test.com
8.3.2010 1129@test.com
9.3.2010 1130@test.com
10.3.2010 1131@test.com
11.3.2010 1132@test.com
12.3.2010 1133@test.com
13.3.2010 1134@test.com
14.3.2010 1135@test.com
15.3.2010 1136@test.com
16.3.2010 1137@test.com
17.3.2010 1138@test.com
18.3.2010 1139@test.com
19.3.2010 1140@test.com
20.3.2010 1141@test.com
21.3.2010 1142@test.com
22.3.2010 1143@test.com
23.3.2010 1144@test.com
24.3.2010 1145@test.com
25.3.2010 1146@test.com
26.3.2010 1147@test.com
27.3.2010 1148@test.com
28.3.2010 1149@test.com
29.3.2010 1150@test.com
30.3.2010 1151@test.com
31.3.2010 1152@test.com
1.4.2010 1153@test.com
2.4.2010 1154@test.com
3.4.2010 1155@test.com
4.4.2010 1156@test.com
5.4.2010 1157@test.com
6.4.2010 1158@test.com
7.4.2010 1159@test.com
8.4.2010 1160@test.com
9.4.2010 1161@test.com
10.4.2010 1162@test.com
11.4.2010 1163@test.com
12.4.2010 1164@test.com
13.4.2010 1165@test.com
14.4.2010 1166@test.com
15.4.2010 1167@test.com
16.4.2010 1168@test.com
17.4.2010 1169@test.com
18.4.2010 1170@test.com
19.4.2010 1171@test.com
20.4.2010 1172@test.com
21.4.2010 1173@test.com
22.4.2010 1174@test.com
23.4.2010 1175@test.com
24.4.2010 1176@test.com
25.4.2010 1177@test.com
26.4.2010 1178@test.com
27.4.2010 1179@test.com
28.4.2010 1180@test.com
29.4.2010 1181@test.com
30.4.2010 1182@test.com
Tímto navrhuji označit téma jako vyřešené :-)