Creating conditional symlink

Hi All,
Is there any way to create a symlink that will point to last 1000 line of a log file. My symlink will always point to "tail -1000 logfile".

This can be achieved by writing a script and scheduling with high frequency, but I am looking for some other alternatives.

Please let me know if there is any way to do so.

Thanks in advance.

A symlink has to point to a physical file if you want it to return a file descriptor on open.
So, what you are asking is interesting but does not make sense to me.

Rather than you telling us how to do it, please tell us what you are trying to accomplish.

Do you know about

tail -f
1 Like

I am looking for a way to create a symlink which will point to last 1000 lines of a logfile. The link will dynamically point to the last 1000 lines always.

My log file is huge and I am only interested to see what happened recently.

Use an alias.

1 Like

Thanks.

Alias will help to get the last 1000 lines dynamically. I am planning to expose this file using web server for external users to read. In this case will alias be helpful?

If there is any other approach please suggest.

May a named pipe?

Create a named pipe:
mkfifo /tmp/watch_log

Point the tail command to it and background it:
tail -f -n1000 logfile > /tmp/watch_log &

Watch it using the cat command:
cat /tmp/watch_log
1 Like

A symlink points to a file. It can't do anything else.

Hi, I am wondering if there is a way to create 'conditional symlinks' on a GNU/linux or unix system. I know this has been brought up already several times.. (I wanted to put some links but I dont have 5 posts yet..)

From wikipedia

However I haven't seen any solutions.

I have the "feeling" that it could perhaps be done by creating a special device (like in /dev). However I have no experience creating such devices. For example a small C-program could act as wrapper processing the conditionals, working as pipe stream. For example based on the hostname the stream would point to either file1 or file2, of course more complicated operations are easily possible if this basic example works.

Could someone comment if my hunch makes any sense?

Thanks.

if this is still an issue ...

just create a wrapper script that accounts for the required conditions ... sample code below just creates the symlinks in OS-specific directories ...

#! /bin/ksh
source=$1
target=$2
hosttype=$(uname)

case $hosttype in 
      Linux) ln -s $source /dir1/$target ;;
      HP-UX) ln -s $source /dir2/$target ;;
      AIX) ln -s $source /dir3/$target ;;
      Solaris) ln -s $source /dir4/$target ;;
esac

exit 0

case