Convert .flv to .wmv using bash.

Package needed: ffmpeg

root@server:$ yum install ffmpeg

Using the command shown underneath you can convert the movie extension .flv to .wmv real easily.

user@server:$ ffmpeg -i movie.flv -vcodec wmv1 -acodec adpcm_ima_wav movie.wmv

How to get yum package update notifications via e-mail?

This will work for: Red Hat / CentOS / Fedora
For Debian / Ubuntu: Please visit this website.

My server sends me a notifications for everything what happens on the server through e-mail, the only thing I had to check manually every time were the updates / upgrades for my Linux system. I figured there should be a way to get yum-update send notifications with available upgrades. So what we are going to do now is force yum to send an email when a update or upgrade is available.

First thing we need to do is open the yum config file.

root@server:$ nano /etc/yum/yum-updatesd.conf
[main]
# how often to check for new updates (in seconds)
run_interval = 3600
# how often to allow checking on request (in seconds)
updaterefresh = 600

# how to send notifications (valid: dbus, email, syslog)
emit_via = dbus
# should we listen via dbus to give out update information/check for
# new updates
dbus_listener = yes

# automatically install updates
do_update = no
# automatically download updates
do_download = no
# automatically download deps of updates
do_download_deps = no

Add these variables, and change “email_to” to your e-mail address:

emit_via = email
# who to send the email to:
email_to = email@example.com
# who send the notifications
email_from = yumupdate@yourserver.com

Here is my working config file. You can also just copy and use this one and change the e-mail addresses.

[main]
# how often to check for new updates (in seconds)
run_interval = 3600
# how often to allow checking on request (in seconds)
updaterefresh = 600

# how to send notifications (valid: dbus, email, syslog)
emit_via = email
# who to send the email to:
email_to = email@example.com
# who send the notifications
email_from = yumupdate@yourserver.com

# should we listen via dbus to give out update information/check for
# new updates
dbus_listener = yes

# automatically install updates
do_update = no
# automatically download updates
do_download = no
# automatically download deps of updates
do_download_deps = no

After saving the file. Restart notification yum-updatesd service.

root@server:$ /etc/init.d/yum-updatesd restart

E-mail notification sample sent by yum notification.

Five ways to backup your Linux Computer or Server using bash.

Using “DD”

Make a backup of a local hard disk on remote host via ssh.

user@server:$ dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz'

Backup content of the hard drive to a file.

user@server:$ dd if=/dev/sda of=/tmp/file1

Make a copy of MBR (Master Boot Record) to floppy.

user@server:$ dd if=/dev/hda of=/dev/fd0 bs=512 count=1

Restore MBR from backup copy saved to floppy.

user@server:$ dd if=/dev/fd0 of=/dev/hda bs=512 count=1

Using “Dump”

Make a full backup of directory ‘/home’.

user@server:$ dump -0aj -f /tmp/home0.bak /home

Make a incremental backup of directory ‘/home’

user@server:$ dump -1aj -f /tmp/home0.bak /home

Restoring a backup interactively.

user@server:$ restore -if /tmp/home0.bak

Using “Rsync”

Synchronization between directories.

user@server:$ rsync -rogpav --delete /home /tmp

Rsync via SSH tunnel.

user@server:$ rsync -rogpav -e ssh --delete /home ip_address:/tmp

Synchronize a local directory with a remote directory via ssh and compression.

user@server:$ rsync -az -e ssh --delete ip_addr:/home/public /home/local

Synchronize a remote directory with a local directory via ssh and compression.

user@server:$ rsync -az -e ssh --delete /home/local ip_addr:/home/public

Using “tar”

Make a incremental backup of directory ‘/home/user’

user@server:$ tar -Puf backup.tar /home/user

For more or better ways to backup your system using tar look here.

Using “SSH”

Copy content of a directory on remote directory via ssh.

user@server:$ ( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p'

Copy a local directory on remote directory via ssh.

user@server:$ ( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p'

Local copy preserving permits and links from a directory to another.

user@server:$ tar cf - . | (cd /tmp/backup ; tar xf - )

Eight interesting Linux/Unix commands.

This command shows you information about who is logged in.

user@server:$ w

This gathers information about a domain name.

user@server:$ dig domain.com

Query DNS servers for information about domain names

user@server:$ nslookup domain.com

Ancient command to find out more information about DNS

user@server:$ whois domain.com

Find the disk usage of a file or a directory.
(-sh = better readable | -ch = the same but larger output)

user@server:$ du *
user@server:$ du -sh *
user@server:$ du -ch *

Disk freespace, pretty much self explaining but I use it with the -h switch to convert the bytes to megabytes or gigabytes

user@server:$ df
user@server:$ df -h

Find information about users.

user@server:$ finger username

Show who is logged on, and print: time of last system boot, dead processes, system login processes, active processes spawned by init, current runlevel, last system clock change.

user@server:$ who -a

How to add overlay .png image to video as logo using bash?

Using this command you can create/convert a video with your own chosen logo. Have fun.

user@server:$ ffmpeg -i movie.mpg -vhook '/usr/lib/vhook/watermark.so -f overlay.png -m 1 -t 222222' -an mm.flv

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 20091128 13:50