Skip to content

FEATURE REQUEST: In follow-mode, detect and respond to file being deleted. #34

Description

@HippoPerson

In follow-mode, it would be useful and helpful for there to be an optional setting which if set, would cause the deletion of the tailed file to be detected and responded to via the logic in the following pseudo-code, or something similar:

IF most detects that the tailed file has been deleted
THEN
    * an appropriate message such as "file <filename> has disappeared" is shown
    * LOOP until file reappears
        ** sleep a short time
    * END LOOP
    * blank the most screen (or also it's OK not to perform this blanking step)
    * show a message such as "file <filename> has reappeared"
    * start tailing the file again
ENDIF

An alternative could instead be the following logic:

IF most detects that the tailed file has been deleted
THEN
    * the most program then exits with a special, unique, non-standard exit code
ENDIF

In this second, alternative scenario, a wrapper script for running most that's similar to the following example could then be utilized to keep re-trying most if the file disappears.

#!/bin/bash
if [[ $# -gt 0 ]]
then
   file="${1}"
   shift
else
   echo "missing file name"
   exit 1
fi
rc=0
while true
do
    most -F "${file}"
    rc=$?
    if [[ ${rc} == xxx ]]  # where "xxx" is the special non-standard exit code
    then
       echo "${file} has disappeared"
       until [[ -r ${file} ]]
       do
           sleep 1
       done
       echo "${file} has reappeared"
       continue
    fi
    break
done
exit ${rc}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions