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 directory
Is there any trick accessing such file straight after it's being created to show it's content?
Best Answer
I've ran into this problem when examining behavior of a particular application I didn't trust. The application would create and later delete its temp files. kenorb's solution is good, however using
cat
can lead to race condition( that is a file may be removed whilecat
is working, so partial data only is retrieved).A lower chance of race condition can be done with creating a hard-link to the file itself.
grep
ing and creating hard link can be combined viaawk
. Thus what I've came up with is the following;Since we're using
-e create
flag , we're only interested in temporary files that are going to be immediately created, and the output format gives us the full path to created temp file. Ignoring first two lines of output viaNR>2
. For every reported file, there will be created a hard link in form/tmp/hardlink_to_<original filename>