Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

ive written a ffmpeg script to mass convert mkv into mp4. when i run the script as my user, and enter my password for sudo privileges it works very well from the command line. the script is:

#! /bin/bash

for INF in *.mkv
do
  sudo ffmpeg -i "$INF" -vcodec copy -acodec ac3 "${INF%.*}.mp4"
done

very simple and works. however, when i run it as a cron job (setup through webmin) as root it runs ffmpeg but then says:

ffmpeg version git-2013-05-14-56ba331 Copyright (c) 2000-2013 the FFmpeg developers
  built on May 13 2013 23:50:16 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-version3
  libavutil      52. 31.100 / 52. 31.100
  libavcodec     55.  9.100 / 55.  9.100
  libavformat    55.  7.100 / 55.  7.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 65.100 /  3. 65.100
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
*.mkv: No such file or directory

for some reason it seems like it cant access the mkv files or INF doesnt work with cron jobs? i dont know. any push in the right direction would be very helpful.

edit: when i run this the script (test.sh) is in a certain dir (/mnt/sdb1/temp) do i need to have that in the script? would it be giving me that error because its running it somewhere else that actually doenst have mkv files?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

i figured it out.

i needed to change this line:

for INF in *.mkv

to point directly at the folder:

for INF in /mnt/sdb1/temp/*.mkv
share|improve this answer
2  
In general, in scripts, use the full path –  bodhi.zazen May 23 '13 at 3:30
2  
Or change to the desired directory. cd /mnt/sdb1/temp || exit; for inf in ./*.mkv; do. On a side note, avoid using all uppercase variable names. Special shell variables and environment variables are (almost) always all uppercase, so using lowercase variable names avoids accidentally overriding special shell variables or environment variables. –  geirha May 23 '13 at 18:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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