In the sh file variable is not being passed on.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting In the sh file variable is not being passed on.
# 1  
Old 01-15-2012
In the sh file variable is not being passed on.

I am having difficulties with the fllowing script:
Code:
!/bin/sh

voicemaildir=/var/spool/asterisk/voicemail/$1/$2/INBOX/

echo `date` ':' $voicemaildir >> /var/log/voicemail-notify.log

for audiofile in `ls $voicemaildir/*.wav`; do
   transcriptfile=${audiofile/wav/transcript}
   flacfile=${audiofile/wav/flac}
   # For each message.wav we check if message.transcript
   # exists
   if [ ! -f $transcriptfile ]; then
      # If not, we create it
      flac --best --sample-rate=8000 $audiofile -o $flacfile
      speech-recog-cli.pl $flacfile  | head -2 | tail -1 | cut -f 2 -d ":"  > $transcriptfile

      # Now we can do whatever we want with the new transcription
      echo `cat $transcriptfile`
  
 fi
done

When I run the script, the flac file that gets generated is empty, it just says fLaC.
However,If I manually run it by typing the following into ssh, it does work. Any suggestions? Thanks
Code:
 flac --best --sample-rate=8000 msg0025.wav  -o msg0025.flac
speech-recog-cli.pl $flacfile  | head -2 | tail -1 | cut -f 2 -d ":"  > $transcriptfile


Last edited by ghurty; 01-15-2012 at 02:18 PM.. Reason: More tags
# 2  
Old 01-15-2012
Try to start by changing this:
Code:
for audiofile in `ls $voicemaildir/*.wav`; do

to this:
Code:
for audiofile in $voicemaildir/*.wav; do

and using double quotes around all occurrences of your variables.

i.e.
Code:
flac --best --sample-rate=8000 "$audiofile" -o "$flacfile"

Remove the trailing space from the declaration of voicemaildir.

Also, maybe change:
Code:
flacfile=${audiofile/wav/flac}

to:
Code:
flacfile=${audiofile%.wav}.flac

# 3  
Old 01-15-2012
I will try that, I just relized I posted some wrong info.

The code that works when I do manually is:
Code:
flac --best --sample-rate=8000 msg0025.wav  -o msg0025.flac

I cant have any variable in it.

Thanks

Last edited by Scott; 01-15-2012 at 02:20 PM.. Reason: Code tags
# 4  
Old 01-15-2012
I gathered that, otherwise you'd have to set all the variables manually Smilie
# 5  
Old 01-15-2012
That worked. Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash variable not being passed

In the bash below the variable date displays in the echo. However when I use it in the for loop it does not. Basically, the user inputs a date then that date is converted to the desired format of (month-day-year, no leading 0). That input is used in the for loop to return every file that matches... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Variable not passed to the sed command

Hello, I am writing a script which is not giving the desired result. When I check the content of the 'InputFile_009_0.sh', it shows following with missing Index in this command sed -i "s/L1ITMBLT.root/L1ITMBLT_"".root/g" run_DttfFromCombinedPrimitives_cfg.py of . Any help? ... (13 Replies)
Discussion started by: emily
13 Replies

3. Shell Programming and Scripting

Variable passed as argument

I have a script. #!/bin/sh cur_$1_modify_time=Hello echo "cur_$1_modify_time" When I run like sh /root/script1 jj I expect value "Hello" being assigned to variable "cur_jj_modify_time" and output being "Hello" ie echoing $cur_jj_modify_time But the output comes as # sh... (3 Replies)
Discussion started by: anil510
3 Replies

4. Shell Programming and Scripting

Grepping file and returning passed variable if the value does not exist in file at all.

I have a list of fields that I want to check a file for, returning that field if it not found at all in the file. Is there a way to do a grep -lc and return the passed variable too rather then just the count? I am doing some crappy work-around now but I was not sure how to regrep this for :0 so... (3 Replies)
Discussion started by: personalt
3 Replies

5. Shell Programming and Scripting

Why Perl Subroutine Passed In Variable is 1?

The following subroutine prints 1 instead of the content of the Equipment variable. Can someone tell me why? #!c:/perl/bin/perl.exe # use strict 'vars'; my $Equipments = "data/equips.txt"; unless (open(EQUIP_FH, "$Equipments")) { print "errors: $Equipments\n"; # This line prints... (1 Reply)
Discussion started by: tqlam
1 Replies

6. UNIX for Dummies Questions & Answers

update value in a file using variable passed via unix script

I have a file in my unix directory called "restart_job1.job". Below is a sample of the script where I am doing a 'grep' to check specifically for an oracle error. If the value 'ORA-" is found, I set a variable to hold the return code value (job1_return_code). If the return code is non zero, I... (2 Replies)
Discussion started by: ncsthbell_dr
2 Replies

7. Shell Programming and Scripting

My variable cannot be passed through into my path

Hi, Can you please help. I am scripting in sh and I am trying to simply copy one directory to another but for some reason my variables are not recognised? echo "The latest version of the program is being found......." cd $SOFTWARE/src/$progname version=`ls $SOFTWARE/src/$progname | grep... (13 Replies)
Discussion started by: cyberfrog
13 Replies

8. UNIX for Dummies Questions & Answers

Assigning a Variable all the Parameters passed

Hi, I have a unix script which can accept n number of parameters . I can get the parameter count using the following command and assign it to a variable file_count=$# Is there a similar command through which i can assign a variable all the values that i have passed as a parameter ... (2 Replies)
Discussion started by: samit_9999
2 Replies

9. UNIX for Dummies Questions & Answers

variable passed to awk

Does anybody know how to print a variable passed to awk command? awk -F"|" 'BEGIN {print $job,"\n","Question \n"} {print $1,$2$4," ",$3}' "job=$job1" file1 I am trying to pass job the variable job1. the output is blank. ?? (3 Replies)
Discussion started by: whatisthis
3 Replies

10. UNIX for Dummies Questions & Answers

variable passed to awk

Anybody know what's wrong with this syntax? awk -v job="$job" 'BEGIN { FS="|"} {print $1,$2," ",$4," ",$3\n,$5,"\n"}' list It's keeping give me this message: awk: syntax error near line 1 awk: bailing out near line 1 It seems awk has problem with my BEGIN command. Any... (8 Replies)
Discussion started by: whatisthis
8 Replies
Login or Register to Ask a Question