Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

file-content.sh - ssh script by ActiveXperts Software

file-content.sh checks the content of a file.

Use file-content.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select file-content.sh. Configure the required parameter, or press 'Load a working sample'.

In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.


file-content.sh script code

#################################################################################
# ActiveXperts Network Monitor - Shell script checks
# © 1999-2015, ActiveXperts Software B.V.
#
# For more information about ActiveXperts Network Monitor and SSH, please
# visit the online ActiveXperts Network Monitor Shell Script Guidelines at:
#   http://www.activexperts.com/support/network-monitor/online/linux/
#################################################################################
# Script
#     file-content.sh
# Description
#     Checks the used space on a disk
# Parameters
#     1) filename (string)  - Path to file
#     2) pattern (string)  - Pattern to look for
# Usage
#     file-content.sh <filename> <pattern>
# Sample
#     file-content.sh test.sh ActiveXperts
#################################################################################

#!/bin/sh

# Validate number of arguments
if [ $# -ne 2 ] ; then
  echo "UNCERTAIN: Invalid number of arguments - Usage: file-content <filename> <pattern>"
  exit 1
fi

if [ -f "$1" ] ; then
  FOUND=`cat $1 | awk 'index(tolower($0),"'"$2"'")!=0 { print "Y" ; }'`

  #Checks if the word specified is contained in the file specified
  if [[ -n $FOUND ]] ; then
    echo "SUCCESS: File $1 contains [$2] DATA:1"
  else
    echo "ERROR: File $1 does not contain [$2] DATA:0"	    
  fi
else
  echo "UNCERTAIN: File [$1] does not exist"
fi