1

I'm running a BBS. A software I ported from DOS to Linux. Impulse BBS. I'm having problems with the message base files. The problem is, it deletes the .BRD files, for some reason, and that halts the system. And crashes the BBS. I need to figure out a way to create those .BRD files when missing. Here's a script I wrote:

#!/bin/bash

inotifywait --daemon --outfile /home/imp/imp/test.log -m /home/imp/imp/msgs -e create 
while read path action file; do
    echo "The file '$file' appeared in directory '$path' via '$action'"
    for name in /home/imp/imp/msgs/*.MIX; do
            touch "${name}.BRD"
    done
done

It doesn't appear to be working, though. It does not actually touch the .BRD file(s). These .BRD files can be 0-byte length in size. I'm using inotifywait because it seems to be the best way to address this situation. I have other scripts that utilitze inotifywait, and they suit my needs perfectly.

8
  • I doubt may of us know what these files are supposed to be, or how to create them, without you telling us what software it is that uses them. As the question currently stands, it is unclear what it is you want to achieve (apart from creating files that we know nothing about).
    – Kusalananda
    Feb 15, 2018 at 21:25
  • They can be 0-byte length files. A simple touch AGN_SYS.BRD (for example) would work. They are message base files for a BBS system.
    – ignatius
    Feb 15, 2018 at 22:56
  • 1. create (or extract from the source code / configuration files) a list of all such files that need to exist. 2. touch all files in that list.
    – cas
    Feb 16, 2018 at 0:29
  • 1
    (1) As Kusalananda says, you’ll get better answers if you ask a better question.  If it’s good enough to create zero-length file(s), you should say so in the text of your question.  Don’t explain your question in comments; edit your question to make it clearer and more complete.  And don’t force people to try to understand the code you’ve written just to figure out (i.e., guess) what you want to accomplish.  (1a) I guess that you’re saying that .BRD and .MIX files get created in pairs (e.g., foo.BRD and foo.MIX), and that sometimes,  … (Cont’d) Feb 16, 2018 at 6:05
  • 1
    You have already 2 reopen votes. Over 300 rep, also you will have a vote regarding your own questions. Good luck! I think your improvement deserves the reopen.
    – peterh
    Feb 16, 2018 at 23:46

1 Answer 1

0

Without looking too much at the inotifywait bit of your code, it looks as if the inner part of the loop touches a file based on what's in the name variable:

for name in /home/imp/imp/msgs/*.MIX; do
        touch "${name}.BRD"
done

The value of $name will be a pathname with a filename at the end that has the .MIX filename suffix.

Touching $name.BRD will create a file with a .MIX.BRD filename suffix, whereas I believe that you might want the original .MIX suffix replaced by .BRD.

This does that:

for name in /home/imp/imp/msgs/*.MIX; do
        touch "${name%.MIX}.BRD"
done

${name%.MIX} removes .MIX from the end of the value of $name.

The code probably also lacks a | at the end of the inotifywait command, to be able to feed its output into the while read loop:

#!/bin/sh

inotifywait --daemon --outfile /home/imp/imp/test.log -m /home/imp/imp/msgs -e create |
while read path action file; do
    printf 'The file "%s" appeared in directory "%s" via "%s"\n' "$file" "$path" "$action"

    for name in "$path"/*.MIX; do
            touch "${name%.MIX}.BRD"
    done
done

Here, I've also taken the liberty to change the echo to a printf (as it's outputting variable data), and of using $path in the inner for loop, which I hope is correct. The code doesn't use any special bash features, so I've changed the shell to /bin/sh as well.

Depending on how inotifywait works and what $file is and what you want to do, it may be enough to touch a file based on $file rather than looping through all files in the directory.

4
  • Awesome. Thank you. There is a problem with the code, though. On your inotifywait solution, it gives me this error: ./ren2.sh: 11: ./ren2.sh: Syntax error: Unterminated quoted string
    – ignatius
    Feb 17, 2018 at 16:14
  • @ignatius Huh. $action" was missing its initial ". I had to look at it three times before I spotted it :-) Now fixed. Thanks.
    – Kusalananda
    Feb 17, 2018 at 16:28
  • I'll test it first. If it works, then i'll accept the question as solved.
    – ignatius
    Feb 17, 2018 at 16:32
  • @ignatius Absolutely, if nobody comes with a better answer, obviously.
    – Kusalananda
    Feb 17, 2018 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.