Among the many languages and tools I work with as a developer and software engineer, I probably use bash the most because it helps make life easier through scripting.
We all realize that some tasks need to be done frequently when working. I have encountered a few of these common and repetitive processes in my line of work:
- Clearing records during a database format change
- Testing if my old APIs are hampered by my changes in code
- A sequence of tasks I need to do to keep my local server up and tunnelled for testing
- Deploying and managing various test server security
- Benchmark testing
- API calls
Almost all of the processes mentioned above often include multiple tasks. For example, when I deploy and manage various test servers on separate Virtual Private Servers, I need to install and configure the firewall,
npm every time. After that, I need to create users and give them the appropriate permissions to deploy the server.
I am currently managing 7 test servers, 2 staging servers, and 2 production servers. Imagine all the repetitive tasks that need to be done for them! Fortunately,
bash comes to the rescue. I write bash scripts since I primarily operate on Linux. I have written a script that does the tasks mentioned above automatically. So, now I can simply copy my bash code to the new remote server and execute it there. Even that can be automated, as I have a bash script for copying my files to the remote server!
Below are the scripts that I mentioned, which I use to make my workflow more efficient.
Automatic Remote Server Setup
The code shown above uses a tool called scp that copies files from one place to another. We can use it to send and fetch files.
Automatic Timezone and cron Service Restart
The code shown above uses Linux commands to set the timezone and restart the cron service.
Scripting helps skip the boring parts of work and makes the experience enjoyable again. It gives us extra time to write even more scripts, templates and modules of codes, create APIs used by multiple projects, prefabs, or user-auth systems. Once tested (and when executed properly), scripts can do repeating tasks for us and free us from the mundane parts of our job.