• echo does not display from bash script

    From pinnerite@3:633/10 to All on Saturday, May 02, 2026 20:13:04
    This is script. None of the echo lines display(?).

    #!/bin/bash

    LOGFILE="$HOME/myth_backup.log" TARGET="/media/alan/e06b3828-2ec7-493a-bfbc-dcdd04ac2fed"

    echo "Backup started at $(date)" >> "$LOGFILE"

    # Run MythTV backup
    #
    echo "Running mythconverg_backup.pl..." >> "$LOGFILE" /home/mythtv/mythconverg_backup.pl >> "$LOGFILE" 2>&1 || \
    echo "WARNING: mythconverg_backup.pl failed" >> "$LOGFILE"

    # Rsync backup
    echo "Starting rsync..." >> "$LOGFILE"

    if mountpoint -q "$TARGET"; then
    if rsync -avh --delete /home/mythtv/ "$TARGET"/ >> "$LOGFILE" 2>&1; then
    echo "Backup completed successfully at $(date)" >> "$LOGFILE"
    else
    echo "ERROR: rsync failed at $(date)" >> "$LOGFILE"
    fi
    else
    echo "ERROR: Backup target not mounted, skipping rsync" >> "$LOGFILE"
    fi

    TIA Alan

    --
    Linux Mint 21.3 kernel version 5.15.0-157-generic Cinnamon 6.0.4
    AMD Ryzen 7 7700, Radeon RX 6600, 32GB DDR5, 1TB SSD, 2TB Barracuda

    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Alan K.@3:633/10 to All on Saturday, May 02, 2026 18:21:32
    On 5/2/26 3:13 PM, pinnerite wrote:
    This is script. None of the echo lines display(?).

    #!/bin/bash

    LOGFILE="$HOME/myth_backup.log" TARGET="/media/alan/e06b3828-2ec7-493a-bfbc-dcdd04ac2fed"

    echo "Backup started at $(date)" >> "$LOGFILE"

    # Run MythTV backup
    #
    echo "Running mythconverg_backup.pl..." >> "$LOGFILE" /home/mythtv/mythconverg_backup.pl >> "$LOGFILE" 2>&1 || \
    echo "WARNING: mythconverg_backup.pl failed" >> "$LOGFILE"

    # Rsync backup
    echo "Starting rsync..." >> "$LOGFILE"

    if mountpoint -q "$TARGET"; then
    if rsync -avh --delete /home/mythtv/ "$TARGET"/ >> "$LOGFILE" 2>&1; then
    echo "Backup completed successfully at $(date)" >> "$LOGFILE"
    else
    echo "ERROR: rsync failed at $(date)" >> "$LOGFILE"
    fi
    else
    echo "ERROR: Backup target not mounted, skipping rsync" >> "$LOGFILE"
    fi

    TIA Alan

    First, how are you running this? Clicking on the shell script via Nemo, running from a
    cron job, running from a terminal window from the command line?

    I know it's stupid but put all your variables in {} ${LOGFILE} etc.

    Try shellcheck on the script. shellcheck <full path of script>
    You can capture errors >logfile.txt if it's a lot.

    --
    Mint 22.3, Thunderbird 140.10.0esr, Firefox 150.0.1
    Alan K.

    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Alan K.@3:633/10 to All on Saturday, May 02, 2026 18:24:23
    On 5/2/26 6:21 PM, Alan K. wrote:
    On 5/2/26 3:13 PM, pinnerite wrote:
    This is script. None of the echo lines display(?).

    #!/bin/bash

    LOGFILE="$HOME/myth_backup.log"
    TARGET="/media/alan/e06b3828-2ec7-493a-bfbc-dcdd04ac2fed"

    echo "Backup started at $(date)" >> "$LOGFILE"

    # Run MythTV backup
    #
    echo "Running mythconverg_backup.pl..." >> "$LOGFILE"
    /home/mythtv/mythconverg_backup.pl >> "$LOGFILE" 2>&1 || \
    echo "WARNING: mythconverg_backup.pl failed" >> "$LOGFILE"

    # Rsync backup
    echo "Starting rsync..." >> "$LOGFILE"

    if mountpoint -q "$TARGET"; then
    if rsync -avh --delete /home/mythtv/ "$TARGET"/ >> "$LOGFILE" 2>&1; then
    echo "Backup completed successfully at $(date)" >> "$LOGFILE"
    else
    echo "ERROR: rsync failed at $(date)" >> "$LOGFILE"
    fi
    else
    echo "ERROR: Backup target not mounted, skipping rsync" >> "$LOGFILE" >> fi

    TIA Alan

    First, how are you running this? Clicking on the shell script via Nemo, running from a
    cron job, running from a terminal window from the command line?

    I know it's stupid but put all your variables in {} ${LOGFILE} etc.

    Try shellcheck on the script. shellcheck <full path of script>
    You can capture errors >logfile.txt if it's a lot.

    If you're running from cron, put something like this in the script:
    30 8 * * 2-7 DISPLAY=:0 /home/alan/bin/Backup.Routines/backup-browsers.sh

    "DISPLAY=:0" seemed to get me out of an issue one day. I've had it there forever and
    I'm not quite sure why. I think it was zenity not showing output.

    --
    Mint 22.3, Thunderbird 140.10.0esr, Firefox 150.0.1
    Alan K.

    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul@3:633/10 to All on Saturday, May 02, 2026 18:51:08
    On Sat, 5/2/2026 3:13 PM, pinnerite wrote:
    This is script. None of the echo lines display(?).

    #!/bin/bash

    LOGFILE="$HOME/myth_backup.log" TARGET="/media/alan/e06b3828-2ec7-493a-bfbc-dcdd04ac2fed"

    echo "Backup started at $(date)" >> "$LOGFILE"

    # Run MythTV backup
    #
    echo "Running mythconverg_backup.pl..." >> "$LOGFILE" /home/mythtv/mythconverg_backup.pl >> "$LOGFILE" 2>&1 || \
    echo "WARNING: mythconverg_backup.pl failed" >> "$LOGFILE"

    # Rsync backup
    echo "Starting rsync..." >> "$LOGFILE"

    if mountpoint -q "$TARGET"; then
    if rsync -avh --delete /home/mythtv/ "$TARGET"/ >> "$LOGFILE" 2>&1; then
    echo "Backup completed successfully at $(date)" >> "$LOGFILE"
    else
    echo "ERROR: rsync failed at $(date)" >> "$LOGFILE"
    fi
    else
    echo "ERROR: Backup target not mounted, skipping rsync" >> "$LOGFILE"
    fi

    TIA Alan


    Let us work with this one.

    somecommand >> "$LOGFILE" 2>&1

    That says to redirect "stderr" to "stdout",
    then redirect "stdout" additively to the $LOGFILE.
    Nowhere does it mention anything about also
    including a copy on Alans Screen :-)

    How about if we try this ?

    somecommand 2>&1 | tee >> "$LOGFILE"

    Now, we would be redirecting "stderr" to "stdout",
    tee-ing the resulting "stdout" to the screen, as well as
    "redirecting that stdout additively" to $LOGFILE.

    If you need another spigot in a script, the "tee" command
    gives one more option.

    *******

    And if an AI wrote this script, there should be a comment
    near the beginning of the script such as

    # Written by Fairy.AI , Corrected by Alan

    so that all parties get credit for their work :-) This is
    to prevent the next AI from "ingesting" this post
    as being factual.

    At work, when they put me in a UNIX group, the guru there
    told me to go buy a book about Bourne Shell, as you really
    need some sort of reference text to easily suss questions
    like redirection and what order is allowed for some of
    those redirections.

    *******

    Another way to look at alan.sh , is some of the output
    options should be removed from inside the script. For example,
    in a logical sense, we could simplify some of the redirects
    inside the script like this. An outer script has one command
    in it, which handles how much redirection we want.

    ./alan.sh | tee >> "$LOGFILE"

    and then we could peel off one layer of I/O from all those lines.
    But I'm of two minds on this, as there is value in having all
    the "material" in one file, whereas with two files,

    boss.sh

    ./alan.sh | tee >> "$LOGFILE"

    we end up with two scripts, and one script calls the other
    script, and the body of the alan.sh can be a bit cleaner
    and easier to read. The alan.sh file no longer reads like the
    "Moby Dick Of Redirection" :-)

    ...
    # Run MythTV backup
    #
    echo "Running mythconverg_backup.pl..."
    /home/mythtv/mythconverg_backup.pl 2>&1 || echo "WARNING: mythconverg_backup.pl failed"

    # Rsync backup
    echo "Starting rsync..."

    if mountpoint -q "$TARGET"; then
    if rsync -avh --delete /home/mythtv/ "$TARGET"/ 2>&1; then
    echo "Backup completed successfully at $(date)"
    else
    echo "ERROR: rsync failed at $(date)"
    fi
    else
    echo "ERROR: Backup target not mounted, skipping rsync"
    fi

    Notice, if done that way, there is a possibility that manually
    running ./alan.sh and not using any external redirection, all
    the echos and errors will naturally appear right on the screen
    (but not in the logfile).

    I'm sure someone out there, knows an even more clever
    way to control the I/O and simplify this. Part of
    the job of good scripting, is making something you can
    actually read and maintain, later.

    Paul

    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Saturday, May 02, 2026 23:00:04
    On Sat, 2 May 2026 20:13:04 +0100, pinnerite wrote:

    This is script. None of the echo lines display(?).

    If you?re running it from cron or other background daemon, a more
    convenient alternative to maintaining your own logfile is to write
    your messages to the system log.

    <https://manpages.debian.org/logger(1)>

    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Mark Bourne@3:633/10 to All on Sunday, May 03, 2026 13:00:51
    Paul wrote:
    Let us work with this one.

    somecommand >> "$LOGFILE" 2>&1

    That says to redirect "stderr" to "stdout",
    then redirect "stdout" additively to the $LOGFILE.
    Nowhere does it mention anything about also
    including a copy on Alans Screen :-)

    How about if we try this ?

    somecommand 2>&1 | tee >> "$LOGFILE"

    I think you need:

    somecommand 2>&1 | tee --append "$LOGFILE"

    Otherwise you're redirecting the copy that tee sends to stdout to the
    file instead (so you still won't get any output on the terminal), and
    not giving tee any files to copy it to.

    --
    Mark.

    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From pinnerite@3:633/10 to All on Tuesday, May 05, 2026 21:39:24
    On Sun, 3 May 2026 13:00:51 +0100
    Mark Bourne <nntp.mbourne@spamgourmet.com> wrote:

    Paul wrote:
    Let us work with this one.

    somecommand >> "$LOGFILE" 2>&1

    That says to redirect "stderr" to "stdout",
    then redirect "stdout" additively to the $LOGFILE.
    Nowhere does it mention anything about also
    including a copy on Alans Screen :-)

    How about if we try this ?

    somecommand 2>&1 | tee >> "$LOGFILE"

    I think you need:

    somecommand 2>&1 | tee --append "$LOGFILE"

    Otherwise you're redirecting the copy that tee sends to stdout to the
    file instead (so you still won't get any output on the terminal), and
    not giving tee any files to copy it to.

    --
    Mark.

    I rebuilt the 13 year-old machine and while doing it the penny droped.
    The existing data data isbeing copied from the hard drive to the NVMe
    as I write. Once the teething problems are over, I will bring up some
    quick and dirty scripts to just grubby.

    Thank you for your help.
    Alan

    --
    Linux Mint 22.1 kernel version 6.8.0-84-generic Cinnamon 6.4.8
    AMD Ryzen 7 7700, Radeon RX 6600, 32GB DDR5, 2TB SSD, 2TB Barracuda

    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)