LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 01-14-2004, 09:38 PM   #1
kleptophobiac
Member
 
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?

Code:
#!/bin/bash
#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
then
	#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
fi
 
Old 01-14-2004, 09:55 PM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
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, 02:43 AM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
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, 06:00 PM   #4
kleptophobiac
Member
 
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, 07:46 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 12,165

Rep: Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784
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
Code:
if yadda
 mv ... 
 foreach file (/audio/*.wav)
  ...
  lame ... $file /audio/$date.mp3 
  rm $file
 end
 (instead of rm $file you can rm /audio/*.wav here )
fi
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 07:49 PM.
 
Old 01-15-2004, 10:06 PM   #6
r.stiltskin
Member
 
Registered: Oct 2003
Location: USA
Distribution: xubuntu
Posts: 196

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
Quote:
lame -a -h -p -b 96 /audio/*.wav /audio/$DATE.mp3
so lame ignores that command, and then you get to
Quote:
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
Quote:
#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:
Quote:
cd /audio
for W_file in *
do
if [[ $W_file == *.wav ]]
then
#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
fi
done
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.
 
  


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


All times are GMT -5. The time now is 10:07 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration