Re: [Dorset] stdout and stderr redirection weirdness

2021-03-08 Thread Hamish McIntyre-Bhatty
Thanks, this all worked fine and I figured out the issue - I needed to 
use Python's -u option to disable buffering.


The NAS box now logs everything to syslog so hopefully the next time 
python crashes I'll know why.


Hamish

On 18/02/2021 17:29, Hamish McIntyre-Bhatty wrote:

Thanks, this all sounds like it'll be a very good idea.

syslog is attractive, but I'm not sure this even has syslog. Or maybe I
need to turn it on, I remember hearing something about it anyway. I'll
figure it out and get back to you.

At the moment I'm adding indexes to the database so it'll have to be a
bit later on - this looks like it will take a few hours.

Hamish

On 18/02/2021 16:20, Keith Edmunds wrote:

OK, this is what I would do. Check whether logger (typically
/usr/bin/loggger) is installed on the system. If it is, create a script
that runs at boot as follows:

#!/bin/ash [if /bin/bash is available, I'd use that]

/usr/bin/logger -t xyzzy "SHELL=$SHELL"
/usr/bin/logger -t xyzzy "me=$(whoami)"
echo "test" > /tmp/me.log
/usr/bin/logger -t xyzzy "Status after file write: $?"

What that does:

  - /usr/bin/logger makes entries in syslog, so no need to worry about
writing files

  - "-t xyzzy" will tag each syslog entry with "xyzzy". Of course you can
use any string, but that allows you to 'grep xyzzy /var/log/messages'
(or wherever syslog writes)

  - we check the shell (is it really ash?)

  - we check who we are (are we really root?)

  - we try writing to a file and report the status of doing so

Just looking at your original post, the other thing I'd change is the
relative file reference. Rather than writing to ../stdout.log, just write
to /tmp/stdout.log. Better still:

python3 ./main.py --id "NAS" 2>&1 | tee /usr/bin/logger -t xyzzy

...and have it sent to syslog.

hth



OpenPGP_signature
Description: OpenPGP digital signature
-- 
  Next meeting: Online, Jitsi, Tuesday, 2021-04-06 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  http://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk


Re: [Dorset] stdout and stderr redirection weirdness

2021-02-18 Thread Hamish McIntyre-Bhatty
Thanks, this all sounds like it'll be a very good idea.

syslog is attractive, but I'm not sure this even has syslog. Or maybe I
need to turn it on, I remember hearing something about it anyway. I'll
figure it out and get back to you.

At the moment I'm adding indexes to the database so it'll have to be a
bit later on - this looks like it will take a few hours.

Hamish

On 18/02/2021 16:20, Keith Edmunds wrote:
> OK, this is what I would do. Check whether logger (typically
> /usr/bin/loggger) is installed on the system. If it is, create a script
> that runs at boot as follows:
>
> #!/bin/ash [if /bin/bash is available, I'd use that]
>
> /usr/bin/logger -t xyzzy "SHELL=$SHELL"
> /usr/bin/logger -t xyzzy "me=$(whoami)"
> echo "test" > /tmp/me.log
> /usr/bin/logger -t xyzzy "Status after file write: $?"
>
> What that does:
>
>  - /usr/bin/logger makes entries in syslog, so no need to worry about
>writing files
>
>  - "-t xyzzy" will tag each syslog entry with "xyzzy". Of course you can
>use any string, but that allows you to 'grep xyzzy /var/log/messages'
>(or wherever syslog writes)
>
>  - we check the shell (is it really ash?)
>
>  - we check who we are (are we really root?)
>
>  - we try writing to a file and report the status of doing so
>
> Just looking at your original post, the other thing I'd change is the
> relative file reference. Rather than writing to ../stdout.log, just write
> to /tmp/stdout.log. Better still:
>
> python3 ./main.py --id "NAS" 2>&1 | tee /usr/bin/logger -t xyzzy
>
> ...and have it sent to syslog.
>
> hth


signature.asc
Description: OpenPGP digital signature
-- 
  Next meeting: Online, Jitsi, Tuesday, 2021-03-02 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  http://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk


Re: [Dorset] stdout and stderr redirection weirdness

2021-02-18 Thread Keith Edmunds
OK, this is what I would do. Check whether logger (typically
/usr/bin/loggger) is installed on the system. If it is, create a script
that runs at boot as follows:

#!/bin/ash [if /bin/bash is available, I'd use that]

/usr/bin/logger -t xyzzy "SHELL=$SHELL"
/usr/bin/logger -t xyzzy "me=$(whoami)"
echo "test" > /tmp/me.log
/usr/bin/logger -t xyzzy "Status after file write: $?"

What that does:

 - /usr/bin/logger makes entries in syslog, so no need to worry about
   writing files

 - "-t xyzzy" will tag each syslog entry with "xyzzy". Of course you can
   use any string, but that allows you to 'grep xyzzy /var/log/messages'
   (or wherever syslog writes)

 - we check the shell (is it really ash?)

 - we check who we are (are we really root?)

 - we try writing to a file and report the status of doing so

Just looking at your original post, the other thing I'd change is the
relative file reference. Rather than writing to ../stdout.log, just write
to /tmp/stdout.log. Better still:

python3 ./main.py --id "NAS" 2>&1 | tee /usr/bin/logger -t xyzzy

...and have it sent to syslog.

hth
-- 
Linux Tips: https://www.tiger-computing.co.uk/category/techtips/

-- 
  Next meeting: Online, Jitsi, Tuesday, 2021-03-02 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  http://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk


Re: [Dorset] stdout and stderr redirection weirdness

2021-02-18 Thread Hamish McIntyre-Bhatty
On 18/02/2021 15:34, Keith Edmunds wrote:
>> I'm finding that during startup piping and redirecting output doesn't
>> work. This is using the ash shell from busybox.
> By "during startup" do you mean system startup or your process startup?

During system startup (that's the only way to get it running
automatically). It piggybacks of the startup scripts for the webserver.

Hamish



signature.asc
Description: OpenPGP digital signature
-- 
  Next meeting: Online, Jitsi, Tuesday, 2021-03-02 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  http://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk


Re: [Dorset] stdout and stderr redirection weirdness

2021-02-18 Thread Keith Edmunds
> I'm finding that during startup piping and redirecting output doesn't
> work. This is using the ash shell from busybox.

By "during startup" do you mean system startup or your process startup?
-- 
Linux Tips: https://www.tiger-computing.co.uk/category/techtips/

-- 
  Next meeting: Online, Jitsi, Tuesday, 2021-03-02 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  http://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk


[Dorset] stdout and stderr redirection weirdness

2021-02-18 Thread Hamish McIntyre-Bhatty
Hi all,

I have yet another query relating to the NAS box. I suspect this issue
is once again due to the weird setup and ancient software.

I'm finding that during startup piping and redirecting output doesn't
work. This is using the ash shell from busybox. I have the following in
my script:

python3 ./main.py --id "NAS" 2>&1 | tee ../stdout.log

I have also tried simple redirects with > ../stdout.log, and | cat >
../stdout.log

The file is created but always remains empty regardless of what I do. It
does work when I SSH in and run commands though. Any ideas what might be
causing this? I've never encountered this behaviour before.

Thanks,

Hamish



signature.asc
Description: OpenPGP digital signature
-- 
  Next meeting: Online, Jitsi, Tuesday, 2021-03-02 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  http://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk