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!
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!
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!
On 13.03.2022 20:52, J. W. wrote:
Hello, I am a user on an institutional system. Could someone point meIt depends on what system you work on. On my Linux system there's a
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!
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 ...
# 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
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
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 meIt depends on what system you work on. On my Linux system there's a
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!
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
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 meIt depends on what system you work on. On my Linux system there's a
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!
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
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 15:09:07 |
Calls: | 9,784 |
Calls today: | 3 |
Files: | 13,748 |
Messages: | 6,187,492 |