Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Real computer scientists like having a computer on their desk, else how could they read their mail?


devel / comp.unix.shell / script to run in background and log access times to a file

SubjectAuthor
* script to run in background and log access times to a fileJ. W.
+* Re: script to run in background and log access times to a fileJanis Papanagnou
|`* Re: script to run in background and log access times to a fileJ. W.
| +* Re: script to run in background and log access times to a fileKenny McCormack
| |`- Re: script to run in background and log access times to a fileJanis Papanagnou
| `* Re: script to run in background and log access times to a fileJanis Papanagnou
|  `- Re: script to run in background and log access times to a fileBit Twister
+- Re: script to run in background and log access times to a fileDavid W. Hodgins
`- Re: script to run in background and log access times to a fileBit Twister

1
script to run in background and log access times to a file

<d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5023&group=comp.unix.shell#5023

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a37:bf45:0:b0:5f1:924c:23d0 with SMTP id p66-20020a37bf45000000b005f1924c23d0mr12715669qkf.374.1647201160903;
Sun, 13 Mar 2022 12:52:40 -0700 (PDT)
X-Received: by 2002:ac8:5889:0:b0:2e1:afa2:65a9 with SMTP id
t9-20020ac85889000000b002e1afa265a9mr14219988qta.268.1647201160667; Sun, 13
Mar 2022 12:52:40 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 13 Mar 2022 12:52:40 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=104.195.199.86; posting-account=Jsi2uwoAAACZnGteOmjoPGNE1WKeRP9N
NNTP-Posting-Host: 104.195.199.86
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com>
Subject: script to run in background and log access times to a file
From: jw2.685...@gmail.com (J. W.)
Injection-Date: Sun, 13 Mar 2022 19:52:40 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 0
 by: J. W. - Sun, 13 Mar 2022 19:52 UTC

Hello, I am a user on an institutional system. Could someone point me in the right direction to a command I can execute with nohup to check last access time to a given file in the background, and write the times to a log file? Thank you!

Re: script to run in background and log access times to a file

<t0lkkk$ieo$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5024&group=comp.unix.shell#5024

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: script to run in background and log access times to a file
Date: Sun, 13 Mar 2022 21:36:35 +0100
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <t0lkkk$ieo$1@dont-email.me>
References: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 13 Mar 2022 20:36:36 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3caca4a9e35831592cd8cd33c5c65865";
logging-data="18904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MdcZE2m2qEnMbnaLEzrrT"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:y+TurabsvrwNQ6cg3/ghDD0f7DI=
In-Reply-To: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sun, 13 Mar 2022 20:36 UTC

On 13.03.2022 20:52, J. W. wrote:
> Hello, I am a user on an institutional system. Could someone point me
> in the right direction to a command I can execute with nohup to check
> last access time to a given file in the background, and write the
> times to a log file? Thank you!

It depends on what system you work on. On my Linux system there's a
tool called 'inotifywait' (use 'man inotifywait' to get details).
inotifywait - wait for changes to files using inotify

Here's an application example - but different from your case; it is
watching in a specific directory all create/delete changes of files
matching a particular file name pattern, and it displays information
about that through an alert box -, that may help you (or not):

#!/usr/bin/ksh
dir=/var/games/slashem
inotifywait -q -m -e create -e delete "${dir}" |
while read -r WHERE EVENT FILE
do
case ${FILE} in
(bon*.*.gz)
typeset -l event=${EVENT}
zenity --info --text="File '${FILE}' ${event}d\n(in ${WHERE})\n"
;;
esac
done

and with 'inotifywait' you can also watch specific files' changes
with access time events; the man page provides you with details.

If you have further questions feel free to ask.

Janis

Re: script to run in background and log access times to a file

<op.1izk9aq2a3w0dxdave@hodgins.homeip.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5025&group=comp.unix.shell#5025

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dwhodg...@nomail.afraid.org (David W. Hodgins)
Newsgroups: comp.unix.shell
Subject: Re: script to run in background and log access times to a file
Date: Sun, 13 Mar 2022 16:45:00 -0400
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <op.1izk9aq2a3w0dxdave@hodgins.homeip.net>
References: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="74013d3c3a7fcea13f93989b74a28ed3";
logging-data="30042"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/I4kYhff8x7stN6nXpu5L9y5oeyCukj4U="
User-Agent: Opera Mail/12.16 (Linux)
Cancel-Lock: sha1:ep/bUTJTD2UAn2BZGZ5DzwNJU3o=
 by: David W. Hodgins - Sun, 13 Mar 2022 20:45 UTC

On Sun, 13 Mar 2022 15:52:40 -0400, J. W. <jw2.685452@gmail.com> wrote:

> Hello, I am a user on an institutional system. Could someone point me in the right direction to a command I can execute with nohup to check last access time to a given file in the background, and write the times to a log file? Thank you!

See https://unix.stackexchange.com/questions/12247/linux-file-access-monitoring

Regards, Dave Hodgins

Re: script to run in background and log access times to a file

<slrnt2snlt.1ie5o.BitTwister@wb.home.test>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5026&group=comp.unix.shell#5026

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: BitTwis...@mouse-potato.com (Bit Twister)
Newsgroups: comp.unix.shell
Subject: Re: script to run in background and log access times to a file
Date: Sun, 13 Mar 2022 16:14:31 -0500
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <slrnt2snlt.1ie5o.BitTwister@wb.home.test>
References: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com>
Injection-Info: reader02.eternal-september.org; posting-host="1f269cef2f7c9328af39f912069a4e1a";
logging-data="3353"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bUZ2GE4x9GIlzuyaeG703iOid3J7DMlo="
User-Agent: slrn/pre1.0.4-6 (Linux)
Cancel-Lock: sha1:yiCl3n0cBPgP/9yzCDvqpiYXqBQ=
 by: Bit Twister - Sun, 13 Mar 2022 21:14 UTC

On Sun, 13 Mar 2022 12:52:40 -0700 (PDT), J. W. wrote:
> Hello, I am a user on an institutional system. Could someone point me in the right direction to a command I can execute with nohup to check last access time to a given file in the background, and write the times to a log file? Thank you!

redirection operator seems appropriate for the append requirement.

It always helps if you provide information about your system, desktop, operating
system, hardware when posting questions. That allows any subject matter expert to
give you more detailed information in a reply.

File information can be found with stat.
homework:
man stat
man cut
man grep
man tail

as for writing to a log file, it depends on script/shell/app being used.

Do bookmark the following url
https://www.google.com/advanced_search

Example bash script
----8<----8<----8<----8<--cut below this line--8<----8<----8<
#!/bin/bash
#****************************************************************
#* script_name_here - script to fetch access time of a file
#****************************************************************
set -u # Show usage of unset variables as an error to help catch typos.

_in_fn=/somewhere/FILENAME_OF_INTEREST_HERE
_log_fn="$HOME/DATA/access.log"

#*************************************************************
#* not really needed/required because >> redirection operator
#* will create file if it does not exist.
#*************************************************************
mkdir --parents $HOME/DATA/
touch $_log_fn # creates initial empty file if does not exist

echo "\
stat %x $_in_fn | grep Access: | tail -1
" >> $_log_fn

#**************** end of bash script ********************************
----8<----8<----8<----8<--cut above this line--8<----8<----8<

Re: script to run in background and log access times to a file

<0ed022ce-2770-4b58-b937-3e3bbee21dadn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5036&group=comp.unix.shell#5036

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:5284:b0:42c:8d98:53ee with SMTP id kj4-20020a056214528400b0042c8d9853eemr21493034qvb.114.1647355431723;
Tue, 15 Mar 2022 07:43:51 -0700 (PDT)
X-Received: by 2002:a05:620a:ec5:b0:67b:309e:a540 with SMTP id
x5-20020a05620a0ec500b0067b309ea540mr18127720qkm.488.1647355431563; Tue, 15
Mar 2022 07:43:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 15 Mar 2022 07:43:51 -0700 (PDT)
In-Reply-To: <t0lkkk$ieo$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=132.206.141.249; posting-account=Jsi2uwoAAACZnGteOmjoPGNE1WKeRP9N
NNTP-Posting-Host: 132.206.141.249
References: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com> <t0lkkk$ieo$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0ed022ce-2770-4b58-b937-3e3bbee21dadn@googlegroups.com>
Subject: Re: script to run in background and log access times to a file
From: jw2.685...@gmail.com (J. W.)
Injection-Date: Tue, 15 Mar 2022 14:43:51 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 52
 by: J. W. - Tue, 15 Mar 2022 14:43 UTC

On Sunday, March 13, 2022 at 4:36:42 PM UTC-4, Janis Papanagnou wrote:
> On 13.03.2022 20:52, J. W. wrote:
> > Hello, I am a user on an institutional system. Could someone point me
> > in the right direction to a command I can execute with nohup to check
> > last access time to a given file in the background, and write the
> > times to a log file? Thank you!
> It depends on what system you work on. On my Linux system there's a
> tool called 'inotifywait' (use 'man inotifywait' to get details).
> inotifywait - wait for changes to files using inotify
>
> Here's an application example - but different from your case; it is
> watching in a specific directory all create/delete changes of files
> matching a particular file name pattern, and it displays information
> about that through an alert box -, that may help you (or not):
>
> #!/usr/bin/ksh
> dir=/var/games/slashem
> inotifywait -q -m -e create -e delete "${dir}" |
> while read -r WHERE EVENT FILE
> do
> case ${FILE} in
> (bon*.*.gz)
> typeset -l event=${EVENT}
> zenity --info --text="File '${FILE}' ${event}d\n(in ${WHERE})\n"
> ;;
> esac
> done
>
> and with 'inotifywait' you can also watch specific files' changes
> with access time events; the man page provides you with details.
>
> If you have further questions feel free to ask.
>
> Janis

Thank you very much Janis. I ended up having to do something I could understand from scratch myself (and I know very little), but it seems to have worked. I wrote this script into a file, made it executable, then ran it from a detached tmux session and it is still going. Since I only need very basic information on time access, do you think this will work just as well as your expert solution? It seemed clunky to have to use a temporary file instead of uniq'ing in place, but it all seems to work.

while true
do
ls -lu ~/myfile | cut -d ' ' -f 6-9 >> ~/sm_log
uniq ~/sm_log > ~/sm_log_t
mv ~/sm_log_t ~/sm_log
sleep 120
done

Re: script to run in background and log access times to a file

<t0qaml$1lpkf$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5037&group=comp.unix.shell#5037

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: script to run in background and log access times to a file
Date: Tue, 15 Mar 2022 15:17:41 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t0qaml$1lpkf$1@news.xmission.com>
References: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com> <t0lkkk$ieo$1@dont-email.me> <0ed022ce-2770-4b58-b937-3e3bbee21dadn@googlegroups.com>
Injection-Date: Tue, 15 Mar 2022 15:17:41 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1762959"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 15 Mar 2022 15:17 UTC

In article <0ed022ce-2770-4b58-b937-3e3bbee21dadn@googlegroups.com>,
J. W. <jw2.685452@gmail.com> wrote:
....
>Thank you very much Janis. I ended up having to do something I could
>understand from scratch myself (and I know very little), but it seems
>to have worked. I wrote this script ...

Although it may look daunting at first, inotifywait (and related tools) is
really worth learning. It solves a lot of these sorts of problems, where
the "normal" way of doing it is poll-sleep-repeat. So, I would recommend
that you install it and learn it.

Janis's script uses the "-m" (monitor) option in inotifywait, which is
kinda cool, but is usually not the best way to go at it. My scripts
usually take the form of:

while :;do
inotifywait ...
do stuff
done

That is, I just use inotifywait to wait until something happens, then I do
my own code once it has happened. I recommend that you do likewise - that
you re-write your script to use inotifywait (without -m) and use the
experience to ease yourself into learning about it.

Note also that there is a tool called inotify-hookable, that is actually a
Perl script, that sort of automates this process. It combines the
functionality of inotifywait's "-m" option with the idea of "Run some
user-specified code whenever the event(s) happen". I'd install and play
with that as well.

># Clunky script follows...
>while true
>do
> ls -lu ~/myfile | cut -d ' ' -f 6-9 >> ~/sm_log
> uniq ~/sm_log > ~/sm_log_t
> mv ~/sm_log_t ~/sm_log
> sleep 120
>done

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/IceCream

Re: script to run in background and log access times to a file

<t0qatu$evh$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5038&group=comp.unix.shell#5038

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: script to run in background and log access times to a file
Date: Tue, 15 Mar 2022 16:21:34 +0100
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <t0qatu$evh$1@dont-email.me>
References: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com>
<t0lkkk$ieo$1@dont-email.me>
<0ed022ce-2770-4b58-b937-3e3bbee21dadn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 15 Mar 2022 15:21:34 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5eea70834bdd3c5def979f9d1378336d";
logging-data="15345"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+H1s1d3fdecGwR9tVe8JtV"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:RW875lJXMNmaYGitxmPskmm4yzU=
In-Reply-To: <0ed022ce-2770-4b58-b937-3e3bbee21dadn@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Tue, 15 Mar 2022 15:21 UTC

On 15.03.2022 15:43, J. W. wrote:
> On Sunday, March 13, 2022 at 4:36:42 PM UTC-4, Janis Papanagnou wrote:
>> On 13.03.2022 20:52, J. W. wrote:
>>> Hello, I am a user on an institutional system. Could someone point me
>>> in the right direction to a command I can execute with nohup to check
>>> last access time to a given file in the background, and write the
>>> times to a log file? Thank you!
>> It depends on what system you work on. On my Linux system there's a
>> tool called 'inotifywait' (use 'man inotifywait' to get details).
>> inotifywait - wait for changes to files using inotify
>>
>> Here's an application example - but different from your case; it is
>> watching in a specific directory all create/delete changes of files
>> matching a particular file name pattern, and it displays information
>> about that through an alert box -, that may help you (or not):
>>
>> #!/usr/bin/ksh
>> dir=/var/games/slashem
>> inotifywait -q -m -e create -e delete "${dir}" |
>> while read -r WHERE EVENT FILE
>> do
>> case ${FILE} in
>> (bon*.*.gz)
>> typeset -l event=${EVENT}
>> zenity --info --text="File '${FILE}' ${event}d\n(in ${WHERE})\n"
>> ;;
>> esac
>> done
>>
>> and with 'inotifywait' you can also watch specific files' changes
>> with access time events; the man page provides you with details.
>>
>> If you have further questions feel free to ask.
>>
>> Janis
>
> Thank you very much Janis. I ended up having to do something I could
> understand from scratch myself (and I know very little), but it seems to
> have worked. I wrote this script into a file, made it executable, then
> ran it from a detached tmux session and it is still going. Since I only
> need very basic information on time access, do you think this will work
> just as well as your expert solution? It seemed clunky to have to use a
> temporary file instead of uniq'ing in place, but it all seems to work.

There's certainly some comments worth regarding your script below. But
I would first make sure whether there are better options available on
your system. Since _if_ you have the tool I mentioned ('inotifywait')
then a solution to check the events for a file might be as simple as

inotifywait -q -m --timefmt '%F %T' --format '%T %e %w' your_file |
tee your_file.log

(Note: I didn't redirect the output to your logfile directly just to
see also on the terminal what will be logged. Change that as desired.)

This tool has the advantage that you immediately get a notification
when the file attributes change (as opposed to implementing a "busy
wait" loop for 2 minutes, unnecessarily fetching the same info many
times, just to clean that up again.).

>
> while true
> do
> ls -lu ~/myfile | cut -d ' ' -f 6-9 >> ~/sm_log

The 'ls' default date format is unreliable if you want to parse it.

You can use the 'stat' command to obtain the infos about the file.

> uniq ~/sm_log > ~/sm_log_t

I'd compare the 'stat' result to the previous result; no temporaries.

> mv ~/sm_log_t ~/sm_log
> sleep 120

Waiting and time-triggered polling is rarely a good solution.

> done
>

Janis

Re: script to run in background and log access times to a file

<t0qbc2$ij9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5039&group=comp.unix.shell#5039

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: script to run in background and log access times to a file
Date: Tue, 15 Mar 2022 16:29:05 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <t0qbc2$ij9$1@dont-email.me>
References: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com>
<t0lkkk$ieo$1@dont-email.me>
<0ed022ce-2770-4b58-b937-3e3bbee21dadn@googlegroups.com>
<t0qaml$1lpkf$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 15 Mar 2022 15:29:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5eea70834bdd3c5def979f9d1378336d";
logging-data="19049"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NgKHrJRF9gWaNRzO9U6pB"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:zSnae9jTMlwrde6t6CveiiriGtU=
In-Reply-To: <t0qaml$1lpkf$1@news.xmission.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Tue, 15 Mar 2022 15:29 UTC

On 15.03.2022 16:17, Kenny McCormack wrote:
> In article <0ed022ce-2770-4b58-b937-3e3bbee21dadn@googlegroups.com>,
> J. W. <jw2.685452@gmail.com> wrote:
> ...
>> Thank you very much Janis. I ended up having to do something I could
>> understand from scratch myself (and I know very little), but it seems
>> to have worked. I wrote this script ...
>
> Although it may look daunting at first, inotifywait (and related tools) is
> really worth learning. It solves a lot of these sorts of problems, where
> the "normal" way of doing it is poll-sleep-repeat. So, I would recommend
> that you install it and learn it.
>
> Janis's script uses the "-m" (monitor) option in inotifywait, which is
> kinda cool, but is usually not the best way to go at it.

It depends on what you intend to do. In my sample code the poll was what
I needed. And I read the OP's demand that the "control structure" would
also match for his case.

The logic you applied below resembles the select() code pattern (which
certainly has its own field if use cases).

I would use this pattern if (for example) I have an exit condition to
be triggered at some point (e.g. a target date is reached, a number of
interesting events reached some threshold, etc.).

Janis

> My scripts
> usually take the form of:
>
> while :;do
> inotifywait ...
> do stuff
> done
>
> That is, I just use inotifywait to wait until something happens, then I do
> my own code once it has happened. I recommend that you do likewise - that
> you re-write your script to use inotifywait (without -m) and use the
> experience to ease yourself into learning about it.
>
> Note also that there is a tool called inotify-hookable, that is actually a
> Perl script, that sort of automates this process. It combines the
> functionality of inotifywait's "-m" option with the idea of "Run some
> user-specified code whenever the event(s) happen". I'd install and play
> with that as well.
>
>> # Clunky script follows...
>> while true
>> do
>> ls -lu ~/myfile | cut -d ' ' -f 6-9 >> ~/sm_log
>> uniq ~/sm_log > ~/sm_log_t
>> mv ~/sm_log_t ~/sm_log
>> sleep 120
>> done
>

Re: script to run in background and log access times to a file

<slrnt324nm.avh7.BitTwister@wb.home.test>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5041&group=comp.unix.shell#5041

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: BitTwis...@mouse-potato.com (Bit Twister)
Newsgroups: comp.unix.shell
Subject: Re: script to run in background and log access times to a file
Date: Tue, 15 Mar 2022 17:28:06 -0500
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <slrnt324nm.avh7.BitTwister@wb.home.test>
References: <d9441291-491e-4d5c-9b1c-5866ee268d5dn@googlegroups.com>
<t0lkkk$ieo$1@dont-email.me>
<0ed022ce-2770-4b58-b937-3e3bbee21dadn@googlegroups.com>
<t0qatu$evh$1@dont-email.me>
Injection-Info: reader02.eternal-september.org; posting-host="400245ba1ffe1da45758c1c4671a3324";
logging-data="32646"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fd+7j32BeWXLVQYeJW5qSSLcu/UWPd7M="
User-Agent: slrn/pre1.0.4-6 (Linux)
Cancel-Lock: sha1:E88sW9kc9E36Iu68rYNGv2SBv8A=
 by: Bit Twister - Tue, 15 Mar 2022 22:28 UTC

On Tue, 15 Mar 2022 16:21:34 +0100, Janis Papanagnou wrote:
> On 15.03.2022 15:43, J. W. wrote:
>> On Sunday, March 13, 2022 at 4:36:42 PM UTC-4, Janis Papanagnou wrote:
>>> On 13.03.2022 20:52, J. W. wrote:
>>>> Hello, I am a user on an institutional system. Could someone point me
>>>> in the right direction to a command I can execute with nohup to check
>>>> last access time to a given file in the background, and write the
>>>> times to a log file? Thank you!
>>> It depends on what system you work on. On my Linux system there's a
>>> tool called 'inotifywait' (use 'man inotifywait' to get details).
>>> inotifywait - wait for changes to files using inotify
>>>
>>> Here's an application example - but different from your case; it is
>>> watching in a specific directory all create/delete changes of files
>>> matching a particular file name pattern, and it displays information
>>> about that through an alert box -, that may help you (or not):
>>>
>>> #!/usr/bin/ksh
>>> dir=/var/games/slashem
>>> inotifywait -q -m -e create -e delete "${dir}" |
>>> while read -r WHERE EVENT FILE
>>> do
>>> case ${FILE} in
>>> (bon*.*.gz)
>>> typeset -l event=${EVENT}
>>> zenity --info --text="File '${FILE}' ${event}d\n(in ${WHERE})\n"
>>> ;;
>>> esac
>>> done
>>>
>>> and with 'inotifywait' you can also watch specific files' changes
>>> with access time events; the man page provides you with details.
>>>
>>> If you have further questions feel free to ask.
>>>
>>> Janis
>>
>> Thank you very much Janis. I ended up having to do something I could
>> understand from scratch myself (and I know very little), but it seems to
>> have worked. I wrote this script into a file, made it executable, then
>> ran it from a detached tmux session and it is still going. Since I only
>> need very basic information on time access, do you think this will work
>> just as well as your expert solution? It seemed clunky to have to use a
>> temporary file instead of uniq'ing in place, but it all seems to work.
>
> There's certainly some comments worth regarding your script below. But
> I would first make sure whether there are better options available on
> your system. Since _if_ you have the tool I mentioned ('inotifywait')
> then a solution to check the events for a file might be as simple as
>
> inotifywait -q -m --timefmt '%F %T' --format '%T %e %w' your_file |
> tee your_file.log

I find using "script" more productive than tee. Usually as simple as
script -c script_of_interest_here log_fn_here
To troubleshoot I use
script -c "bash -x ; script_of_interest_here" log_fn_here

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor