Automating Periodic SSH Login Checks with Jenkins and Expect
This guide explains how to use a Jenkins‑triggered shell script with Expect to regularly log into multiple remote VMs, record results, allow users to add hostnames, and commit changes to a Git repository for automated DevOps operations.
Background: The goal is to periodically batch‑login to remote virtual machines, perform specified operations, and support users adding new hostnames.
Requirements: automatic periodic execution, clear login test result output, ability to add hostnames to the check list, and user notification after execution, all using Jenkins without additional web pages.
Implementation steps: maintain a hostname list in a file, use a Jenkins job to add new hostnames (grep to avoid duplicates), commit the updated file to a Git repository, and schedule the script for regular runs.
Key techniques:
Use expect to automate interactive SSH login; install it with sudo yum install expect .
Utilize Bash arrays to read the file, perform logins, record failures, and display results.
When pushing new hostnames, set the remote URL to https://${USERNAME}:${PASSWORD}@git.company.com/scm/vmm.git or [email protected]:scm/vmm.git , with an SSH key pre‑configured on the execution machine.
The script archives results; an example output is shown below:
#####################################################
######### VM login check via SSH results ############
#####################################################
# #
# Compelted (success) 14/16 (total) login vm check. #
# #
# Below 2 host(s) login faied, need to check. #
# #
abc.company.com
xyz.company.com
# #
#####################################################Conclusion emphasizes the importance of understanding underlying principles rather than merely mastering tools, encouraging deep learning of operating systems, shell scripting, and programming languages for sustainable DevOps practice.
DevOps Engineer
DevOps engineer, Pythonista and FOSS contributor. Created cpp-linter, commit-check, etc.; contributed to PyPA.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.