3

This question already has an answer here:

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: -

marked as duplicate by muru command-line May 17 '16 at 22:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Please edit your post to include the output of file conv-script and stat conv-script. – muru May 17 '16 at 20:43
  • 1
    First, you do not need sudo is all of the above. Second, make sure to cd to the location of the script, for example, cd Downloads or cd Music. – mikewhatever May 17 '16 at 20:43
  • 1
    Don't use sudo. @mikewhatever, he's already in the right directory because chmod is not failing. – wjandrea May 17 '16 at 20:48
  • 1
    Could also move the script to an EXT partition, if there's one readily available. – wjandrea May 17 '16 at 22:52
  • 1
    Hmm. Had no idea chmod didn't work on different partition types today I learned, thanks. I ended up following wjandrea's suggestion and moving it to an EXT partition and the script is in progress right now and appears to be working – kalenpw May 17 '16 at 22:56
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.

  • Turns out I didn't have libav-tools installed but after installing that and fixing the script I still get the same Permission denied message. – kalenpw May 17 '16 at 22:49
  • Well as i read from the comments on your question this is more a problem of remounting the partition properly. But your command not found error should be past now. – Videonauth May 17 '16 at 22:53
  • yeah that was the issue I had no idea it couldn't be mounted as FAT but I needed libav-tools anyway so thank you – kalenpw May 17 '16 at 22:58
  • libav-tools is just a transitional package that installs the ffmpeg package, so it can be ignored if you install ffmpeg. – llogan May 17 '16 at 23:22
  • @LordNeckbeard and why then avprobedoesnt show up even if i have ffmpeginstalled? Ad why does apt-cache search avprobe yields as output this package? I test each answer I write on my machine before and without libav-tools the script didn't work. – Videonauth May 17 '16 at 23:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.