0

So I am trying to take this:

SELECT  'cran_juniper' AS `set`, c.*
FROM    cran_juniper c
WHERE   ROW(c.device_fqdn, c.device_ip, c.interface, c.admin_state, c.link_state, c.description) NOT IN
        (
        SELECT  device_fqdn, device_ip, interface, admin_state, link_state, description
        FROM    cran_juniper_baseline
        )
UNION ALL
SELECT  'cran_juniper_baseline' AS `set`, b.*
FROM    cran_juniper_baseline b
WHERE   ROW(b.device_fqdn, b.device_ip, b.interface, b.admin_state, b.link_state, b.description) NOT IN
        (
        SELECT  device_fqdn, device_ip, interface, admin_state, link_state, description
        FROM    cran_juniper
        )
into outfile 'today.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
;

And insert it into a bash script. Considering there's a SLEW of special characters all over this query, I am having a hard time finding a way to go about this. Any assist would be magical.

1 Answer 1

2

1st solution using here-doc :

mysql -h 127.0.0.1 <<'EOF'
SELECT  'cran_juniper' AS `set`, c.*
FROM    cran_juniper c
...
;
EOF

2nd solution using a separate file

mysql -h 127.0.0.1 < file.sql # you will put all of your query within this file

Check

man bash | less +/here-doc
Sign up to request clarification or add additional context in comments.

1 Comment

That was the one, and a lot easier than I thought it'd be. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.