Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-14-2004, 08:38 PM   #1
Registered: Jun 2003
Distribution: Arch
Posts: 315

Rep: Reputation: 30
Why does this script just delete my new wav files all the time?

The idea is for the script to run at 3:00 pm every day, and if there are new wav files, to move the old mp3 into an archive, encode a new mp3, and then dispose of the wav file.

Instead, the thing just goes on a psycho rampage and eats wav files with no mp3 output. What is going wrong?

#Archives old MP3's, and compresses new ones

#Set DATE variable to today
DATE=`date +'%m-%d-%Y'`

#Checks to see if there is a new wav file. Does nothing if there is not.
if ls /audio/ | grep -q wav &> /dev/null
	#Copy old MP3's into an archive directory, then deletes
	mv /audio/*.mp3 /audio/archive

	#Encodes wav file into MP3
	lame -a -h -p -b 96 /audio/*.wav /audio/$DATE.mp3

	#Deletes old wav file
	rm /audio/*.wav
Old 01-14-2004, 08:55 PM   #2
LQ Guru
Registered: Jan 2001
Posts: 24,147

Rep: Reputation: 229Reputation: 229Reputation: 229
Have you tried the script without the deletion of .wav's yet? Just to see if it is actually encoding them at all?
Old 01-15-2004, 01:43 AM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 657Reputation: 657Reputation: 657Reputation: 657Reputation: 657Reputation: 657
You might want to add verbose options to the commands that allow it and redirect stdio and stderr to a file.

Also, whenever I move files to a directory, I add a '/' after the target directory. The first time that the file is run, if the target directory doesn't exist, will rename the file instead of causing an error. ( Assumming only one file exists ) I just think that is is a good habit, whether you are using bash or even windows DOS.
Old 01-15-2004, 05:00 PM   #4
Registered: Jun 2003
Distribution: Arch
Posts: 315

Original Poster
Rep: Reputation: 30
My main concern is the if statement.... I really don't know how to use them. This is my first bash script ever, and I don't know if I did it right.
Old 01-15-2004, 06:46 PM   #5
Registered: Aug 2002
Posts: 13,318

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Does it convert all of the files by just using a wildcard? Have you tried the lame line (no pun intended) on the command line?

How about
if yadda
 mv ... 
 foreach file (/audio/*.wav)
  lame ... $file /audio/$date.mp3 
  rm $file
 (instead of rm $file you can rm /audio/*.wav here )
This is untested but you probably get the idea.

Why are you changing the name of the wav file to a date? It is possible to use the sed command to name the MP3 the same as the wav.

(For some reason my changes are not being saved)
There is more to shell programming than meets the eye.

Last edited by michaelk; 01-15-2004 at 06:49 PM.
Old 01-15-2004, 09:06 PM   #6
Registered: Oct 2003
Location: USA
Distribution: xubuntu
Posts: 202

Rep: Reputation: 21
According to the lame man page, this is the syntax:

lame [options] <infile> <outfile>

Apparently you can't use a wildcard as you did in
lame -a -h -p -b 96 /audio/*.wav /audio/$DATE.mp3
so lame ignores that command, and then you get to
rm /audio/*.wav
rm is perfectly happy with wildcards so on the first loop it deletes all the wav files in the /audio directory.

Instead, before the loop, move the old mp3s to the archive directory. Use your code
#Copy old MP3's into an archive directory, then deletes
mv /audio/*.mp3 /audio/archive
Then step through the /audio directory one file at a time, something like:
cd /audio
for W_file in *
if [[ $W_file == *.wav ]]
#Encodes wav file into MP3
lame -a -h -p -b 96 $W_file /audio/$W_file$DATE.mp3

#Deletes old wav file
rm $W_file
PS: if you use $DATE.mp3 for <outfile>, you'll just keep overwriting lame's output & end up with only 1 mp3 for the day.


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
Script to delete files with 0k file size in a directory justgiver Linux - Newbie 4 01-28-2008 04:56 AM
need a script to delete all files from a folder and subfolders cccc Programming 1 03-04-2005 10:54 AM
bash script to delete files c0d3 Programming 9 12-05-2004 10:45 PM
Delete old files and folders Script? AsteX Linux - General 4 11-11-2004 06:26 PM
Script on linux to delete certain files ForumKid Linux - General 2 06-22-2002 01:09 PM

All times are GMT -5. The time now is 05:55 AM.

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