![]() |
optimizing bash process
I have over the past weeks been putting together certain ideas, I have currently a working idea that allows me process video files automatically to html5 WebM VP8 format, my primary language are shell scripts in bash. I want to know if there is better way in simplifying the coding to extremely small sections easy to understand and such.
I'm using nohup to loop every 60 seconds into another shell script, this nohup shell script fires grep and checks if ffmpeg is running or not, this way grep acts for me as a yes or no, from here i can fire ffmpeg to process the videos automatically without me doing anything. essentially grep when is active and checking for ffmpeg looking for 1 or 0, acts as a encoding queue because ffmpeg processes one file at a time. so i fire nohup into Quote:
Quote:
and grep checks Quote:
I have around 8 sh scripts, whats the best way of merging them into maybe 2 or a single script that does everything this is the main shell script, used to do the processing, here I'm in need of figuring a simpler way of doing everything better Quote:
I'm also not a coder, but i learn and pickup fast when explained properly |
Quote:
That's what I'd do, but I too am no coder. But I manage shell scripts now and then...but even those are getting tedious... Obligatory Bash Tutorials. :) Bash scripting guides: http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html http://www.tldp.org/LDP/Bash-Beginne...tml/index.html http://www.gnu.org/software/bash/man...ode/index.html http://www.grymoire.com/Unix/Sh.html http://tldp.org/LDP/abs/abs-guide.pdf http://www.tldp.org/LDP/abs/html/ http://mywiki.wooledge.org/BashFAQ http://mywiki.wooledge.org/BashPitfalls http://rute.2038bug.com/index.html.gz http://bashscripts.org/forum/ Have fun! |
Quote:
Code:
pgrep ffmpeg >/dev/null 2>&1 && exit 0Quote:
Code:
renice -n +20 $$I agree using functions does help with accessing repetitive tasks, you should avoid "for" loops and use "while" ones instead and you could do things like Code:
NEWFILE=${infile// /_}; NEWFILE=${NEWFILE//-/_}; NEWFILE=${NEWFILE//\!/_}; NEWFILE=${NEWFILE//,/_}Code:
find /var/www/logs/ -type f -not -iname \*.text -delete |
I’m still not sure about your intended setup. You want to drop files in a folder and they should be handled automatically once the copy/download processes finished? Or you want to start the next bunch of conversions once the old run is over?
Maybe it can also be handled by a queuing system like GNUbatch: if the copy/download completed, you submit a job for this particular file. This way you can also limit the number of executions of the jobs to avoid overloading of the machine. |
Quote:
Code:
#replace " - " with a single underscore.Code:
NEWFILE=${infile// - /_}; NEWFILE=${NEWFILE//[[:blank:]-]/_}; NEWFILE=${NEWFILE//[\!,]}Code:
NEWFILE=${infile//@( - |[[:blank:]-])/_}; NEWFILE=${NEWFILE//[\!,]}; |
Quote:
Code:
killall -s 0 "$SERVICE" &>/dev/nullAlso please use CODE instead of QUOTE when quoting your codes. |
my setup looks something like this
http://i48.tinypic.com/11afxmq.png I'm currently trying out whats been said here, slowly I'm putting everything into a single short shell script. thanks everybody to telling me some new tools i never heard of such as GNUbatch :) |
Quote:
|
I'd rather do things this way also:
Code:
#!/bin/bash |
thank you very much for that example, I'm reading stuff here glob and trying to figure it all out :D
i understand about maybe 80% of what you scripted lol but totally confused about ([[:digit:]]) what do the ([[: and :]]) do :O i use this to check for 1 or 0 Quote:
Quote:
|
Quote:
There is inotifyd to start a script or alike in case of an event in a directory: Code:
$ incrontab -e |
yes i have looked into this inotify, i thought it was part of ubuntu 12.04 server by default, maybe im mistaking the utilities from ubuntu, but anyway that is good to know more tools :D, i'm looking also into ruby, as i have heard its pretty cool but thats for another thread
i will need to read much more to understand, the batch job with inotify or incrontab, right now grep_ffmpeg.sh acts as a service check and batch job creator. i mean ffmpeg wont get to execute because grep makes sure if it runs or not. and knows what to follow . I'm pretty scared to mess with the code after all this i have spent nearly 4 weeks putting everything very slowly :D i will have to backup everything first. here i go wish me luck i don't destroy everything :D a demo of what I'm working on can be seen here, |
Quote:
Quote:
|
thanks kon, I'm still reading what Reuti posted lol,
Quote:
|
To expand a bit more on konsolebox' last post, [::] represents a regular expression character class, preset ranges of characters that can be used inside [] bracket expressions. bash has also adapted them for use in globbing.
Note that the exact entries represented by the character classes can vary depending on the current system locale. The regular expressions section of info grep has a very readable description of all of them. Edit: I think most of your find commands could be replaced with simple globbing patterns too, particularly if you use extended globbing. It would help to know if the search has to be recursive, however. Code:
# find /var/www/cache02 -regextype posix-egrep -regex '.*\.(jpg|webm)$' -exec mv "{}" /var/www/public/ \; |
| All times are GMT -5. The time now is 03:44 PM. |