Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 24th May 2006, 16:48
erez erez is offline
Junior Member
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help for writing shell script

I need some help in writing a shell script, it basically need to delete all my older files , the file name structure is like that :

song100000732200506114828.3gp
song100000732200506124528.3gp
song100000732200506214528.3gp
.....................
.....

· song – constant prefix.
· 100000732 – 9 digits unique key [per msisdn]
· 200506114528 – time stamp [DDMMYYHHMISS format]

The unique key is the same for each play list of specific msisdn.
The only thing that changes is the timestamp.


so i need for each unique key (there are more then one) the news file will remain


Can anyone help me?

thanks
Reply With Quote
Sponsored Links
  #2  
Old 11th June 2006, 10:40
EvanCarroll EvanCarroll is offline
Junior Member
 
Join Date: Jun 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by erez
I need some help in writing a shell script, it basically need to delete all my older files , the file name structure is like that :

song100000732200506114828.3gp
song100000732200506124528.3gp
song100000732200506214528.3gp
.....................
.....

· song – constant prefix.
· 100000732 – 9 digits unique key [per msisdn]
· 200506114528 – time stamp [DDMMYYHHMISS format]

The unique key is the same for each play list of specific msisdn.
The only thing that changes is the timestamp.


so i need for each unique key (there are more then one) the news file will remain


Can anyone help me?

thanks
Do you need it in shell? Or can it be scripted in a real language.
Reply With Quote
  #3  
Old 15th June 2006, 18:11
erez erez is offline
Junior Member
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i need it in a shell
Reply With Quote
  #4  
Old 16th June 2006, 06:51
g33k g33k is offline
Junior Member
 
Join Date: Jun 2006
Location: India
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to g33k Send a message via Yahoo to g33k
Default

>> so i need for each unique key (there are more then one) the news file will remain

I don't get what exactly you want to do..May be you could have been more clear !!

Well the following script extracts each field (key and date-time) from the file name..

Code:
#!/bin/bash
ext=".3gp"	#put the file extension here

for f in *.3gp	#repeats of for each file in the directory	
do
	#extract the filename without extension
	base=`basename $f $ext`
	echo $base
	
	#extract the prefix
	pref=`echo $base | cut -c 5-13 -`
	echo $pref

	#extract date and time
	dtime=`echo $base | cut -c 14-25 -`
	echo $dtime
done
Reply With Quote
  #5  
Old 16th June 2006, 15:23
flim flim is offline
Junior Member
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

Quote:
Originally Posted by erez
I need some help in writing a shell script, it basically need to delete all my older files , the file name structure is like that :

song100000732200506114828.3gp
song100000732200506124528.3gp
song100000732200506214528.3gp
I assume you want to remove unused stuff older than X days. Instead of checking the timestamp within the filenames you could just do something like this:

find /my/directory -name song*3gp -ctime 50 -print| rm -f

which would delete everything min 50 days old

You can test that it picks the right files with something like:
find /my/directory -name song*3gp -ctime 50 -print| ls -l

Cheers
flim
Reply With Quote
Reply

Bookmarks

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
Need help for writing shell script chris_87 Programming/Scripts 7 4th April 2007 16:50
Perl and cgi script installation linuxuser1 General 30 27th April 2006 00:09
Shell nveid General 5 27th March 2006 15:49
Internal Server Error 500 cgi script mphayesuk General 6 8th February 2006 23:53
Shell script is broken... Duplex Installation/Configuration 4 16th January 2006 10:55


All times are GMT +2. The time now is 08:46.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.