Skip to content

Sftp watchdog

Watchdog for GAIA

The watchdog is running on the customer production SFTP servers (for those who have GAIA).

  • Script location: watch.sh on the SFTP server
  • Additional script for EW: watch_dwh.sh

The watch.sh script runs continuously. If you need to start or restart it, follow the instructions below:


Start

setsid ~/watch.sh

Restart

  1. Use ps fx to locate the process ID (PID) for watch.sh.
  2. Kill the process and its subprocesses:

bash kill -9 [process_id]

  1. Restart with:

bash setsid ~/watch.sh

Depending on the SFTP data size, startup may take a few minutes.


Watchdog Script Example

<pre><code>#!/bin/bash
#--- Variables ---
MESSAGE_BASE="a3/prod"
USER=
PASSWORD=
IP=10.100.113.200
PORT=1883

#--- Main Program ---
inotifywait -m --exclude '(/\.|/*/history|/a3ssim/tuissim)'  -e create -e modify -e moved_to -e moved_from -e delete -r /data/ftp/ftp_a3/ |
while read dir op file
do
  FDIR=$(echo $dir | cut -d '/' -f6)
  FDIRREP=$(echo $dir | cut -d '/' -f5)

  if [ "$FDIR" == "pnl" ]; then
    TO=$(echo $dir | cut -d '/' -f 5 | tr '[:lower:]' '[:upper:]')
    FILESIZE=$(stat -c%s "$dir/$file")
    mosquitto_pub -h $IP -p $PORT -u $USER -P $PASSWORD -t $MESSAGE_BASE/to/${TO:2:4}/passengerfilereceived  -m "{\"timestamp\":\"$(date +'%Y-%m-%d %H:%M:%S')\",\"filename\":\"$file\",\"filesize\":\"$FILESIZE\"}"
  elif [ "$FDIR" == "book" ]; then
    TO=$(echo $dir | cut -d '/' -f 5 | tr '[:lower:]' '[:upper:]')
    FILESIZE=$(stat -c%s "$dir/$file")
    mosquitto_pub -h $IP -p $PORT -u $USER -P $PASSWORD -t $MESSAGE_BASE/to/${TO:2:4}/rescountfilereceived  -m "{\"timestamp\":\"$(date +'%Y-%m-%d %H:%M:%S')\",\"filename\":\"$file\",\"filesize\":\"$FILESIZE\"}"
  elif [ "$FDIRREP" == "a3report" ]; then
    TO=$(echo $dir | cut -d '/' -f 4 | tr '[:lower:]' '[:upper:]')
    FILESIZE=$(stat -c%s "$dir/$file")
    mosquitto_pub -h $IP -p $PORT -u $USER -P $PASSWORD -t $MESSAGE_BASE/to/DEVIATIONREPORT/delivery  -m "{\"timestamp\":\"$(date +'%Y-%m-%d %H:%M:%S')\",\"filename\":\"$file\",\"filesize\":\"$FILESIZE\"}"
  elif [ "$FDIRREP" == "a3ssim" ]; then
    TO=$(echo $dir | cut -d '/' -f 4 | tr '[:lower:]' '[:upper:]')
    FILESIZE=$(stat -c%s "$dir/$file")
    mosquitto_pub -h $IP -p $PORT -u $USER -P $PASSWORD -t $MESSAGE_BASE/to/SSIM/delivery  -m "{\"timestamp\":\"$(date +'%Y-%m-%d %H:%M:%S')\",\"filename\":\"$file\",\"filesize\":\"$FILESIZE\"}"
  elif [ "$FDIRREP" == "a3errors" ]; then
    TO=$(echo $dir | cut -d '/' -f 4 | tr '[:lower:]' '[:upper:]')
    FILESIZE=$(stat -c%s "$dir/$file")
    mosquitto_pub -h $IP -p $PORT -u $USER -P $PASSWORD -t $MESSAGE_BASE/to/ASGERRORS/delivery  -m "{\"timestamp\":\"$(date +'%Y-%m-%d %H:%M:%S')\",\"filename\":\"$file\",\"filesize\":\"$FILESIZE\"}"
  elif [ "$FDIR" == "in" ]; then
    TO=$(echo $dir | cut -d '/' -f 5 | tr '[:lower:]' '[:upper:]')
    FILESIZE=$(stat -c%s "$dir/$file")
    mosquitto_pub -h $IP -p $PORT -u $USER -P $PASSWORD -t $MESSAGE_BASE/to/PRICESPLITFILE/delivery  -m "{\"timestamp\":\"$(date +'%Y-%m-%d %H:%M:%S')\",\"filename\":\"$file\",\"filesize\":\"$FILESIZE\"}"
  elif [ "$FDIRREP" == "a3flightclosures" ]; then
    TO=$(echo $dir | cut -d '/' -f 4 | tr '[:lower:]' '[:upper:]')
    FILESIZE=$(stat -c%s "$dir/$file")
    mosquitto_pub -h $IP -p $PORT -u $USER -P $PASSWORD -t $MESSAGE_BASE/to/FLIGHTCLOSURE/delivery  -m "{\"timestamp\":\"$(date +'%Y-%m-%d %H:%M:%S')\",\"filename\":\"$file\",\"filesize\":\"$FILESIZE\"}"
  elif [ "$FDIR" == "pool" ]; then
    TO=$(echo $dir | cut -d '/' -f 5 | tr '[:lower:]' '[:upper:]')
    FILESIZE=$(stat -c%s "$dir/$file")
    mosquitto_pub -h $IP -p $PORT -u $USER -P $PASSWORD -t $MESSAGE_BASE/to/${TO:2:4}/allotmentfiledelivered  -m "{\"timestamp\":\"$(date +'%Y-%m-%d %H:%M:%S')\",\"filename\":\"$file\",\"filesize\":\"$FILESIZE\"}"
  elif [ "$FDIR" == "specialprices" ]; then
    TO=$(echo $dir | cut -d '/' -f 5 | tr '[:lower:]' '[:upper:]')
    FILESIZE=$(stat -c%s "$dir/$file")
    mosquitto_pub -h $IP -p $PORT -u $USER -P $PASSWORD -t $MESSAGE_BASE/to/${TO:2:4}/specialpricesfiledelivered  -m "{\"timestamp\":\"$(date +'%Y-%m-%d %H:%M:%S')\",\"filename\":\"$file\",\"filesize\":\"$FILESIZE\"}"
  fi
done
</code></pre>