-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
monitor-1password-logs.sh
executable file
·41 lines (33 loc) · 1.13 KB
/
monitor-1password-logs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
echo "Starting to monitor 1Password logs..."
# Define the path to the log file.
LOG_FILE="/home/ubuntu/.config/1Password/logs/1Password_rCURRENT.log"
# Function to monitor 1Password log for a specific line.
monitor_logs_for_line() {
local search_line="$1"
local timeout="$2"
local start_time
start_time=$(date +%s)
echo "Starting to monitor 1Password logs..."
# Check if the log file exists.
if [[ ! -f "$LOG_FILE" ]]; then
echo "Error: Log file does not exist at path: $LOG_FILE" >&2
return 1
else
echo "Log file found: $LOG_FILE"
fi
# Loop until the line is found or timeout is reached.
while true; do
# Check if the current time is greater than start time + timeout.
if [[ $(($(date +%s) - start_time)) -gt timeout ]]; then
echo "Timeout reached while monitoring logs." >&2
return 1
fi
# Use grep to search for the line in the log file.
if grep -q "$search_line" "$LOG_FILE"; then
echo "Detected desired line in logs: '$search_line'"
return 0
fi
sleep 1
done
}