Friday, October 15, 2010

Sendmail rebuild and Sendmail-access Lesson basic 101

SkyHi @ Friday, October 15, 2010
 sendmail - an electronic mail transport agent


# rpm -ihv sendmail-8.11.6-3.i386.rpm
# rpm -ihv sendmail-doc-8.11.6-3.i386.rpm
# rpm -ihv sendmail-cf-8.11.6-3.i386.rpm
# rpm -ihv imap-2000c-15.i386.rpm
# rpm -ihv imap-devel-2000c-15.i386.rpm

Location of setting file


How to make

  1. Edit /etc/mail/
  2. divert(-1)
    dnl This is the sendmail macro config file. If you make changes to this file,
    dnl you need the sendmail-cf rpm installed and then have to generate a
    dnl new /etc/ by running the following command:
    dnl        m4 /etc/mail/ > /etc/
    VERSIONID(`linux setup for Red Hat Linux')dnl
    define(`confTO_CONNECT', `1m')dnl
    define(`ALIAS_FILE', `/etc/aliases')dnl
    define(`UUCP_MAILER_MAX', `2000000')dnl
    define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
    define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
    define(`confAUTH_OPTIONS', `A')dnl
    FEATURE(`mailertable',`hash -o /etc/mail/mailertable.db')dnl
    FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
    FEATURE(local_procmail,`',`procmail -t -Y -a $h -d $u')dnl
    FEATURE(`access_db',`hash -o /etc/mail/access.db')dnl
    DAEMON_OPTIONS(`port=smtp,Addr=, Name=MTA')
  3. Edit /etc/mail/access
  4. # Check the /usr/share/doc/sendmail-8.11.6/ file for a description
    # of the format of this file. (search for access_db in that file)
    # The /usr/share/doc/sendmail-8.11.6/ is part of the sendmail-doc
    # package.
    # by default we allow relaying from localhost...
    # localhost.localdomain         RELAY
    # localhost                     RELAY
    #                     RELAY
  5. Edit /etc/mail/relay-domains
  6. 192.168.0.
  7. Edit /etc/mail/local-host-names
  8. # local-host-names - include all aliases for your machine here.
  9. Enable imap, imaps, ipop3, pop3s, sendmail using by ntsysv
    # ntsysv
  10. Compile and restart sendmail
    # m4 /etc/mail/ > /etc/
    # makemap hash /etc/mail/access.db < /etc/mail/access
    # /etc/init.d/sendmail restart
  11. Check the start-up log
    # tail /var/log/message
    Jun  6 22:28:45 yourname sendmail: sendmail shutdown succeeded
    Jun  6 22:28:47 yourname sendmail: sendmail startup succeeded

How to test

  1. Test by telnet
    # telnet 110
    Connected to
    Escape character is '^]'.
    +OK POP3 yourhost v6.50 server ready
    -ERR Unknown command in AUTHORIZATION state
    USER youruser
    +OK User name accepted, password please
    PASS ********
    +OK Mailbox open, 15 messages
    1 15086
    2 13874
    3 10065
    4 15055
    5 17742
    6 15442
    7 9176
    8 9052
    9 1471
    10 37106
    11 14620
    12 8343
    13 7457
    14 14941
    15 1418
    +OK Sayonara
    Connection closed by foreign host.
  2. Test
    # sendmail -bt -f /etc/
    ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
    > 0 youruser parse input: youruser Parse0 input: youruser Parse0 returns: youruser ParseLocal input: youruser ParseLocal returns: youruser Parse1 input: youruser Parse1 returns: $# local $: youruser parse returns: $# local $: youruser > 0 parse input: youruser @ yourdomain . bt Parse0 input: youruser @ yourdomain . bt Parse0 returns: youruser @ yourdomain . bt ParseLocal input: youruser @ yourdomain . bt ParseLocal returns: youruser @ yourdomain . bt Parse1 input: youruser @ yourdomain . bt Parse1 returns: $# local $: youruser @ yourdomain . bt parse returns: $# local $: youruser @ yourdomain . bt >

Reject SPAM domain

If you want to reject receiving mail (as SPAM) from particular domain, maintain /etc/mail/access
  1. Edit /etc/mail/access
    ...                            REJECT       REJECT                     REJECT                            REJECT
  2. Convert access to access.db
    # makemap hash /etc/mail/access.db < /etc/mail/access
  3. Restart sendmail
    # /etc/init.d/sendmail restart

Remove blacklist message automatically

Remove blacklist message automatically by procmail
  1. Edit $HOME/.procmailrc
    :0 h
    *$ ? test -s $BLACKLIST
    * ? (formail -x From: -x Reply-To: -x Sender: -x From | fgrep -iqf $BLACKLIST)
  2. Make a blacklist $HOME/.blacklist

Aliases name

  1. Edit /etc/aliases
    group1: user1, user2, user3, . . .
  2. Rebuild the data base for the mail aliases file
    Newaliases rebuilds the random access data base for the mail aliases file /etc/aliases. It must be run each time this file is changed in order for the change to take effect.
    # newaliases

Message forwarding

  1. Edit ~/.forward file to forward all messages.



sendmail access.db by example

The sendmail access database file can be created to accept or reject mail from selected domains.
Since "/etc/mail/access" is a database, after creating the text file, use makemap to create the database map.
# makemap hash /etc/mail/access.db < /etc/mail/access
Below is what my access file currently looks like and can be used as a starting point. All internal addresses have been changed except for spammers!!
# by default we allow relaying from localhost...
localhost.localdomain           RELAY
localhost                       RELAY                       RELAY

# Allow Connect from local server IPs
Connect:   OK

# Accept Mail
# accept mail from PayPal      OK

# Reject Mail     REJECT REJECT                 REJECT                     REJECT REJECT                   REJECT

# Discard Mail  DISCARD
# forum admin mails:         DISCARD

# Reject full mailbox ERROR:4.2.2:450 mailbox full REJECT

# Blacklist recipients ERROR:550 That host does not accept mail

# Spam friend domains: exempt domains from dnsbl list checking      FRIEND

# Spam friend users: exempt email users from dnsbl list checking
# example:
# Spam:user@domain.tld         FRIEND
# clients  FRIEND

# Auto REJECT via hourly cron added below

Below are more examples and explanations for reference which comes from the sendmail-cf distribution docs.
The table itself uses e-mail addresses, domain names, and network numbers as keys.
Note that IPv6 addresses must be prefaced with "IPv6:".
For example:                 REJECT                REJECT
        TLD                             REJECT
        192.168.212                     REJECT
        IPv6:2002:c0a8:02c7             RELAY
        IPv6:2002:c0a8:51d2::23f4       REJECT
would refuse mail from, any user from (or any host within the domain), any host in the entire top level domain TLD, 192.168.212.* network, and the IPv6 address 2002:c0a8:51d2::23f4. It would allow relay for the IPv6 network 2002:c0a8:02c7::/48.
The value part of the map can contain:
OK              Accept mail even if other rules in the running
                        ruleset would reject it, for example, if the domain
                        name is unresolvable.  "Accept" does not mean
                        "relay", but at most acceptance for local
                        recipients.  That is, OK allows less than RELAY.
        RELAY           Accept mail addressed to the indicated domain or
                        received from the indicated domain for relaying
                        through your SMTP server.  RELAY also serves as
                        an implicit OK for the other checks.
        REJECT          Reject the sender or recipient with a general
                        purpose message.
        DISCARD         Discard the message completely using the
                        $#discard mailer.  If it is used in check_compat,
                        it affects only the designated recipient, not
                        the whole message as it does in all other cases.
                        This should only be used if really necessary.
        SKIP            This can only be used for host/domain names
                        and IP addresses/nets.  It will abort the current
                        search for this entry without accepting or rejecting
                        it but causing the default action.
        ### any text    where ### is an RFC 821 compliant error code and
                        "any text" is a message to return for the command.
                        The string should be quoted to avoid surprises,
                        e.g., sendmail may remove spaces otherwise.
                        This type is deprecated, use one the two
                        ERROR:  entries below instead.
        ERROR:### any text
                        as above, but useful to mark error messages as such.
        ERROR:D.S.N:### any text
                        where D.S.N is an RFC 1893 compliant error code
                        and the rest as above.
For example:        ERROR:"550 We don't accept mail from spammers"   OK            RELAY
        128.32                  RELAY
        IPv6:1:2:3:4:5:6:7      RELAY
        []             OK
        [IPv6:1:2:3:4:5:6:7:8]  OK
would accept mail from, but would reject mail from all other hosts at with the indicated message. It would allow relaying mail from and to any hosts in the domain, and allow relaying from the 128.32.*.* network and the IPv6 1:2:3:4:5:6:7:* network. The latter two entries are for checks against ${client_name} if the IP address doesn't resolve to a hostname (or is considered as "may be forged"). That is, using square brackets means these are host names, not network numbers.
You can also use the access database to block sender addresses based on the username portion of the address.
For example:
FREE.STEALTH.MAILER@    ERROR:550 Spam not accepted
Note that you must include the @ after the username to signify that this database entry is for checking only the username portion of the sender address.
If you use:
then you can add entries to the map for local users, hosts in your domains, or addresses in your domain which should not receive mail:
badlocaluser@           ERROR:550 Mailbox disabled for this username       ERROR:550 That host does not accept mail     ERROR:550 Mailbox disabled for this recipient
This would prevent a recipient of, any user at, and the single address from receiving mail. Please note: a local username must be now tagged with an @ (this is consistent with the check of the sender address, and hence it is possible to distinguish between hostnames and usernames). Enabling this feature will keep you from sending mails to all addresses that have an error message or REJECT as value part in the access map. Taking the example from above:         REJECT        REJECT
Mail can't be sent to or anyone at
If using DNS Blackhole List Database via:
To avoid checking your own local domains against those blacklists, add:
Connect:10.1            OK
        Connect:       RELAY
where 10.1 is your local network. You may want to use "RELAY" instead of "OK" to allow also relaying instead of just disabling the DNS lookups in the backlists.
There is now the option to tag entries in the access map according to their type. Three tags are available:
Connect:        connection information (${client_addr}, ${client_name})
        From:           envelope sender
        To:             envelope recipient
If the required item is looked up in a map, it will be tried first with the corresponding tag in front, then (as fallback to enable backward compatibility) without any tag, unless the specific feature requires a tag.
For example:
From:spammer@some.dom   REJECT
        To:friend.domain        RELAY
        Connect:friend.domain   OK
        Connect:from.domain     RELAY
        From:good@another.dom   OK
        From:another.dom        REJECT
This would deny mails from spammer@some.dom but you could still send mail to that address even if FEATURE(`blacklist_recipients') is enabled. Your system will allow relaying to friend.domain, but not from it (unless enabled by other means). Connections from that domain will be allowed even if it ends up in one of the DNS based rejection lists. Relaying is enabled from from.domain but not to it (since relaying is based on the connection information for outgoing relaying, the tag Connect: must be used; for incoming relaying, which is based on the recipient address, To: must be used). The last two entries allow mails from good@another.dom but reject mail from all other addresses with another.dom as domain part.
By using FEATURE(`delay_checks') the rulesets check_mail and check_relay will not be called when a client connects or issues a MAIL command, respectively. Instead, those rulesets will be called by the check_rcpt ruleset; they will be skipped if a sender has been authenticated using a "trusted" mechanism, i.e., one that is defined via TRUST_AUTH_MECH(). If check_mail returns an error then the RCPT TO command will be rejected with that error. If it returns some other result starting with $# then check_relay will be skipped. If the sender address (or a part of it) is listed in the access map and it has a RHS of OK or RELAY, then check_relay will be skipped. This has an interesting side effect: if your domain is my.domain and you have
my.domain       RELAY
in the access map, then any e-mail with a sender address of will not be rejected by check_relay even though it would match the hostname or IP address. This allows spammers to get around DNS based blacklist by faking the sender address. To avoid this problem you have to use tagged entries:
To:my.domain            RELAY
        Connect:my.domain       RELAY
if you need those entries at all (class {R} may take care of them).
FEATURE(`delay_checks') can take an optional argument:
FEATURE(`delay_checks', `friend')
                 enables spamfriend test
        FEATURE(`delay_checks', `hater')
                 enables spamhater test
If such an argument is given, the recipient will be looked up in the access map (using the tag Spam:). If the argument is `friend', then the default behavior is to apply the other rulesets and make a SPAM friend the exception. The rulesets check_mail and check_relay will be skipped only if the recipient address is found and has RHS FRIEND. If the argument is `hater', then the default behavior is to skip the rulesets check_mail and check_relay and make a SPAM hater the exception. The other two rulesets will be applied only if the recipient address is found and has RHS HATER.
This allows for simple exceptions from the tests, e.g., by activating the friend option and having
Spam:abuse@     FRIEND
in the access map, mail to abuse@localdomain will get through (where "localdomain" is any domain in class {w}). It is also possible to specify a full address or an address with +detail:
Spam:abuse@my.domain    FRIEND
        Spam:me+abuse@          FRIEND
        Spam:spam.domain        FRIEND


Thursday, October 14, 2010

PHP exec mail -s

SkyHi @ Thursday, October 14, 2010
$mail_to_array = array("");

$mail_log_path = "/var/log/maillog";

echo "Producing filtered maillog..";

$generated_date_month = date("M");

$generated_date_day = date("j");

if(strlen($generated_date_day) == 1) {
        $gen_date = "$generated_date_month  $generated_date_day";
else {
        $gen_date = "$generated_date_month $generated_date_day";

$execution_string = "grep unknown $mail_log_path | grep '$gen_date' > /tmp/.unknownhack";


#mail($mail_to_array[$u], "[pot] Daily unknown users", $message_body, "From:");

#exec(mail -s "[Unknown_user_hack potato] $HOSTNAME - `date`" < /tmp/.unknownhack);

//exec(mail -s "[Unknown_user_hack potato] $HOSTNAME - `date`" < /tmp\.unknownhack);

//mail($mail_to_array[$u], "[pot] sendmail Abuse Report!", $message_body, "From:");
$command = "mail -s '[Unknown_user_hack potato] $HOSTNAME - `date`' < /tmp/.unknownhack";


echo "[error_log/pot] $HOSTNAME - `date` " > /tmp/
tail -2000 /var/log/messages > /tmp/
echo "complete." >> /tmp/
mail -s "[error_log/pot] $HOSTNAME - `date`" < /tmp/


$mail_to_array = array(",,");
//$mail_to_array = array("");

$mail_log_path = "/var/log/maillog";

echo "Producing filtered maillog..";

$generated_date_month = date("M");

$generated_date_day = date("j");

if(strlen($generated_date_day) == 1) {
        $gen_date = "$generated_date_month  $generated_date_day";
else {
        $gen_date = "$generated_date_month $generated_date_day";

$execution_string = "grep Login $mail_log_path | grep '$gen_date' > /tmp/.filteredmaillog_ipop3";


$user_access_array = array();

$fp = fopen("/tmp/.filteredmaillog_ipop3", "r");

while($line = fgets($fp)) {
        $line_explosion = explode(" ", $line);
        if(strlen($generated_date_day) == 1) {
                $user_explosion = explode("=", $line_explosion[7]);
        else {
                $user_explosion = explode("=", $line_explosion[6]);

        $username = trim($user_explosion[1]);
        if($user_access_array["$username"] == "") {
                $user_access_array["$username"] = 0;


#Daily POP3 Abuse Report from $gen_date

$message_body = "
Daily(1440 minutes in a day) POP3 and Imap Total Abuse Report from " . date("r") . "\n" .


foreach ($user_access_array as $key => $val) {
   $mail_spool_size = "0";
   $retstr = shell_exec("/bin/ls -lahS /var/spool/mail/" . $key);
   $tmpuserinfo = shell_exec("grep '$key:' /etc/passwd");
   $arrTmpUI = explode(":", $tmpuserinfo);
   $arrRetstr = explode(" ", $retstr);
   $mail_spool_size = $arrRetstr[5];
   $message_body .= "$val\t$key\t\t $mail_spool_size\t\t" . $arrTmpUI[4] . "\n";


for($u=0;$u<count($mail_to_array);$u++) {

mail($mail_to_array[$u], "[potato] Daily IPOP3 and Imap Total Abuse Report!", $message_body, "From:");

echo "mailing $mail_to_array[$u]..\n";


// old exec string exec("cat $mail_log_path | grep 'sm-mta' | grep 'from=' > /tmp/.filteredmaillog_sendmail");
$execution_string = "grep 'from=' $mail_log_path | grep '$gen_date' > /tmp/.filteredmaillog_sendmail";

$fp = fopen("/tmp/.filteredmaillog_sendmail", "r");

$from_access_array = array();

while($line = fgets($fp)) {
    $line_explosion = explode(" ", $line);
        if(strlen($generated_date_day) == 1) {
        $from_explosion = explode("=>", $line_explosion[7]);
        else {
        $from_explosion = explode("=>", $line_explosion[6]);
#       print_r($line_explosion);

        $fromaddr = trim($from_explosion[0]);
        $additional_from_explosion = explode(",", $fromaddr);
        $fromaddr = $additional_from_explosion[0];
        if($from_access_array["$fromaddr"] == "") {
                $from_access_array["$fromaddr"] = 0;


#Daily sendmail Abuse Report for $gen_date.
$message_body = "
Daily sendmail Abuse Report for " . date("r") ."\n" ."


foreach ($from_access_array as $key => $val) {
        if($val > 1) {
                $message_body .= "$val\t\t $key\n";

for($u=0;$u<count($mail_to_array);$u++) {

mail($mail_to_array[$u], "[Po]Smtp Abuse Report!", $message_body, "From:");



Wednesday, October 13, 2010

Ubuntu 10.10 codenamed Maverick Meerkat dock eye candy

SkyHi @ Wednesday, October 13, 2010
7. Eye Candy

Compiz Fusion
Compiz Fusion allows you to use advanced desktop effects such as the rotating cube desktop.

sudo apt-get install compiz compizconfig-settings-manager compiz-fusion-plugins-main \
compiz-fusion-plugins-extra emerald librsvg2-common fusion-icon

Run Applications -> System Tools -> Compiz Fusion Icon. A blue icon will appear to the tray. From here you can configure Compiz-Fusion.
Conky is a light-weight system monitor for X, that displays any information on your desktop.

sudo apt-get install conky

Screenlets are small applications that are laying on your desktop. Eye candy stuff and useful in many ways. Just type:

sudo apt-get install screenlets

Go to Applications -> Accessories –> Screenlets choose the screenlet you want click launch/add (you can choose Auto start on login)

You can download additional screenlets from or from
Cairo Dock
Cairo Dock is a light eye-candy fully themable animated dock for any Linux desktop. It has a family-likeness with OSX dock, but with more options.

sudo apt-get install cairo-dock cairo-dock-plug-ins

You will find it under Applications > Accessories > Cairo Dock
Gnome Do
GNOME Do (Do) is an intelligent launcher tool that makes performing common tasks on your computer simple and efficient. Do not only allows you to search for items in your desktop environment (e.g. applications, contacts, bookmarks, files, music), it also allows you to specify actions to perform on search results (e.g. run, open, email, chat, play).

sudo apt-get install gnome-do

You will find it under Applications > Accessories > Cairo Dock
Windows Buttons Order
A lot of users complain that the new place for the minize - maximize - close window buttons isn't good. Mwbuttons is a script that allows you to easily change the place the buttons place from left to right. To install and run it type:

chmod +x mwbuttons

Now just select Settings > Karmic style and the buttons will go to the right.

Alternatively you can use Ubuntu Tweak mentioned above.


Tuesday, October 12, 2010

FFmpeg Tricks You Should Know About

SkyHi @ Tuesday, October 12, 2010
FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library. FFmpeg is free software and is licensed under the LGPL or GPL depending on your choice of configuration options.
FFmpeg supports most of the popular formats, we don’t need to worry a lot about that. Formats supported by FFmpeg include MPEG, MPEG-4 (Divx), ASF, AVI, Real Audio/Video and Quicktime. To see a list of all the codecs/formats supported by FFmpeg, run the following command:
ffmpeg -formats

1. X11 grabbing

FFmpeg can grab the X11 display.
ffmpeg -f x11grab -s cif -i :0.0 /tmp/out.mpg
0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable.
ffmpeg -f x11grab -s cif -i :0.0+10,20 /tmp/out.mpg
0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. 10 is the x-offset and 20 the y-offset for the grabbing.
ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg

2. Convert Pictures To Movie

First, rename your pictures to follow a numerical sequence. For example, img1.jpg, img2.jpg, img3.jpg,… Then you may run:
ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg
Notice that `%d’ is replaced by the image number.
`img%03d.jpg' means the sequence `img001.jpg', `img002.jpg', etc…
If you have large number of pictures to rename, you can use the following command to ease the burden. The command, using the bourne shell syntax, symbolically links all files in the current directory that match *jpg to the `/tmp' directory in the sequence of `img001.jpg', `img002.jpg' and so on.
x=1; for i in *jpg; do counter=$(printf %03d $x); ln "$i" /tmp/img"$counter".jpg; x=$(($x+1)); done
If you want to sequence them by oldest modified first, substitute $(ls -r -t *jpg) in place of *jpg.
Then run:
ffmpeg -f image2 -i /tmp/img%03d.jpg /tmp/a.mpg
The same logic is used for any image format that ffmpeg reads.

3. Video Conversions

Quick and dirty convert to flv
ffmpeg -i inputfile.mp4 outputfile.flv
This converts any media ffmpeg handles to flash. It would actually convert anything to anything, it’s based on the file extension. It doesn’t do ANY quality control, sizing, etc, it just does what it thinks is best.
Convert .flv to .3gp
ffmpeg -i file.flv -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000 -ac 1 -ab 13 -f 3gp -y out.3gp
Download YouTube videos as .flv and convert them to .3gp for your mobile phone.
Convert AVI to iPhone MP4
ffmpeg -i [source].avi -f mp4 -vcodec mpeg4 -b 250000 -s 480?320 -acodec aac -ar 24000 -ab 64 -ac 2 [destination].mp4
for 4:3 aspect:
ffmpeg -i source-xvid.avi -s 480x320 -aspect 4:3 -b 768k -ab 64k -ar 22050 -r 30000/1001 OUT.mp4
for 16:9:
ffmpeg -i source-xvid.avi -s 480x320 -aspect 16:9 -b 768k -ab 64k -ar 22050 -r 30000/1001 OUT.mp4
Create a video that is supported by youtube:
ffmpeg -i mymovie.mpg -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv
Takes an mpeg video and coverts it to a youtube compatible flv file.
The -r 25 sets the frame rate for PAL, for NTSC use 29.97

4. Audio Conversion

Convert RM file to mp3
ffmpeg -i input.rm -acodec libmp3lame -ab 96k output.mp3
Adjust the bitrate (-ab) as necessary. If omitted FFmpeg will use a default of 64 kb/s.
Converting WMV to MP3 using FFMPEG
ffmpeg -i audio1.wmv audio1.mp3
This will convert audio1.wmv file to audio1.mp3
Converting WMV to FLV using FFMPEG

ffmpeg -i audio1.wmv audio1.flv
This will convert audio1.wmv file to audio1.flv, this will generate only audio content
Converting AMR to MP3 using FFMPEG

ffmpeg -i audio1.amr -ar 22050 audio1.mp3
This will convert audio1.amr file to audio1.mp3 having audio rate 22.05 Khz
Converting aac to mp3 using FFMPEG

ffmpeg -i audio1.aac -ar 22050 -ab 32 audio1.mp3
This will convert audio1.aac to audio1.mp3 having audio rate 22.05 Khz and Audio BitRate 32Khz
Converting aac to mp3 using FFMPEG with MetaData

ffmpeg -i audio1.aac -ar 22050 -ab 32 -map_meta_data audio1.mp3:audio1.aac audio1.mp3
This will convert audio1.aac to audio1.mp3 having audio rate 22.05 Khz and Audio BitRate 32Khz and will copy the meta data from .aac file to .mp3 file

5. Audio Extraction

ffmpeg -i video.avi -f mp3 audio.mp3
Dumping Audio stream from flv (using ffmpeg)
ffmpeg -i input.flv -f mp3 -vn -acodec copy ouput.mp3

6. Record Audio and Video from webcam

To record video run ffmpeg with arguments such as these:
ffmpeg -f video4linux2 -s 320x240 -i /dev/video0 out.mpg
To record both audio and video run ffmpeg with arguments such as these:
ffmpeg -f oss -i /dev/dsp -f video4linux2 -s 320x240 -i /dev/video0 out.mpg

7. Copy Only A Part Of Video

Cut out a piece of film from a file. Choose an arbitrary length and starting time.
ffmpeg -vcodec copy -acodec copy -i orginalfile -ss 00:01:30 -t 0:0:20 newfile
-vcodec, you choose what video codec the new file should be encoded with. Run ffmpeg -formats E to list all available video and audio encoders and file formats.
copy, you choose the video encoder that just copies the file.
-acodec, you choose what audio codec the new file should be encoded with.
copy, you choose the audio encoder that just copies the file.
-i originalfile, you provide the filename of the original file to ffmpeg
-ss 00:01:30, you choose the starting time on the original file in this case 1 min and 30 seconds into the film
-t 0:0:20, you choose the length of the new film
newfile, you choose the name of the file created.

8. Join Multiple Video Files

A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow to join video files by merely concatenating them.
Hence you may concatenate your multimedia files by first transcoding them to these privileged formats, then using the humble cat command (or the equally humble copy under Windows), and finally transcoding back to your format of choice.
mkfifo orig1.mpg
mkfifo orig2.mpg
ffmpeg -i input1.avi -sameq -y orig1.mpg
ffmpeg -i input2.avi -sameq -y orig2.mpg
Merge files
cat orig1.mpg orig2.mpg | ffmpeg -f mpeg -i - -vcodec copy -acodec copy merged.mpg
Merge and convert to avi
cat orig1.mpg orig2.mpg | ffmpeg -f mpeg -i - -sameq -vcodec mpeg4 -acodec libmp3lame merged.avi
Notice that you should either use -sameq or set a reasonably high bitrate for your intermediate and output files, if you want to preserve video quality.
Also notice that you may avoid the huge intermediate files by taking advantage of named pipes, should your platform support it:

9. Removing Synchronization Problems Between Audio and Video

ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_video.flv
This assumes that there is a 10.2 sec delay between the video and the audio (delayed).
To extract the original video into a audio and video composites look at the command on extracting audio and video from a movie
Here is more information of how to use ffmpeg: