3

I am using a script called conv-script that I found on AskUbuntu here. It looks like this

#!/bin/sh

readarray -t files < wma-files.txt

for file in "${files[@]}"; do
    out=${file%.wma}.mp3
    probe=`avprobe -show_streams "$file" 2>/dev/null`
    rate=`echo "$probe" | grep "^bit_rate" | sed "s:.*=\(.*\)[0-9][0-9][0-9][.].*:\1:" | head -1`
    ffmpeg -i "$file" -ab "$rate"k "$out" && rm "$file"
done

I have ran sudo chmod +x ./conv-script and then I try and execute it with sudo ./conv-script

After doing so I get an error sudo: ./conv-script: command not found

I am unsure what I am doing wrong as I can see the file in the current working directory and I have set it to be executable. One thing I thought it might be was the first line of my script is wrong, but I have another script with the same shebang and it executes fine. When I use the shebang in the original #!/usr/bin/env bash I get the same thing. Thanks for the help

EDIT:

output of file conv-script

conv-script: a /usr/bin/env bash script, ASCII text executable

output of stat conv-script

  File: ‘conv-script’
  Size: 325             Blocks: 64         IO Block: 32768  regular file
Device: 821h/2081d      Inode: 82004       Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/ kalenpw)   Gid: ( 1000/ kalenpw)
Access: 2016-05-17 16:40:43.000000000 -0600
Modify: 2016-05-17 14:33:31.000000000 -0600
Change: 2016-05-17 14:33:32.000000000 -0600
 Birth: -
kalenpw
  • 754

1 Answers1

1

As first make sure you have ffmpeg and libav-tools installed, this you can do by typing in terminal (ctrl+alt+t):

apt-cache policy ffmpeg libav-tools

This should get you an output like the following if both are installed:

ffmpeg:
  Installed: 7:2.8.6-1ubuntu2
  Candidate: 7:2.8.6-1ubuntu2
  Version table:
 *** 7:2.8.6-1ubuntu2 500
        500 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        100 /var/lib/dpkg/status
libav-tools:
  Installed: 7:2.8.6-1ubuntu2
  Candidate: 7:2.8.6-1ubuntu2
  Version table:
 *** 7:2.8.6-1ubuntu2 500
        500 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        500 http://archive.ubuntu.com/ubuntu xenial/universe i386 Packages
        100 /var/lib/dpkg/status

If you get in one of the lines beginning with Installed: an entry (none) install the package with sudo apt-get install <package-name>.

Now only a few corrections to the script itself:

#!/bin/bash

cd "$1"
find . -type f | grep wma$ > wma-files.txt

readarray -t files < wma-files.txt

for file in "${files[@]}"; do
    out=${file%.wma}.mp3
    probe="$(avprobe -show_streams "$file" 2>/dev/null)"
    rate="$(echo "$probe" | grep "^bit_rate" | sed "s:.*=\(.*\)[0-9][0-9][0-9][.].*:\1:" | head -1)"
    ffmpeg -i "$file" -ab "$rate"k "$out" && rm "$file"
done

You can call this then with ./script.sh /path-to-your-music.

Videonauth
  • 33,815