Trying to automate using Perl
Hi all
I want to create a script in Perl that automates some stuff for me. But let me start with another question. When do I do the following: Code:
$ ls -haltr The question is, is there a way to 'grep' that part and use it in a script? Thanks! More question are on the way ;) Dragonix |
Yes, you can either user link name or orignial file. A soft link is nothing but just as a shortcut of any file/dir.
Let's know what you want to grep out of this? |
Hi shivaa
thanks for your fast reply. What I eventually want to do is to copy that file to the local directory and change the name to the original file. Example: file is called test.xml schortcut is like /path/to/file/blablabla.doc So I want to copy the blablabla.doc file to my local directory, then remove the original test.xml and finally rename the copied blablabla.doc to test.xml (so that I don't have 2 test.xml files). Is that a bit clear :p? |
You can have the following:
Code:
FILE=<local filename> you need another script if you have directories also. |
Thanks!
I will give it a shot later on the day. Yeah, I know so I will make sure to use some checks like 'Are you sure to delete <filename>?'. But it's still a work in progress and it's the first time that I will be using Perl so a lot of trial and error will be involved ;) |
perldoc -f readlink
$link_target=readlink("test.xml"); # edit correction to scalar type |
Quote:
|
Suppose link is like:
Code:
lrwxrwxrwx 1 user user 24 Feb 28 15:04 test.xml -> /path/to/file/file.xml Code:
cp -p /path/to/file/file.xml /path/to/local_dir |
That's what I wrote you - in shell. And here is it in perl: http://www.java2s.com/Code/Perl/File...boliclinks.htm
|
Quote:
I'm still at the level like shivaa posted... |
pan64's code is not much tough. It can simply be understood, if you've tried:
Code:
FILE=<local filename> # Saving local finename in FILE variable |
oke, cheers!
I will give it a shot and will get back to you! |
If you are new to Perl, here are some good links
http://perldoc.perl.org/ http://www.tizag.com/perlT/index.php http://www.perlmonks.org/?node=Tutorials Incidentally, the Perl Cookbook is worth its weight in $valuable_mineral :) |
All times are GMT -5. The time now is 12:57 AM. |