Wednesday, August 3, 2011

Python: Reading and Running Commands From A File

So I recently came across a broken process that needed some manual re-running. I was able to search through the log files and then see what part needed to be re-run. I ended up with a new data file (that I modified) to be a list of each command that failed for each iteration. So, the file looked something like this:
/path/to/program -option x -site a
/path/to/program -option x -site b
...
/path/to/program -option x -site z



Using a bash for line in `cat command.file`; do $line; done would not work since I would end up with a
-bash: -option: command not found
-bash: x: command not found
-bash: -site: command not found
error. So, here's some quick Python that can get the job done:

import os

f = open('/tmp/tmp-fix.commands')
for line in f:
    print line.rstrip()
    os.system(line.rstrip())


Yay for saving me some time! Cheers!

Tuesday, August 2, 2011

ffmpeg: Creating A Single Image Video With Audio via CLI

Here's a nice quickie for you command line junkies. So say you wanted to share an audio file, but for sites like Facebook or Google+ you only have an option to upload a video. Okay sure, just create a video with the audio embedded.

My friend left me a hilarious voicemail a while back that I wanted to share with friends. I also wanted to set an image to constantly display just for viewing pleasure. So, bake the image to loop add in the mp3 voicemail and voila!


ffmpeg -loop_input -i Downloads/P1010155.png -i Downloads/30ad00fa24c1dcdf7479271f290c82252216718a.mp3 -shortest tmp/output.mp4