I've script which is connecting to remote host via SSH, creates temporary file and executing the following command:Calling system(mysql --database=information_schema --host=localhost < /tmp/drush_1JAjtt)Each time it's creating different file (pattern: drush_xxxxxx).I've tried couple of times manually running on the remote:tail -f /tmp/drush_*but my connection is too slow and most of the time I've end up with the error:tail: cannot open `/tmp/drush_*' for reading: No such file or directoryIs there any trick accessing such file straight after it's being created to show it's content?
How to access temporary file straight after creation?
linux;command line;files;tmp
If the file is created for enough short amount of time, you can run the following command on separate terminal before running the script:while true; do cat /tmp/drush_* 2>/dev/null && break; doneWhere /tmp/drush_* is your pattern. The advantage is that it's quick and you don't have to install any external tools (if you don't have e.g. admin/root permissions).Please note that using inotifywatch (from inotify-tools) tool won't work in this particular case, because the file is created after the watches have been placed and the change will not be detected. Read more: Why inotify doesn't print list of changed files?But still you can use inotifywait tool which efficiently waits for changes to files using Linux's inotify interface.Here is the simple example:inotifywait -m --format %e %f /tmpAnd example to show the content of newly created files in /tmp:inotifywait -m --format %f /tmp | grep --line-buffered ^drush | xargs -L1 -I% cat /tmp/% 2> /dev/nullAdd sudo before cat if necessary. Change /tmp and drush to your suitable values.