Here is my little script... All it does is to iterate through some folders, check for modified files, commit changes to git, but at the same time store output of git messages to be sent via email as a raport:
#!/bin/bash
enviromentName=xyz
serverName=abc
serverSize=1GB
cd /home/$enviromentName/domains/
domainsArray=(*/)
changes=0
message="Usage (max ${serverSize}): $(du -h --max-depth=0 | head -n1 | awk '{print $1;}')\n"
currentDate=$(date +%Y%m%d)
cd /home/$enviromentName/
for i in "${domainsArray[@]}"
do
cd /home/$enviromentName/domains/$i/public_html/
gitstatus=$(git status)
if echo $gitstatus | grep -v -q "nothing to commit, working directory clean"; then
message+="\n"
message+=" Git Changes made to ${i}:\n"
message+="'$gitstatus'\n"
message+="$(git add .)\n"
message+="$(git commit -m ${currentDate})\n"
message+="\n"
changes=1
fi
done
if [ "$changes" -eq "1" ]; then
#echo "Changes done"
echo -e ${message}|mail -s "${serverName} logs" marcin@citystudio.pl
fi
The output of the script looks this way:
Usage (max 1GB): 0.5G
Git Changes made to foldername/:
'On branch master Untracked files: (use "git add <file>..." to include in what will be committed) test.php nothing added to commit but untracked files present (use "git add" to track)'
[master d4d3916] 20190707 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 public_html/test.file
It looks like all line breaks of git commands output seems to be gone. How should I modify the script so the output looks like this:
Usage (max 1GB): 0.5G
Git Changes made to foldername/:
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: test.php
no changes added to commit (use "git add" and/or "git commit -a")
[master 86f39b9] 20190707
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 public_html/test.php