LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-21-2009, 10:23 AM   #1
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Rep: Reputation: 15
have i got this right (symlink new file then unsymlink after 7 days)


ok originly i asked for help converting stuff automaticly to a format my archos could understand and you guys were fantastic u showed me a acceptable way and a right way lol i must admit i got the acceptable way to work and did not dare change it but have incorperated the right way into this new script, now my archos is dead (moment of silence for a fallen friend please)............ so i brought a netbook (a samsung n110) this means i no longer have to convert things, however i found myself keeping the conversion scripts as it was handy to just go into the converted folder and copy the most recent files across rather then hunt through folders, but i also like having the folders organised.
i renembered about symlinks and have spent the last few hours googling and i think i have a working script, since there are rm commands involved and it is essentialy making copys of files i wanted some expert opinions before i make the script live

Code:
#!/bin/bash

dir=$1
cd "$dir"
for file in *.avi
do
 ln -s "$file" /home/mrgreaper/recent/"$file".avi
done

find /home/mrgreaper/recent/ -type f -mtime +7 rm
what it should do if i have it right is,
1)make a symlink of all avi files from the $dir folder ($1 is a veriable sabnzbd post processing gives) into a folder called recent
2) scan the files in there and remove the symlink for any file older then 7 days


i want the original file untouched just the symlink destroyed after 7 days

the original $dir is on another harddrive to /home/mrgreaper/recent will that cause problems
my understanding of symlinks is that they dont take up hard drive space is that right ? if so it gives it deffinate bonuses over the conversion method

special thanks to schneidz(showing me the right way) catkin(showing me a working way first) and i92guboj (explaning the difference between the right way and the working way in language i could understand) from my original archos thread, hopefully they will be as helpful here too


there is ofcourse another way i could do this using something i only now of by name, cron job and have it scan every 5 minutes for a new file ....actualy i like my script idea (i have used scripts i havent used cronjob (or inotify which im guessing would be the best way to detect new files)

man thats a long post any help greatfully recieved
 
Old 09-21-2009, 11:15 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,580
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
You ln line should read:
ln -s "$file" /home/mrgreaper/recent/"$file"

Since the .avi is in your selection list (*.avi) you'd end up with file.avi.avi if you had the .avi in your target as you indicated.
Also you don't need the quotes unless you know you'll have files with spaces in their names.

Symlinks DO take up a tiny amount of space but far less than a full copy of a file would have.
 
Old 09-21-2009, 11:48 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
In this line
Code:
find /home/mrgreaper/recent/ -type f -mtime +7 rm
  • The -type f will not find symlinks. To specify symlinks, use -type l (that's a letter l).
  • rm is not a find option and is not told which file to act on. To remove the symlink, use -exec rm {} \; or, safer until you are confident it is working as intended, -exec echo rm {} \;
 
Old 09-21-2009, 11:54 AM   #4
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
i tested the symlink part of the script.
i have hit a snag, it seems after the post processing script the avi is moved to another folder breaking the symlink.
so in the recent folder i can see the symlinks though if i click them it errors and asks if i want to delete it.
the shared folder when accessed from the netbook shows nothing

im not sure this can be fixed unless i can learn how to use the inotify command and cronjob maybe some googling later
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
daysold script - how many days old is a file lrirwin Linux - Software 5 07-12-2012 09:03 AM
removing directory having file older than 4 days irfanb146 Linux - Newbie 4 05-08-2008 12:05 PM
Tip: How to copy a symlink and its target file in a script fotoguy Programming 4 08-05-2006 04:24 PM
delete file more than 50 days christina_rules Linux - Newbie 6 05-24-2006 04:13 AM
how to download a symlink file? unix20009876 Linux - Software 9 11-16-2005 06:24 PM


All times are GMT -5. The time now is 02:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration