1838469 Members
2844 Online
110126 Solutions
New Discussion

symbolic link script

 
Carol Crose
New Member

symbolic link script

Does anyone have a script that finds all files with symbolic links containing modification dates exceeding the current date (dated in the future) and sets the date to the current date?

This is on an hp-ux 11.11 system.

Thank you,
Carol
6 REPLIES 6
Rodney Hills
Honored Contributor

Re: symbolic link script

Carol,

Would a simple find command do it?

find /path -type l -mtime +1 -exec touch {} \;

-- Rod Hills
There be dragons...
Carol Crose
New Member

Re: symbolic link script

Rod,
The touch command doesn't work on sym links and the -mtime +1 would find files more than 1 day old, but not 1 day in the future.

But thanks so much for your input. I do appreciate it.

Carol
Rodney Hills
Honored Contributor

Re: symbolic link script

Carol,

How about this perl script-

open(INP,"find /path -type l -print|");
$now=time();
while() {
@a=lstat($_);
next if $a[8] > $now;
$real=readlink($_);
unlink $_;
symlink($real,$_);
print "Updated $_ to $real\n";
}
close(INP);

This will look at symbolic link files, look at the last access time of the link file itself and compare to the current date.
Since you can't touch a link, just remove it and recreate it.

Hope this helps...

-- Rod Hills
There be dragons...
Chris Lonergan
Advisor

Re: symbolic link script

Hi

I don't have a script, but suggest that it could be done fairly easily using perl.

Chris
Ralph Grothe
Honored Contributor

Re: symbolic link script

@ Rodney,

why not use Perl's File::Find module? (meanwhile it is part of the standard suite of modules).
Even if you're unsure how to write the callback function yourself, Perl can help you with its find2perl converter.
At the shell just try something like:

e.g.

find2perl /etc -type l > my_link_renewer.pl

To place further tests of mtimes and your unlink(), and symlink() calls in there should be straight forward.

Btw. always test opens for success, because with the pipe appended Perl is forking off a child, and connecting STDIN and STDOUT handles for the parent to read and the child to write.
Apart from this she was asking for the mtime not the atime.
When I have a look at the POD of stat() it should be in the 9th returned list element,
so something like

next unless ($now > (lstat $_)[9] && -l _);

looks more appropriate to me.




Madness, thy name is system administration
Carol Crose
New Member

Re: symbolic link script

Rodney, Ralph and Chris,

I would like to thank you for your help. The action I actually took to solve my symbolic link date problem was to use a script from Eric Herberholz from HP Tech Support below. It worked! Thanks so much for all your responses...I appreciate it!

Carol

#!/usr/bin/sh
# unsupported script
find / -type l -exec ls -ld {} \; | awk '{
printf("rm %s;ln -s %s %s\n",$(NF-2),$(NF),$(NF-2));
}' >/tmp/doit
-------------------------

Notice the "unsupported script" comment above. This script assumes that there aren't any spaces in the name of the symbolic link nor in the name of the actual file.

Look at the results in /tmp/doit and then decide if it has acurately captured the commands need to remove the symbolic links and recreate them. And then if it does, you could run /tmp/doit by making it executable or by running 'sh /tmp/doit'.