#!/bin/bash# Use last -F to get detailed login information, grep for "logged" to filter relevant lineslast -F | grep logged | while read -r line; do # Extract username, login time, logout time, and duration # Adjust the awk command according to your specific output format username=$(echo "$line" | awk '{print $1}') login_time=$(echo "$line" | awk '{print $5, $6, $7, $8}') logout_time=$(echo "$line" | awk '{print $10, $11, $12, $13}') # Use jq to format the extracted data into JSON # Note: jq arguments must be passed as strings jq -n \ --arg user "$username" \ --arg login "$login_time" \ --arg logout "$logout_time" \ '{username: $user, login_time: $login, logout_time: $logout}'done
[[inputs.exec]] commands = ["/usr/local/bin/logonSessions.sh"] interval = "60s" data_format = "json" json_string_fields = ["username", "login_time", "logout_time"] name_override = "logon_sessions" [inputs.exec.tags] source = "logon_script"