Back to Resources

Level Verified

Linux Monitor - File Exists Script

Created by

Level

Type

Script

Category

General

Platforms
WindowsApple iOSLinux

Problem Overview

Critical files can sometimes be moved, deleted, or corrupted without notice, leading to system failures or unexpected behavior. This script eliminates guesswork by automatically confirming whether a file is present, helping IT Professionals and MSPs catch and fix issues before they escalate.

Description

This script verifies if a file, specified through a Level Script Variable, exists on a Linux system. When the file is present, the script echoes a confirmation message; otherwise, it reports that the file is missing. The straightforward design makes it a reliable building block for your monitoring strategies.

You can configure a script-based monitor in Level to run this check on-demand whenever a particular event occurs, such as critical system actions or scheduled maintenance. Alternatively, you can create an Automation in Level with a schedule trigger to run this script regularly, ensuring continuous oversight of essential files.

Script

1#!/bin/bash
2
3# This resource is provided as a convenience for Level users. We cannot 
4# guarantee it will work in all environments. Please test before deploying 
5# to your production environment. We welcome contributions to our community 
6# library
7
8# Level Library
9# https://level.io/library/script-linux-monitor-file-exists
10
11# Specify the file path to check for existence
12file_path="{{FilePath}}"
13# -----------------------------------------------------------------------------
14
15# Check if the file exists
16if [ -f "$file_path" ]; then
17  echo "file exists: $file_path"
18else
19  echo "file not found: $file_path"
20fi
21

Use Cases

  • Checking for critical configuration files
  • Ensuring log files are available for compliance
  • Monitoring sensitive security files
  • Validating user-created scripts or backups

Recommendations

  • Test in a non-production environment before deploying widely
  • Use a script-based monitor in Level to alert if the file is missing
  • Configure an Automation in Level to run on a schedule for frequent checks
  • Update Script Variables ({{FilePath}}) accurately to avoid false positives
  • Check script output to quickly identify “file not found” messages

FAQ

  • How do I run this script through Level?
    Configure it as a resource within your Level environment, then specify the desired file path as a Script Variable.
  • Why do I need System or Root permissions?
    This script needs the ability to check any location, even those restricted to standard users, ensuring comprehensive checks.
  • What if the script cannot access the file path?
    The script will return “file not found” if it can’t confirm file presence. Verify path accuracy and permissions.
  • Can I automate any remediation steps?
    Yes. If the file is missing, pair this script with an automated workflow in Level to replace or restore it immediately.
  • Is this script suitable for large-scale deployment?
    Absolutely. Its lightweight design and easy integration make it a robust tool for broad usage across various systems.

Included with this Script:

Below is a list of what you can expect to find when importing this Script.

Script details:

The following data and settings will be imported with your script.

Script Name

Linux Monitor - File Exists

Description

This script checks for the existence of a specified file on a Linux system, outputting "file exists" or "file not found" to help monitor critical files as part of a recurring check.

Language

Bash

Timeout (In Seconds)

100

Run As

Local system

Import into Level

Related resources

Explore more automations, scripts, and policies to further enhance your IT operations.

View all resources