FFMPEG: How to launch script automatically?

Share your awesome tips and tricks here.
Post Reply
Jagstyles
youtube meble na wymiar Warszawa

FFMPEG: How to launch script automatically?

Post by Jagstyles »

So I have FFMPEG installed and upon entering the following line using PuTTY I can execute FFMPEG to convert all MKV files in a set directory to MP4 files:

/volume1/misc/Convert/manual.py -a -i /volume1/misc/Convert/process

What i need to know is how do I run that script automatically or have it constantly monitor the set directory for new MKV files without manually having to launch PuTTY to login with ROOT access and then enter the command line?

Any suggestions/ideas? Trying to automate the process by which Couch Potato downloads the MKV files and then FFMPEG converts them over. Right now its working but I have to manually run the command line script each time i know there are MKV files to convert.

Thanks
MikeG.6.5
Posts: 917
Joined: Fri May 15, 2015 1:56 am

Re: FFMPEG: How to launch script automatically?

Post by MikeG.6.5 »

Look in the Plex sub-forum for the posts I made yesterday about Plex Media Server and such. You are going to need to make a small script, I put it in /volume1/misc called Conv.sh. Then I make an entry in the root file in the /volume0/usr/builtin/etc/crontabs folder.

This line reads: */15 * * * * /volume1/misc/Conv.sh It runs every 15 minutes. The actual script is this:

Code: Select all

#!/bin/sh
SERVICE='ffmpeg'
 
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
    echo "$SERVICE service running, everything is fine"
else
    echo "$SERVICE is not running"
    /volume1/misc/Convert/manual.py -a -i /volume1/misc/Convert/process
fi

exit 0
This tests if ffmpeg is running, and won't start if it is. If it's not it starts up and then processes each file in that folder until they are converted and then deletes the original files from the process folder.
Jagstyles

Re: FFMPEG: How to launch script automatically?

Post by Jagstyles »

Okay so I've followed all of the instructions and think everything is setup properly but the startup scripts in the root file still isn't being launched. Here's what I have in my root file:

ROOT FILE:

Code: Select all

0 4 * * 0 /usr/builtin/sbin/syssetagent "System Setting"
0 2 * * 0 /usr/builtin/sbin/extbkagent "NASBackup"
*/15 * * * * /volume1/Misc/Conv.sh "Convert MKV"
*/20 * * * * /volume1/Misc/ChkPlexPy.sh "Check Plex Logging"
*/20 * * * * /volume1/Misc/CkPlex.sh "Check Plex Server"
30 0 * * * /bin/sh /usr/builtin/sbin/ntpupdate.sh north-america.pool.ntp.org 
I added the quotes part to describe what it is but I also tried it without the description beside each of the lines of code for each script but it made no difference. I confirmed that all the paths are properly set and ensured I checked the case-sensitive names of the paths as well. Still none of these being launched. Also, here are the other scripts I've added:

Conv.sh

Code: Select all

#!/bin/sh
SERVICE='ffmpeg'

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
    echo "$SERVICE service running, everything is fine"
else
    echo "$SERVICE is not running"
    /volume1/Misc/Convert/manual.py -a -i /volume1/Download/Process
fi

exit 0
ChkPlexPy.sh

Code: Select all

#!/bin/sh

curl -I -m 8 "http://jagstyles.myasustor.com:8181/home";
if [ "$?" -ne "0" ]

then
                /usr/sbin/syslog --log 0 --level 0 --user admin --event "PlexPy isn't running:  Starting it"                
                /volume1/Misc/PlexPy/PlexPy.py -d
fi

exit 0
CKPlex.sh

Code: Select all

#!/bin/sh

curl -I -m 8 "http://rmgud.myasustor.com:21464/web/index.html"
if [ "$?" -ne "0" ]

then
/usr/sbin/syslog --log 0 --level 0 --user admin --event "Remote Access to Plex is unavailable"

                /usr/local/AppCentral/plexmediaserver/CONTROL/start-stop.sh stop
                sleep 5
                /usr/local/AppCentral/plexmediaserver/CONTROL/start-stop.sh start
fi

exit 0
I'm at a loss for why these scripts aren't starting up. I have a file in the Process folder ready to be converted called "Spy (2015).mkv" but nothing ever seems to happen. When I run the conversion script manually in Putty, it works no problem.

Any ideas/suggestions?

Thanks
Jagstyles

Re: FFMPEG: How to launch script automatically?

Post by Jagstyles »

Also, are there any log files I can view from when my NAS boots up to see if there's an error being generated trying to launch these scripts? Also wondering if it matters which user has ownership of these folders i.e.: FFMpeg or Convert folders etc. I created all those folders on the NAS using my account which is an admin account. I noticed some folders show ownership by me, others by Root etc.

Probably grasping at straws here but trying to figure it out given everything seems to beginning up.

Thanks
Jagstyles

Re: FFMPEG: How to launch script automatically?

Post by Jagstyles »

Okay so looks like the script to check if PlexPy is running is working as I get the following message:

This is a system event notification sent from MyAsustor.

Event Level: INFO
Date: 11/14/2015 PM 12:00
User: admin
Event: PlexPy isn't running: Starting it

The problem is that this message shows up every 20 mins which means that although it's correctly checking, the part to start the script when it's not running isn't working.

Also, the conv.sh script still doesn't seem to be doing anything as the spy.mkv file is still unprocessed in the Process folder.
Post Reply

Return to “Tips & Tricks”