#!/bin/sh
set -eu

lines=${1:-200}
case "$lines" in
    *[!0-9]*|'')
        echo "日志行数必须是正整数" >&2
        exit 2
        ;;
esac

if [ -d /run/systemd/system ] && command -v journalctl >/dev/null 2>&1; then
    exec journalctl -u laotie-remote-ssh-agent.service -n "$lines" --no-pager
fi

log_file=/var/log/laotie-remote-ssh-agent/laotie-remote-ssh-agent.log
if [ -f "$log_file" ]; then
    exec tail -n "$lines" "$log_file"
fi

echo "未找到节点日志" >&2
exit 1
