Featured Post

read more

How to update your twitter status in linux using bash?

Updating your twitter status using the bash SHell in Linux is easier then you may think, you can update your status using “curl“, curl is a tool to transfer data from or to a server. All you have to do is execute this command showed underneath. This will transfer the status data to the twitter site using the Twitter API.

user@server:$ curl -u user:pass -d status=”Tweeting from the shell” http://twitter.com/statuses/update.xml

But of course, you don’t want to be typing all that every time you want to update your twitter status. So I found this website which has a executable twitter bash script.

user@server:$ curl --basic --user "user:password" --data-ascii "status=`echo $@|tr ' ' '+'`" "http://twitter.com/statuses/update.json"

Replace the user and password with your twitter user id and password. Now save the text to a file called ‘twitter‘ and give the file execute permission. Put this file in any folder in your path. If you want to use this script everywhere on the server make sure it’s located in /usr/local/bin or ~/bin. If you are a user on the server, you may just create the file in your ~/user folder.

Now, how to use the script?

If you have created the twitter file in /usr/local/bin or ~/bin you may use this command anywhere you are in the server.

user@server:$ twitter Testing and using Twitter CLI.

For best results, enclose the message within quotes. This will prevent problems when using wild card characters like ‘?’

user@server:$ twitter "Testing and using Twitter CLI."

And if have created the twitter file in your ~/user directory, make sure you are in the same folder as the file and then you may use this command.

user@server:$ ./twitter "Testing and using Twitter CLI."

Not working?

Did you make sure the file has executable rights?

user@server:$ chmod +x twitter

How to unrar multiple .rar files using bash?

You might need the package: unrar

You can check your server using the following command if you have already installed it or not.

user@server:$ rpm -q unrar

If nothing shows up, install the package unrar. If you are using a Linux OS which uses yum update you can use the following command to install it.

user@server:$ yum install unrar

If that does not work for you, you can simply install it manually using the next commands.

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

When that is all done, we can start using unrar. If you want to unrar multiple .rar files at once, you may use this command.

user@server:$ find -type f -name '*.rar' -exec unrar x {} \;

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