Featured Post

read more

How to Schedule Downloads using bash?

This code is incredibly handy; it allows you to schedule the time for a download to happen — say, at 3PM while you’re at work or midnight while you’re sleeping.

user@server:$ echo 'wget http://www.website.com/file.tar.gz' | at 03:00

For example:

user@server:$ echo 'wget http://www.rarlab.com/rar/winrar-x64-390nl.exe' | at 13:50

Output:

job 1 at 2009-11-28 13:50

How to find and list all large files on server using bash?

Looking for large files on your server or linux computer? Find them simply using one of the following commands.

This example search for anything above 50MB.

root@server:$ find / -type f -size +50M

This example search for anything above 100MB.

root@server:$ find / -type f -size +100M

This example search for anything above 1000MB.

root@server:$ find / -type f -size +1000M

Modify your search changing the digit between the “+” and “M”.. Make sense right?

Install SABnzbd on Unix

Alas, the CentOS 5.2 repositories do not have all required modules, so you need to so some work yourself. It does come with Python 2.4, which is OK for SABnzbd. Some extra packages are available if you allow access to the unofficial Dag Wieers repository:

user@server:$ rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

Required compiler stuff:

user@server:$ yum install gcc gcc-c++ python-devel

PyOpenSSL

user@server:$ yum install pyOpenSSL

Cheetah

user@server:$ yum install python-cheetah

OR

user@server:$ wget http://mesh.dl.sourceforge.net/sourceforge/cheetahtemplate/Cheetah-2.0.1.tar.gz
gzip zxf Cheetah-2.0.1.tar.gz
cd Cheetah-2.0.1
python setup.py install # Need to do this as admin
cd ..

YEnc

user@server:$ wget http://sabnzbd.sourceforge.net/yenc-0.3.tar.gz
tar zxf yenc-0.3.tar.gz
cd yenc-0.3
python setup.py install # Need to do this as admin
cd ..

par2cmdline

user@server:$ wget http://garr.dl.sourceforge.net/sourceforge/parchive/par2cmdline-0.4.tar.gz
wget http://sage.math.washington.edu/home/binegar/src/par2cmdline-0.4-gcc4.patch
tar zxf par2cmdline-0.4.tar.gz
cd par2cmdline-0.4
patch < ../par2cmdline-0.4-gcc4.patch reedsolomon.cpp
./configure
make
make check
make install # Need to do this as admin
cd ..

unrar

user@server:$ yum install unrar

OR

user@server:$ wget http://www.rarlab.com/rar/unrar-3.7.7-centos.gz
gzip -d unrar-3.7.7-centos.gz
chmod +x unrar-3.7.7-centos
cp unrar-3.7.7-centos /usr/bin/unrar # Need to do this as admin

Feedparser

user@server:$ wget http://feedparser.googlecode.com/files/feedparser-4.1.zip
mkdir feedparser-4.1
cd feedparser-4.1
unzip ../feedparser-4.1.zip
python setup.py install # Need to do this as admin
cd ..

SABnzbd itself

user@server:$ wget http://switch.dl.sourceforge.net/sourceforge/sabnzbdplus/SABnzbd-0.4.6-src.tar.gz
tar zxf SABnzbd-0.4.6-src.tar.gz
cd SABnzbd-0.4.6
# pre-compile optimized
python -OO SABnzbd.py -v
cd ..

Start SABnzbd

user@server:$ ./SABnzbd.py -s 0.0.0.0:8080

Article Source: CentOS 5.2 (will work for RedHat 5 too)
Ubuntu Server 8.04
ClarkConnect 4.2 Community Edition
For more information: look here.

Convert .mkv to .avi and merge subtitles using bash.

Converting a .mkv file to .avi is easy using this command. It should also merge the standard subtitles. The only problem is that the .avi is still large.

user@server:$ mencoder "video.mkv" -ovc lavc -lavcopts vcodec=mpeg4:threads=8:vbitrate=3000 -oac copy -o video.avi

Create a DVD from .MPG and add subtitles using Spumux in bash.

Packages needed: FFmpeg, spumux, dvdauthor. And maybe mkisofs to create a dvd iso. Or growisofs to burn directly. (If you need to identify your video, install Mplayer.

user@server:$ yum install ffmpeg spumux dvdauthor mkisofs growisofs mplayer

First we need a .mpg or .mpeg file. For example if you have an .avi file, convert this to .mpg (change pal-dvd to ntsc-dvd if needed)

user@server:$ ffmpeg -i movie.avi -target pal-dvd movie.mpg

Now we have the .mpg file we can set up the XML files with the settings for the conversion. Create spumux.xml and add the following settings into it.

<subpictures>
   <stream>
      <textsub filename="yoursubsname.srt" characterset="ISO8859-1"
        fontsize="28.0" font="arial.ttf" horizontal-alignment="left"
        vertical-alignment="bottom" left-margin="60" right-margin="60"
        top-margin="20" bottom-margin="30" subtitle-fps="25"
        movie-fps="25" movie-width="720" movie-height="576"
     />
   </stream>
</subpictures>

You have to replace the filename, movie-width and the movie-height to your video preferences. You have seen them while converting if not use this command.

user@server:$ mplayer -identify output.mpg

Now before we start processing, we need arial.ttf in our .spumux folder. If you don’t have a .spumux folder, create one;

user@server:$ mkdir ~/.spumux

OK — now we are all set, what you have to do now is use the following command.

user@server:$ spumux spumux.xml < out.mpg > output.mpg
DVDAuthor::spumux, version 0.6.11.
Build options: gnugetopt iconv freetype
Send bugs to

INFO: Locale=en_US.UTF-8
INFO: Converting filenames to UTF-8
INFO: Detected subtitle file format: subviewer
INFO: Opened iconv descriptor. *UTF-8* *ISO8859-1*
INFO: Read 1340 subtitles
INFO: Adjusted 39 subtitle(s).
INFO: Unicode font: 1418 glyphs.
INFO: Found EOF in .sub file.
WARN:  Read 0, expected 4
INFO: 1340 subtitles added, 0 subtitles skipped, stream: 32, offset: 0.50

Statistics:
- Processed 1340 subtitles.
- The longest display line had 48 characters.
- The maximum number of displayed lines was 3.
- The normal display height of the font arial.ttf was 32.
- The bottom display height of the font arial.ttf was 45.
- The biggest subtitle box had 4470 bytes.

Alright, when this is done we have to make another .xml file. Create dvd.xml and put this in there.

<dvdauthor dest="DVD">
  <vmgm />
   <titleset>
     <titles>
       <pgc>
         <vob file="output.mpg"/>
       </pgc>
     </titles>
   </titleset>
</dvdauthor>

Obviously you have to change the vob file to your output video name. When you have done that we can do the following command.

user@server:$ dvdauthor -x dvd.xml
DVDAuthor::dvdauthor, version 0.6.11.
Build options: gnugetopt iconv freetype
Send bugs to

INFO: Locale=en_US.UTF-8
INFO: Converting filenames to UTF-8
INFO: dvdauthor creating VTS
STAT: Picking VTS 01

STAT: Processing output.mpg…
STAT: VOBU 12080 at 4249MB, 1 PGCS
INFO: Video pts = 0.500 .. 5813.060
INFO: Audio[0] pts = 0.500 .. 5813.172
INFO: Audio[32] pts = 5.660 .. 5760.406
STAT: VOBU 12086 at 4250MB, 1 PGCS
INFO: Generating VTS with the following video attributes:
INFO: MPEG version: mpeg2
INFO: TV standard: pal
INFO: Aspect ratio: 4:3
INFO: Resolution: 720×576
INFO: Audio ch 0 format: ac3/6ch, 48khz drc

STAT: fixed 12086 VOBUS
INFO: dvdauthor creating table of contents
INFO: Scanning DVD/VIDEO_TS/VTS_01_0.IFO

You have just created a dvd including subtitles which you can enable or disable. What you got to do now is simply make a ISO or burn it directly to your blank dvd.

To make a ISO you can use this command:

user@server:$ mkisofs -dvd-video -o name-your-dvd.iso DVD/
97.40% done, estimate finish Fri Nov 13 08:53:17 2009
97.63% done, estimate finish Fri Nov 13 08:53:16 2009
97.86% done, estimate finish Fri Nov 13 08:53:17 2009
98.09% done, estimate finish Fri Nov 13 08:53:17 2009
98.32% done, estimate finish Fri Nov 13 08:53:16 2009
98.55% done, estimate finish Fri Nov 13 08:53:17 2009
98.78% done, estimate finish Fri Nov 13 08:53:16 2009
99.01% done, estimate finish Fri Nov 13 08:53:16 2009
99.24% done, estimate finish Fri Nov 13 08:53:16 2009
99.46% done, estimate finish Fri Nov 13 08:53:15 2009
99.69% done, estimate finish Fri Nov 13 08:53:15 2009
99.92% done, estimate finish Fri Nov 13 08:53:16 2009
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 4096
Path table size(bytes): 42
Max brk space used 15000
2176659 extents written (4251 MB)
[user@server]$

If you want to burn it directly without making a .iso then use this command; (Replace /dev/scd0 with the device path to your DVD recorder)

user@server:$ growisofs -Z /dev/scd0 -dvd-video DVD/

How to create a sample of a video using bash?

With this code you can simply create a preview/sample of your video. Starts at 5.00 and ends on 8.00.

Package needed: Mencoder

user@server:$ mencoder movie.mkv -o movie.avi -ovc lavc -oac mp3lame -ss 5:00 -endpos 8:00

Easy full server backup using tar in bash.

If you decide to use “tar” as your backup solution, you should probably take the time to get to know the various command-line options that are available; type “man tar” for a comprehensive list.

The following code will create a full backup of your entire server. Excluding, /media, /proc and /var/spool/squid you might want to add or delete some excludes. Like /mnt, most servers mount devices in that folder. You need to exclude these as well. Also, You need to make sure you are creating your backup in a excluded folder/area. I make my backups in a mounted 30GB HD Device located in /media which is excluded.

user@server:$ tar -cvpzf ServerBackup-`date '+%d-%B-%Y'`.tar.bz2 / --exclude=media --exclude=proc --exclude=var/spool/squid

If you only want to make a Backup from your /home and /root directory (which are probably the most important) just use this command:

user@server:$ tar -cvpzf ServerBackup-`date '+%d-%B-%Y'`.tar.bz2 /root /home

Hope it works for you like it did for me, if you have any questions regarding to this post, please leave a comment so others can read it too.

Posts may be digged!

Like you can see I’ve added a “digg it!” button to all of my posts. This is not the actual “digg” button from digg.com, But a-look-a-like. I didn’t want to use the official digg button because, then you need a digg.com account and you have to log in every time you want to vote/digg it.. which annoys me big time on other websites. (If i’m not right, you may want to correct me — leave a comment!)

So, if you like one of my posts! Don’t forget to digg it! Thanks.