The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 622     Votes:  7     ✅ Solution
Tags: command-line   bash   yad  
Link: 🔍 See Original Answer on Ask Ubuntu ⧉ 🔗

URL: https://askubuntu.com/q/1144592
Title: What does `LOGFILE=${1:-/var/log/syslog}` do?
ID: /2019/05/19/What-does-_LOGFILE___1_-_var_log_syslog__-do_
Created: May 19, 2019    Edited:  February 12, 2022
Upload: September 15, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


The command: LOGFILE=${1:-/var/log/syslog} is shorthand for:

if [[ "$1" == "" ]]               # if parameter 1 is blank
then
    LOGFILE="/var/log/syslog"     # LOGFILE set to /var/log/syslog
else
    LOGFILE="$1"                  # LOGFILE set to parameter 1
fi

If parameter 1 is not passed you see:

yad-logfile 1.png

If you pass paraemeter 1:

journalctl -b > /tmp/messages
yad-logfile /tmp/messages

you see:

yad-logfile 2.png


The original code in question link was modified:

#!/bin/bash

# NAME: yad-logfile
# DATE: May 19, 2019.

# From: https://sourceforge.net/p/yad-dialog/wiki/LogViewer/

# This script demonstrates new features of list dialog. Script displays content
# of specified log file and mark some special strings: with word "kernel" by
# setting italic font, with word "error" by light yellow background and with
# word "warn" by pink background 

LOGFILE=${1:-/var/log/syslog}

 PARSER='{font=""; color="#FFFFFF"}; \
/CRON/   {font="italic"}; \
/smartd/ {color="#FFF4B8"}; \
/upower/ {color="#FFD0D8"}; \
OFS="\n" {print $1 " " $2, $3, $4, substr($5,0,index($5,":")-1), \
substr($0,index($0,$6)), font, color; fflush()}'

cat $LOGFILE | awk "$PARSER" | \
yad --title="Log viewer" --window-icon=logviewer \
    --button=gtk-close --geometry 600x350 \
    --list --text="Content of $LOGFILE" \
    --column Date --column Time --column Host \
    --column Tag --column Message:TIP \
    --column @font@ --column @back@

exit $?
⇧ How can I increase screen resolution? Set CPU temperature throttle threshold on Ubuntu/Thinkpad  ⇩