Created
October 10, 2021 13:22
-
-
Save LPX55/116902d13bc2d8ff7ff4254d0f80cbd7 to your computer and use it in GitHub Desktop.
ShapeShift Unified Docs Repo Daily Update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/bash | |
| # | |
| # Daily Email Updates | |
| # db creds | |
| user="user" | |
| database="db" | |
| file=/opt/repo/body.html | |
| email="user@example.com" | |
| where="WHERE p.\"updatedAt\"::TIMESTAMP AT TIME ZONE 'UTC' AT TIME ZONE 'America/New_York' BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW() ORDER BY p.\"updatedAt\"" | |
| # get the names of the users of changes in the last 24 hours, store in 'names' array | |
| query="SELECT u.name FROM \"pages\" p JOIN \"users\" u ON p.\"authorId\"=u.id $where" | |
| while read line | |
| do | |
| name+=("$line") | |
| done < <(sudo -u postgres -H -- psql -qAtX -d wiki -c "${query}") | |
| # get paths, store in 'path' array | |
| query="SELECT p.path FROM \"pages\" p $where" | |
| while read line | |
| do | |
| path+=("$line") | |
| done < <(sudo -u postgres -H -- psql -qAtX -d wiki -c "${query}") | |
| # get titles, store in 'title' array | |
| query="SELECT p.title FROM \"pages\" p $where" | |
| while read line | |
| do | |
| title+=("$line") | |
| done < <(sudo -u postgres -H -- psql -qAtX -d wiki -c "${query}") | |
| query="SELECT \"updatedAt\"::TIMESTAMP(0) AT TIME ZONE 'UTC' AT TIME ZONE 'America/New_York' FROM \"pages\" p $where" | |
| while read line | |
| do | |
| updatetime+=("$line") | |
| done < <(sudo -u postgres -H -- psql -qAtX -d wiki -c "${query}") | |
| if test -f "$file"; then | |
| rm $file | |
| fi | |
| count=0 | |
| { | |
| echo "<html><br/>" | |
| echo "<head><title></title><br/>" | |
| echo "</head><br/>" | |
| echo "<body><br/>" | |
| echo "<h1>Today's Doc Repo Changes</h1>" | |
| for i in "${name[@]}" | |
| do | |
| echo "<table style=\"font-family:Helvetica\" border=\"1\">" | |
| echo "<tr><th align="left">Page Title</th>" | |
| echo "<td>" ${title[$count]} "</td></tr>" | |
| echo "<tr><th align="left">Updated By</th>" | |
| echo "<td>" $i "</td></tr>" | |
| echo "<tr><th align="left">Update Time</th>" | |
| echo "<td>" ${updatetime[$count]} "</td></tr>" | |
| echo "<tr><th align="left">Page Path</th>" | |
| echo "<td><a href=\"https://<your server address & port>/"${path[$count]}"\">" | |
| echo ${path[$count]} "</a></td></tr>" | |
| echo "</table><br>" | |
| echo "<br/>" | |
| let count++ | |
| done | |
| echo "</body><br/>" | |
| echo "</html><br/>" | |
| } >>$file | |
| echo $count " Items found." | |
| if [ ${#name[@]} -ge 1 ]; then | |
| mail \ | |
| -a "From: helper@shapeshift.one" \ | |
| -a "MIME-Version: 1.0" \ | |
| -a "Content-Type: text/html" \ | |
| -s "[REPO] Recent Changes" \ | |
| $email \ | |
| <$file | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment