#!/bin/bash
# mysql login
MYUSER=****
MYPW=****
# Email für Versand
Reci=****
# SCQ Abfrage Belgium
echo "
SELECT
ticket_0.tn AS 'OTRS',
ticket_0.freetext5 AS 'MKS',
ticket_0.freetext7 AS 'Customer',
ticket_0.title AS 'Summery',
ticket_state_0.name AS 'State',
ticket_0.freetext9 AS 'System',
ticket_0.freetext10 AS 'Component',
ticket_0.create_time AS 'Created',
ticket_0.id
FROM
otrs.ticket ticket_0,
otrs.ticket_state ticket_state_0
WHERE
ticket_state_0.id = ticket_0.ticket_state_id AND
((ticket_0.freetext13='Belgium') AND
(ticket_0.freetext9 Like 'CINEO%')) AND
EXISTS (SELECT ticket_history_0.ticket_id FROM otrs.ticket_history ticket_history_0 WHERE ticket_history_0.ticket_id = ticket_0.id AND ticket_history_0.queue_id = 184)
ORDER BY ticket_0.create_time
INTO OUTFILE '/tmp/otrs_belgium.csv';" > /tmp/belgium
# SCQ Abfrage Malaysia
echo "
SELECT
ticket_0.tn AS 'OTRS',
ticket_0.freetext5 AS 'MKS',
ticket_0.freetext7 AS 'Customer',
ticket_0.title AS 'Summery',
ticket_state_0.name AS 'State',
ticket_0.freetext9 AS 'System',
ticket_0.freetext10 AS 'Component',
ticket_0.create_time AS 'Created',
ticket_0.id
FROM
otrs.ticket ticket_0,
otrs.ticket_state ticket_state_0
WHERE
ticket_state_0.id = ticket_0.ticket_state_id AND
((ticket_0.freetext13='Malaysia') AND
(ticket_0.freetext9 Like 'CINEO%')) AND
EXISTS (SELECT ticket_history_0.ticket_id FROM otrs.ticket_history ticket_history_0 WHERE ticket_history_0.ticket_id = ticket_0.id AND ticket_history_0.queue_id = 184)
ORDER BY ticket_0.create_time
INTO OUTFILE '/tmp/otrs_malaysia.csv';" > /tmp/malaysia
# SCQ Abfrage Österreich
echo "
SELECT
ticket_0.tn AS 'OTRS',
ticket_0.freetext5 AS 'MKS',
ticket_0.freetext7 AS 'Customer',
ticket_0.title AS 'Summery',
ticket_state_0.name AS 'State',
ticket_0.freetext9 AS 'System',
ticket_0.freetext10 AS 'Component',
ticket_0.create_time AS 'Created',
ticket_0.id
FROM
otrs.ticket ticket_0,
otrs.ticket_state ticket_state_0
WHERE
ticket_state_0.id = ticket_0.ticket_state_id AND
((ticket_0.freetext13='Austria') AND
(ticket_0.freetext9 Like 'CINEO%')) AND
EXISTS (SELECT ticket_history_0.ticket_id FROM otrs.ticket_history ticket_history_0 WHERE ticket_history_0.ticket_id = ticket_0.id AND ticket_history_0.queue_id = 184)
ORDER BY ticket_0.create_time
INTO OUTFILE '/tmp/otrs_austria.csv';" > /tmp/oesterreich
# SCQ Abfrage Schweiz
echo "
SELECT
ticket_0.tn AS 'OTRS',
ticket_0.freetext5 AS 'MKS',
ticket_0.freetext7 AS 'Customer',
ticket_0.title AS 'Summery',
ticket_state_0.name AS 'State',
ticket_0.freetext9 AS 'System',
ticket_0.freetext10 AS 'Component',
ticket_0.create_time AS 'Created',
ticket_0.id
FROM
otrs.ticket ticket_0,
otrs.ticket_state ticket_state_0
WHERE
ticket_state_0.id = ticket_0.ticket_state_id AND
((ticket_0.freetext13='Switzerland') AND
(ticket_0.freetext9 Like 'CINEO%')) AND
EXISTS (SELECT ticket_history_0.ticket_id FROM otrs.ticket_history ticket_history_0 WHERE ticket_history_0.ticket_id = ticket_0.id AND ticket_history_0.queue_id = 184)
ORDER BY ticket_0.create_time
INTO OUTFILE '/tmp/otrs_switzerland.csv';" > /tmp/schweiz
# SCQ Abfrage Singapur
echo "
SELECT
ticket_0.tn AS 'OTRS',
ticket_0.freetext5 AS 'MKS',
ticket_0.freetext7 AS 'Customer',
ticket_0.title AS 'Summery',
ticket_state_0.name AS 'State',
ticket_0.freetext9 AS 'System',
ticket_0.freetext10 AS 'Component',
ticket_0.create_time AS 'Created',
ticket_0.id
FROM
otrs.ticket ticket_0,
otrs.ticket_state ticket_state_0
WHERE
ticket_state_0.id = ticket_0.ticket_state_id AND
((ticket_0.freetext13='Singapore') AND
(ticket_0.freetext9 Like 'CINEO%')) AND
EXISTS (SELECT ticket_history_0.ticket_id FROM otrs.ticket_history ticket_history_0 WHERE ticket_history_0.ticket_id = ticket_0.id AND ticket_history_0.queue_id = 184)
ORDER BY ticket_0.create_time
INTO OUTFILE '/tmp/otrs_singapore.csv';" > /tmp/singapur
#MySql starten mit query ausführen
#mysql -h localhost -u $MYUSER -p$MYPW -D "otrs7" -e "Select..." execute SQL-Query
echo "mysql -h localhost -u $MYUSER -p$MYPW -D "otrs7" < belgium + malaysia"
mysql -h localhost -u $MYUSER -p $MYPW -D "otrs7" < /tmp/belgium
mysql -h localhost -u $MYUSER -p $MYPW -D "otrs7" < /tmp/malaysia
mysql -h localhost -u $MYUSER -p $MYPW -D "otrs7" < /tmp/oesterreich
mysql -h localhost -u $MYUSER -p $MYPW -D "otrs7" < /tmp/schweiz
mysql -h localhost -u $MYUSER -p $MYPW -D "otrs7" < /tmp/singapur
#Email versenden mit Anhang mit mutt
echo "mutt -s "Tickets.csv" -a /tmp/otrs_belgium.csv + malaysia $Reci < /home/otrsmgr/Emailnachricht.txt"
mutt -s "Tickets.csv" -a /tmp/otrs_belgium.csv -a /tmp/otrs_malaysia.csv -a /tmp/otrs_austria.csv -a /tmp/otrs_switzerland.csv -a /tmp/otrs_singapore.csv $Reci < Emailnachricht.txt
# Datein wird wieder gelöscht
echo "rm /tmp/otrs_belgium.csv + otrs_malaysia.csv"
rm /tmp/otrs_belgium.csv
rm /tmp/otrs_malaysia.csv
rm /tmp/otrs_austria.csv
rm /tmp/otrs_switzerland.csv
rm /tmp/otrs_singapore.csv
rm /tmp/belgium
rm /tmp/malaysia
rm /tmp/oesterreich
rm /tmp/schweiz
rm /tmp/singapur
echo "exit"
exit