NOTE: This Monthly Linux Tip discusses using bash and cron, more advanced Linux administrative topics. Both topics will be briefly discussed, but not explained in great depth as that falls outside the scope of this blog.
It is no secret that some tasks are more repetitive than others; this is especially true with daily administrative tasks. To handle such repetition, automation is often the answer. ArcGIS Enterprise offers several built-in tools to promote automation in repetitive workflows, such as creating an ArcGIS Server site for multiple machines. In this Monthly Linux Tip, we will explore using Linux utilities bash and cron to automate creating an ArcGIS Server site. Listed below is the table of contents we will follow:
- Why Bash?
- Using Bash with ArcGIS Server
- Combining Bash and ArcGIS Server into Cron
1. Why Bash?
Shell scripting is arguably one of the most important tools that comes pre-built with every Linux distribution. Shell scripting is so powerful because every command that can be executed in the terminal can be automated. There are several shells such as Bourne shell (sh), Z shell (zsh), korn shell (ksh) and the list goes on.
Most popularly used in Linux is Bash (Bourne Again Shell). As bash is most commonly used in Linux distributions, we will focus on this shell in today’s tip.
2. Using Bash with ArcGIS Server
Previously mentioned, ArcGIS Server comes with several tools that promotes utilizing automation. Let’s explore the following user story:
“My name is Joe and I am the system administrator for my organization. A common practice for us is to stand up several QA and development machines with ArcGIS Server installed before going into production. These environments typically last for around 3 months before they’re destroyed. Is there a way to automate ArcGIS Server installations so that I don’t have to manually do this process every time?”
In the above user story, Bash would be a great choice to get up and going with automated ArcGIS Server installations. Below, here is a simplified Bash script named createAGS.sh that Joe might use:
In a realistic scenario, this script will be more comprehensive and not make assumptions about the system (as well as a better username and password). Looking past that, we see that the install_server function is calling upon the Setup script to install. Similarly, we see that the configure_server function utilizes the createsite.sh script to create the ArcGIS Server site.
This bash script by itself can be used throughout each of Joe’s QA and development machines and eliminates manual effort. However, to take it a step further, Joe can additionally utilize cron scheduling to fully automate.
3. Combining Bash, ArcGIS Server and Cron
It is nearing the end of the three-month interval Joe earlier described and he is creating a new set of machines. Despite the createAGS.sh script he has, Joe wants a way to have this entire process fully automated after he creates the machines. This is where crontab will come in handy.
Crontab (CRON TABle) is a virtualized table in the system that can schedule repetitive tasks. System administrators mostly use this for system backups, updates, file synchronization, etc. The syntax of cron jobs are as follows:
In Joe’s case, we will create a crontab that takes advantage of the createAGS.sh script so that every 3 months, this script will run. To do this, Joe will use the command crontab -e to create a new cron job as the ArcGIS Server installation user. Below is an example of the createAGS.sh script running at 12PM on the 1st of January, April, July and October:
Realistically, the three-month interval will depend on when Joe creates the environments, but the overall syntax would look the same.
Conclusion
In this Monthly Linux tip, we went over utilizing built in Linux tools Bash and cron and how they can help automate ArcGIS Enterprise. There are several automation utilities available, so please explore what works best for your organization.
Please feel free to leave a comment on this blog and what you would like to see next month. Thanks for reading this Monthly Linux Tip!
Article Discussion: