DaemonForums  

Go Back   DaemonForums > Other Operating Systems > Other BSD and UNIX/UNIX-like

Other BSD and UNIX/UNIX-like Any other flavour of BSD or UNIX that does not have a section of its own.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 21st April 2009
wubrgamer's Avatar
wubrgamer wubrgamer is offline
Port Guard
 
Join Date: May 2008
Posts: 34
Thanked 0 Times in 0 Posts
Exclamation Delayed command?

I'd like to (on my dreamhost shared debian server):

run a delayed command, I would like make a file available for download, but only for a short amount of time (say 48 hours) and then after that, remove the file. without having to manually removing the file? (as I have been doing through an FTP client.)

is there a way to do this?

I could put into my crontab "rm /home/USERNAME/SITE/file.ext" for the date and time that I would like to remove it from my server.

But how do I do this?

What would you do?

thanks for your help!
Reply With Quote
  #2   (View Single Post)  
Old 21st April 2009
wubrgamer's Avatar
wubrgamer wubrgamer is offline
Port Guard
 
Join Date: May 2008
Posts: 34
Thanked 0 Times in 0 Posts
Default

basically, what I'm trying to do is auto-prune these files.

based on time.
Reply With Quote
  #3   (View Single Post)  
Old 21st April 2009
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 2,834
Thanked 190 Times in 160 Posts
Default

Quote:
Originally Posted by wubrgamer View Post
...I would like make a file available for download, but only for a short amount of time (say 48 hours) and then after that, remove the file. without having to manually removing the file? (as I have been doing through an FTP client.)
Set up a cron job which compares the timestamp when the file was uploaded to the current time. HINT: look at the +%s switch of date(1) which will return the number of seconds since the epoch.
  • Substracting the upload timestamp from the current timestamp will yield the number of seconds lapsed since uploading.
  • Convert 48 hours into seconds & if the lapsed time is greater than this threshold, delete the file.
  • Iterate over all files you want to make available for only a prescribed amount of time.
This is one way you might do it within a shell script. Perl or Python will have modules which can look at elapsed time as well.
Reply With Quote
  #4   (View Single Post)  
Old 21st April 2009
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,116
Thanked 182 Times in 149 Posts
Default

I haven't used Linux for a long time, but doesn't crontab -e allow you to add a task to your personal cron table?.

For an automatic pruning after 48 hours you could use the find command. The following shows a listing of all files in my home dir older then file 48 hours
Code:
$ find /home/j65nko/ -ctime 2  2 -exec ls {} \;
Change the ls to rm -f and you have your auto-prune command
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #5   (View Single Post)  
Old 21st April 2009
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,435
Thanked 214 Times in 189 Posts
Default

The cron "system" usually includes an at(1) command.

Example:
Code:
$ echo sh bin/script | at 1am tomorrow
commands will be executed using /bin/ksh
job 1240290000.c at Tue Apr 21 01:00:00 2009
$
edit:

You can also use "now +" -- specific to your needs:

$ echo rm /path/to/file | at now + 48 hours

Last edited by jggimi; 21st April 2009 at 01:16 AM.
Reply With Quote
  #6   (View Single Post)  
Old 21st April 2009
wubrgamer's Avatar
wubrgamer wubrgamer is offline
Port Guard
 
Join Date: May 2008
Posts: 34
Thanked 0 Times in 0 Posts
Default

thank you!

"at" is the PERFECT command for what I'm looking to do!

could you please help me find a primer or another place to start using "at"
Reply With Quote
  #7   (View Single Post)  
Old 21st April 2009
Albright Albright is offline
Port Guard
 
Join Date: Apr 2009
Posts: 14
Thanked 0 Times in 0 Posts
Default

at(1)?
Reply With Quote
  #8   (View Single Post)  
Old 21st April 2009
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,435
Thanked 214 Times in 189 Posts
Default

The man page is what I used; granted, it required a little experimentation before I figured it out. And, if I don't use it for six month or a year, I forget everything and have to start over, and learn it again.

At has two types of time specifications.

If you use "-t <timespec>", the "timespec" is a single format, starting with an optional century, then optional year, then month, then day, then hour, then minute, then optional seconds:

e.g: 200905012315.30 = this coming May 1, at 23:15:30. 05012316 = the same evening, 30 seconds later, at 23:16:00

The other formats that do not use -t are much more loosely defined.
Reply With Quote
  #9   (View Single Post)  
Old 21st April 2009
wubrgamer's Avatar
wubrgamer wubrgamer is offline
Port Guard
 
Join Date: May 2008
Posts: 34
Thanked 0 Times in 0 Posts
Default

Yep, *at* is pretty awesome...

thanks!
Reply With Quote
Old 22nd April 2009
phoenix's Avatar
phoenix phoenix is offline
Risen from the ashes
 
Join Date: May 2008
Posts: 699
Thanked 90 Times in 81 Posts
Default

The find command via cron is much more automated (set it once and forget about it). But at is workable.

I prefer to use at for one-off type jobs, since the at-job is removed once it has executed. Whereas cron is better for continuous-type jobs (like the one you are asking about).
__________________
Freddie

Help for FreeBSD: Handbook, FAQ, man pages, mailing lists.
Reply With Quote
Reply

Tags
bash, linux, script, shell, unix

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify the ls command? bsdnewbie999 OpenBSD General 9 16th May 2009 08:20 AM
djvu conversion (c44) command gosha Programming 5 12th December 2008 03:04 AM
avidemux2 command line roddierod FreeBSD General 1 10th November 2008 08:27 PM
pkg-get command not found whispersGhost Solaris 2 11th June 2008 01:06 PM
crypt command whispersGhost Solaris 3 9th June 2008 05:37 AM


All times are GMT. The time now is 09:34 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick