Watch Demo×
×

See NinjaOne in action!

By submitting this form, I accept NinjaOne's privacy policy.

Complete Script Guide: Automate Linux Install Date Retrieval

Key takeaways

  • Fetches Linux installation date: The script retrieves the installation date of a Linux system using the stat / command.
  • Integrates with NinjaOne: Optionally stores the installation date in a custom field using NinjaOne’s ninjarmm-cli tool.
  • Enhances system management: Knowing the installation date aids in scheduling maintenance and updates.
  • Universal Linux compatibility: Works across various Linux distributions.
  • Security and compliance: Helps in maintaining security by tracking system age and lifecycle.
  • Automates data recording: Offers an automated solution compared to manual methods.
  • Supports proactive IT strategies: Enables proactive management and upgrade suggestions by MSPs.
  • Requires minimal setup: Easy to implement with basic scripting knowledge and appropriate permissions.

Introduction

In the dynamic landscape of IT, maintaining and monitoring systems efficiently is crucial. A fundamental aspect of system management involves understanding the history of your machines, starting with their installation dates. This knowledge can be particularly vital for IT professionals and Managed Service Providers (MSPs) who manage a fleet of Linux servers.

Background

The script in focus is designed to fetch the installation date of a Linux system and optionally store it in a custom field. It’s a valuable tool for IT professionals and MSPs, providing insights into system age, maintenance schedules, and compliance with software lifecycle policies.

The script:

#!/usr/bin/env bash
# Description: Fetches the install date and can store it in a custom field. Based on stat / .
#
# Release Notes: Initial Release
# By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
# Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
# Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
# Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
# Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
# Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
# Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
# EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#
# Usage: [Custom Field]
# <> are required
# [] are optional
#
# Example: installdate
#  Saves the install date to the customfield named installdate
#

function GetInstallDate() {
    stat /
}

function SetCustomField() {
    /opt/NinjaRMMAgent/programdata/ninjarmm-cli "$@"
}

# When run directly without testing, the "__()" function does nothing.
test || __() { :; }

__ begin __

# Parameters
CustomField=${installDateCF:=$1}

ISO_8601='%Y-%m-%d %T %Z'
Date=$(GetInstallDate | sed 's/ Birth: //' | tail --lines=1)
InstallDate=$(date -d "${Date}" "+$ISO_8601")

echo "${InstallDate}"

if [[ -n "${CustomField}" ]]; then
    SetCustomField set "$CustomField" "$InstallDate"
fi

__ end __

 

Access over 300+ scripts in the NinjaOne Dojo

Get Access

Detailed breakdown

The script operates in a straightforward manner:

  • GetInstallDate function: This function calls stat /, which retrieves detailed information about the root directory. Since the root directory is created during installation, its metadata contains the installation date.
  • SetCustomField function: This uses the ninjarmm-cli tool to set a custom field in the NinjaOne management system, allowing for easy tracking and reporting.
  • Execution flow: The script first sets parameters and formats the installation date into a readable ISO 8601 format. It then prints this date and, if provided, stores it in a specified custom field.

Potential use cases

Imagine an MSP managing several client servers. Knowing installation dates helps in scheduling maintenance, updates, and replacements. For instance, an MSP finds a server nearing the end of its expected lifespan and proactively suggests upgrades to the client.

Comparisons

Alternatively, installation dates can be retrieved manually or via other scripting methods. However, this script’s integration with NinjaOne offers streamlined, automated data recording – a significant advantage in large-scale operations.

FAQs

  • How accurate is the installation date?
    • The date retrieved is as accurate as the creation date of the root directory, which typically coincides with system installation.
  • Can it work on any Linux distribution?
    • Yes, it uses universal Linux commands.
  • What if my system doesn’t have NinjaOne?
    • The script still functions to display the installation date; only the custom field storage feature requires NinjaOne.

Implications

Accurate knowledge of installation dates is pivotal for security and compliance. Systems running beyond their support lifecycle may pose security risks. Timely upgrades and checks, guided by installation dates, mitigate such risks.

Recommendations

When using this script:

  • Ensure its run with appropriate permissions.
  • Regularly verify the accuracy of dates, especially after significant system changes.
  • Integrate it into regular system audits for comprehensive insights.

Final thoughts

This script, especially when used in conjunction with NinjaOne, optimizes IT infrastructure management. NinjaOne’s capabilities extend beyond just recording data, offering comprehensive tools for managing IT ecosystems effectively. In a world where data-driven decisions are key, such tools are indispensable for modern IT professionals.

Next Steps

Building an efficient and effective IT team requires a centralized solution that acts as your core service deliver tool. NinjaOne enables IT teams to monitor, manage, secure, and support all their devices, wherever they are, without the need for complex on-premises infrastructure.

Learn more about NinjaOne Remote Script Deployment, check out a live tour, or start your free trial of the NinjaOne platform.

Categories:

You might also like

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).