Automating daily tasks with shell script

Recently I wrote a shell script to automate daily tasks. I bet it saved me several hours in the course of action.

As This Xkcd strip demonstrates, it took a while to write a script. But once that was done I could not thanks automation enough.

Let me summarize the list of task we were supposed to perform on daily basis

  • Commit code and get log of commit messages
  • Store these commit messages on persistent storage
  • Periodically build an app with release configuration
  • Distribute generated .ipa file using Crashlytics to concerned parties
  • Add release notes to distributing build. (This is taken directly from stored commit messages in the first step)
  • Remove generated dYSM file from disk once build is distributed
  • Show total time spent generating ipa file (In seconds)
  • Send email to concerned parties with list of tasks accomplished

Whoaa! That's hell of a long list of tasks.
Here's how I accomplished it with shell script

Script to commit work and write log message to persistent storage

 git add .
 git commit -am "$1"
 git push origin dev
 git pc > [path_of_file_to_append_commit_message_to]
Script to make release build and distribute it through Crashlytics

 start_time = 'date +%s'
 echo "Building an app....Please hang on....."
 ipa build -s [app_name] mv [old_ipa_file_name].ipa [new_ipa_file_name].ipa   
 ipa distribute:crashlytics -c   [path_to_Crashlytics_framework] -a [API_KEY] -s  [BUILD_SECRET] -e [list_of_emails_to_distribute_this_build_to] -f [path_to_ipa_file] -n [path_to_release_notes]
 rm [path_to_dYSM_zip_file]
 echo $'Build completed. You should find an ipa file in archivesCollection folder. Please check your email for copy of recent app build'
 end_time = 'date +%s'
 echo Execution time was 'expr $end_time - $start_time' seconds.
Script to send email with updates

#!/bin/bash
$recipients = [list_of_recipients_separated_with_comma]       
cat [path_to_file_with_tasks_list] | mail -s "Tasks Completed : "$(date +'%m/%d/%Y') -c $recipients

Make sure to setup your SMTP server for MAC to make it work.

And thats's it! This is not so complicated script per say, but it did save my 10 minutes each day in compiling list of tasks and sending manual email to everyone.

Hope this will be useful for someone else too!