Linux Tips and Tricks

A collection of tips, tricks and everything linux

Transferring files with netcat {nc}

without comments

Why? If you ever are in the situation of being stuck behind a firewall or VPN connection and want to transfer a file from the machine inside the VPN or firewalled back to your local desktop.

On the server we’re going to pipe the output of file through cat and set netcat to listen on port 4009

# cat file-i-want-to-send.ext | nc -l 4009

On my desktop im going to open a nc session to port 4009 and redirect the output to a local file.

# nc server.ip.address 4009 > file-i-want-to-recieve.ext

And viola! you can verify the file is intact by doing a md5sum on the server and compare it to the one locally

On Server
# md5sum file-i-want-to-send.ext
# e4ef527eac8f5afe26d8464a963694ad file-i-want-to-send.ext

On Client
# md5sum file-i-want-to-recieve.ext
# e4ef527eac8f5afe26d8464a963694ad file-i-want-to-recieve.ext

Written by mnk0

February 28th, 2011 at 12:30 pm

CentOS 5.5, exim, dovecot with MySQL & SquirrelMail

without comments

So this is a little guide I pieced together from various sources on the internet, hopefully it helps someoone when making a similar setup.

Could not find these packages in the centOS repository, so grabbed these from atrpms http://packages.atrpms.net/dist/el5/exim/

# rpm --import http://packages.atrpms.net/RPM-GPG-KEY.atrpms
# yum install dovecot squirrelmail;

Setup mysql database and create tables

# mysql -u root -p
mysql> CREATE DATABASE maildb;
mysql> grant all on maildb.* to mail@localhost identified by 'mail'
mysql> flush privileges;

CREATE MYSQL TABLES

CREATE TABLE domains (
id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
fqdn VARCHAR(250) NOT NULL,
type ENUM('local','relay') NOT NULL DEFAULT 'local',
description VARCHAR(250) NULL,
active TINYINT(1) NOT NULL DEFAULT 0,
created TIMESTAMP(14) NOT NULL DEFAULT NOW(),
modified TIMESTAMP(14) NULL
);
CREATE TABLE mailboxes (
id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
domain_id INT(10) NOT NULL,
local_part VARCHAR(250) NOT NULL,
password VARCHAR(50) NULL,
description VARCHAR(250) NULL,
active TINYINT(1) NOT NULL DEFAULT 0,
created TIMESTAMP(14) NOT NULL DEFAULT NOW(),
modified TIMESTAMP(14) NULL
);
CREATE TABLE aliases (
id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
domain_id INT(10) NOT NULL,
local_part VARCHAR(250) NOT NULL,
goto VARCHAR(250) NOT NULL,
description VARCHAR(250) NULL,
active TINYINT(1) NOT NULL DEFAULT 0,
created TIMESTAMP(14) NOT NULL DEFAULT NOW(),
modified TIMESTAMP(14) NULL
);
CREATE TABLE vacations (
id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
mailbox_id INT(10) NOT NULL,
subject VARCHAR(250) NOT NULL,
body TEXT NOT NULL,
description VARCHAR(250) NULL,
active TINYINT(1) NOT NULL DEFAULT 0,
created TIMESTAMP(14) NOT NULL DEFAULT NOW(),
modified TIMESTAMP(14) NULL
);

Exim Configuration

# Auth params for mysql
hide mysql_servers = localhost/MAILDB/MYSQLUSER/MYSQLPASS
# local and relay to domains settings from mysql
domainlist local_domains = ${lookup mysql{SELECT fqdn AS domain FROM domains WHERE fqdn='${quote_mysql:$domain}' AND type='local' AND active=1}}
domainlist relay_to_domains = ${lookup mysql{SELECT fqdn AS domain FROM domains WHERE fqdn='${quote_mysql:$domain}' AND type='relay' AND active=1}}
local_delivery:
driver = appendfile
maildir_format = true
directory = /var/spool/mail/$domain/$local_part
create_directory = true
directory_mode = 0770
mode_fail_narrower = false
message_prefix =
message_suffix =
delivery_date_add
envelope_to_add
return_path_add
group = mail
mode = 0660
dovecot_delivery:
driver = appendfile
maildir_format = true
directory = /var/spool/mail/$domain/$local_part
create_directory = true
directory_mode = 0770
mode_fail_narrower = false
message_prefix =
message_suffix =
delivery_date_add
envelope_to_add
return_path_add
user = mail
group = mail
mode = 0660
auth_plain:
driver = plaintext
public_name = PLAIN
server_condition = ${lookup mysql{SELECT CONCAT(mailboxes.local_part,'@',domains.fqdn) FROM mailboxes,domains WHERE \
mailboxes.local_part=SUBSTRING_INDEX('${quote_mysql:$auth2}','@',1) AND \
mailboxes.password=MD5('${quote_mysql:$auth3}') AND \
mailboxes.active=1 AND \
mailboxes.domain_id=domains.id AND \
domains.fqdn=SUBSTRING_INDEX('${quote_mysql:$auth2}','@',-1) AND \
domains.active=1}{yes}{no}}
server_prompts = :
server_set_id = $auth2
auth_login:
driver = plaintext
public_name = LOGIN
server_condition = ${lookup mysql{SELECT CONCAT(mailboxes.local_part,'@',domains.fqdn) FROM mailboxes,domains WHERE \
mailboxes.local_part=SUBSTRING_INDEX('${quote_mysql:$auth1}','@',1) AND \
mailboxes.password=MD5('${quote_mysql:$auth2}') AND \
mailboxes.active=1 AND \
mailboxes.domain_id=domains.id AND \
domains.fqdn=SUBSTRING_INDEX('${quote_mysql:$auth1}','@',-1) AND \
domains.active=1}{yes}{no}}
server_prompts = Username:: : Password::
server_set_id = $auth1

Dovecot configuration - /etc/dovecot.conf


passdb sql {
args = /etc/dovecot-sql.conf
}
userdb passwd {
}
userdb SQL {
args = /etc/dovecot-sql.conf
}

/etc/dovecot-sql.conf

driver = mysql
connect = host=localhost dbname=maildb user=MYSQLUSER password=MYSQLPASS
default_pass_scheme = PLAIN-MD5
password_query = SELECT CONCAT(mailboxes.local_part,'@',domains.fqdn) as `user`,mailboxes.password AS `password`,'/var/spool/mail/%d/%n' AS `userdb_home`, 8 AS `userdb_uid`, 12 AS `userdb_gid` FROM `mailboxes`, `domains` WHERE mailboxes.local_part = '%n' AND mailboxes.active = 1 AND mailboxes.domain_id = domains.id AND domains.fqdn = '%d' AND domains.active = 1
user_query = SELECT '/var/spool/mail/%d/%n' AS `home`, 8 AS `uid`, 12 AS `gid`

Populating our mysql tables
INSERT INTO domains (fqdn,type,active) VALUES('my-test-site.com','local',1);
INSERT INTO mailboxes VALUES(NULL,1,'dummy',MD5('dummy'),'test',1,NOW(),NOW());

Testing configuration

# telnet 10.3.0.204 143
Trying 10.3.0.204...
Connected to 10.3.0.204.
Escape character is '^]'.
* OK Dovecot ready.
a003 LOGIN dummy@my-test-site.com dummy
a003 OK Logged in.
a004 SELECT INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 7 EXISTS
* 7 RECENT
* OK [UNSEEN 1] First unseen.
* OK [UIDVALIDITY 1296735311] UIDs valid
* OK [UIDNEXT 8] Predicted next UID
a004 OK [READ-WRITE] Select completed.

SENDING A TEST EMAIL FROM ANOTHER BOX

# telnet 10.3.0.204
HELO my-test-box.com
250 devmail Hello my-test-box.com [10.3.0.201]
MAIL FROM:me@my-test-site.com
250 OK
RCPT TO:dummy@my-test-site.com
250 Accepted
DATA
354 Enter message, ending with “.” on a line by itself
TEST MESSAGE DATA
.
250 OK id=1Pkyad-0001b7-AF

ACCESSING WEBMAIL

Load up a web browswer and type in the following address.

http://10.3.0.204/webmail

Written by mnk0

February 21st, 2011 at 10:57 am

Posted in Linux

Ubuntu 10.10 Maverick Meerkat USB install problems

without comments

I finished downloading ubuntu-10.10-desktop-i386.iso , and successfully created a USB startup disk using the utility in my 10.04 desktop. Now for some reason after trying to boot from it im faced with a boot error “Unknown keyword in configuration file” . After some googling I found a fix posted on Trent Scott’s Blog.

After creating your usb startup disk with the ubuntu 10.10 iso file, open the file syslinux.cfg in the syslinux folder.

look for the line “ui gfxboot bootlogo” and change it to “gfxboot bootlogo”.

save the file and you’re good to go.

Written by mnk0

October 13th, 2010 at 11:05 am

Posted in Linux, Ubuntu

Tagged with ,

ASRock ION 330 HTPC with Ubuntu 9.10 and XBMC

without comments

So decided to go with ASRock ION 330 dual core atom at 2.6ghz fully specd out for 1080p playback ;) Very nice package for the price and I threw a SSD in the box for no moving parts (besides the 30mm and 80mm fans ) for airflow.

Im installing Ubuntu 9.10 and XBMC, so installation of 9.10 was pretty standard, XBMC repository needs to be added to the apt sources, and this can easily be done by a few commands below.

sudo add-apt-repository ppa:team-xbmc
sudo apt-get update
sudo apt-get install xbmc xbmc-standalone

I ran into an issue of when I put a DVD disc in there was no way for me to eject it cleanly, and also took me a good ten minutes to find the location of Play DVD from the main menu, so after a bit of digging around I found a guide on XBMC forums on how to add items to the home page.

Basically to add items to the menu system with Confluence skin, you will need to edit this file
/usr/share/xbmc/skin/Confluence/720p
and find the section with the Videos and other items and add the following code

<item id="16">
<description>PLAY DVD</description>
<label>PLAY DVD</label>
<label2>PLAY DVD</label2>
<visible>System.HasMediadvd + !Skin.HasSetting(HideDVD)</visible>
<onclick>XBMC.PlayDVD()</onclick>
</item>
<item id="15">
<description>Eject</description>
<label>Eject</label>
<label2>Eject the DVD</label2>
<visible>System.HasMediadvd + !Skin.HasSetting(HideDVD)</visible>
<onclick>XBMC.EjectTray()</onclick>
</item>

Written by mnk0

April 13th, 2010 at 12:43 pm

Posted in htpc

Tagged with ,

Disk imaging with netcat and dd with ubuntu linux

with 3 comments

Want to create a disk image of a system but write it on another hard disk? This can easily be done with the help of netcat and dd.
For this example you will need two computers connected on the same network, and enough room on one machine to hold your disk image

Destination Machine

So we’ll start off this example by preparing our destination machine to listen on tcp port 4444 via netcat. The port is arbitrary so you can really pick any port that is not being used. Just have to make sure that its the same on both ends.

root@tree:~# netcat -l -p 4444 | dd of=remote-machine.img

Source Machine

Next we’ll start a dd on the source machine and pipe it to netcat on port 4444

root@leaf:~# dd if=/dev/sda1 | netcat destination-machine-ip 4444

Now sit back and wait for your image to be done, when it’s finished dd will print out its status something like

NOTE: you will have to push CTRL+C to cancel out after this is completed, as the netcat session will still be active.
root@leaf:~#
30820468+71926 records in
30867456+0 records out
15804137472 bytes (16 GB) copied, 739.395 s, 21.4 MB/s
^C

If you want to find out the status of dd during the copy theres a couple of ways to do this, open up the system monitor in Ubuntu Linux, and it should tell you the transfer rate. Launch iostat or ifstat through a terminal. Invoke a command from terminal to get dd to display the current progress .

Viola, we’ll now have a dd image of our disk or partition. I like to verify the exact size of the file matches the size output from fdisk.

Destination Machine

root@root:~# ls -la remote-machine.img
-rw-r--r-- 1 root root 15804137472 2010-02-04 10:53 remote-machine.img

Source Machine

root@leaf:~# fdisk -l /dev/sda
Disk /dev/sda: 15.8 GB, 15804137472 bytes
255 heads, 63 sectors/track, 1921 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Written by mnk0

February 4th, 2010 at 12:29 pm

Posted in Linux, Ubuntu, shell

Tagged with , , ,

Display dd progress during dd in ubuntu linux

with 2 comments

Started a dd but wondering what the progress is? I haven’t found a way to do a verbose mode for dd, but this command seems to do the trick.

Lets start off by creating a dd of /dev/sda1

mnk0@tree:~# dd if=/dev/sda1 of=my-dd.img

We’ll need to find the process number of our dd which can easily be done with the following command.

ps -ef | grep dd

we’ll get something like this

root 31733 31268 54 10:44 pts/0 00:01:55 dd of my-dd.img

Now we can run our command to find the status of this dd. Open another terminal session.

kill -SIGUSR1 31733

and looking back at our dd page we should see dd dump out a status of its current progress.

mnk0@tree:~# dd if=/dev/sda1 of=my-dd.img
12574781+40555 records in
12601304+0 records out
6451867648 bytes (6.5 GB) copied, 224.634 s, 28.7 MB/s

Written by mnk0

February 4th, 2010 at 11:45 am

Posted in Linux, Ubuntu, shell

Tagged with , ,

ubuntu 9.10 nvidia monitor settings dont save

with 3 comments

Was having the issue of not being able to save my dual monitor configuration with a default installation of 9.10. The xorg.conf seems to be unable to be parsed by nvidia-settings tool, so to get around this we can run nvidia-xconfig to reset the config file to something that it can work with.

sudo nvidia-xconfig

after that

gksudo nvidia-settings

and we can save to xorg.conf successfully.

Written by mnk0

November 5th, 2009 at 5:16 pm

Posted in Ubuntu

Tagged with ,

Data recovery the quick and easy way with ubuntu desktop linux 9.04

without comments

Ever had a failing disk? Using some hard drive recovery tools we can make salvaging our valueble data something possible.
Using dd_rescue we are going to make an image of the hard drive onto a reliable storage area, then we can run whatever filesystem recovery utilities we want.

The beauty of ddrescue is that it is fully automated and will rescue all the blocks that it can read successfully on the first pass, and with any bad blocks it will come back and retry as much as possible.

Install ddrescue tools

sudo apt-get install ddrescue

Connect the failed disk to your system

By either plugging the drive directly into system, or using one of those usb enclosure or slotted drive device you’ll need to have your failing hard disk connected and unmounted before we can begin.

sudo dd_rescue /dev/sdb disk-image.img

mnk0@earth:~$ sudo dd_rescue /dev/sdb disk-image.img
[sudo] password for mnk0:
Summary for /dev/sdb -> disk-image.img:r: 0.0k, succxfer: 228352.0k
dd_rescue: (info): ipos: 229376.0k, opos: 229376.0k, xferd: 229376.0k
errs: 0, errxfer: 0.0k, succxfer: 229376.0k
+curr.rate: 26249kB/s, avg.rate: 28391kB/s, avg.load: 13.5%

We can now mount this image on our system and take a look at the files.

mount -t ext3 -o loop disk-image.img /mnt/tmp

Written by mnk0

September 28th, 2009 at 12:09 pm

Using linux like a pro with mplayer, find & play mp3 files from command line in Ubuntu Linux 9.04 Jaunty

with 3 comments

Save precious CPU and memory by using mplayer to play mp3s, also keep your playlist file up to date with all your mp3 media files.

First and foremost we need to have mplayer installed, if your on a ubuntu-debian based system use the following command
to install mplayer, if not then you can download the appropriate packages and install them.

apt-get install mplayer

Lets make a home for our script file, and set the appropiate permissions

mkdir ~/scripts; touch ~/scripts/playme.sh; chmod +x ~/scripts/playme.sh; gedit ~/scripts/playme.sh

Paste the following code into your new script file, if you keep your Music files in a different location then change the variable musdir to match your setup.

#/bin/bash
# VARS ##########################################
tmpdir='/tmp'
musdir='/home/osamad/Music'
filename='playlist.m3u'
# CODE ##########################################
find $musdir -name '*.mp3' -o -name '*.ogg' 2>/dev/null >> $tmpdir/$filename
mplayer -playlist $tmpdir/$filename -shuffle -loop 0 -radio volume=80

playme

Using find we build a list of all our mp3s, in this case we have multiple types of media files we want to play so we can specify that by adding the -o -name flags and add them in.

  • -playlist ;flag we set the playlist file we just created
  • -shuffle ; enables shuffle mode
  • -loop 0 ; enables loop 0=forever
  • -radio volume=80 ; set the default volume to 80% (use * or / to adjust when playing)

RunTime

Push ALT+F2 or launch from a terminal

./scripts/playme.sh

playme-terminal

MORE

To find out more information, or to customize your mplayer settings

man mplayer

Create a custom launcher and run your script from the gnome-panel

Written by mnk0

May 1st, 2009 at 1:35 pm

Posted in Linux, Ubuntu, shell

Tagged with , , , ,

Gnome Do, with Docky in Ubuntu Ibex 8.10 setup guide

without comments

I recently found out about an amazingly slick desktop dock, called Gnome Do. Not only is it great looking, but its functionality is what sold me on this one. With the ability to launch any app, from the launcher simply by typing the name Gnome Do has totally converted me.

I set this up on my Ubuntu Ibex Desktop with a couple easy steps.

Adding repository to Apt

Open up a gnome-terminal window, and then lets open up the file /etc/apt/sources.list . Paste the following into your terminal.
gksudo /etc/apt/sources.list

Copy and paste the following repositories at the end of your file in gedit.
# GNOME DO ######################################################
deb http://ppa.launchpad.net/do-core/ppa/ubuntu intrepid main
deb-src http://ppa.launchpad.net/do-core/ppa/ubuntu intrepid main

Adding GPG Key to apt (Optional)

1. Open up gedit then copy and paste this PGP key to a text file, gnome-do.key and save it
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SKS 1.0.10
mI0ESXUVdQEEAN8ALfH3wueKsSgDwA/HVEHdB7nlppqGKW/tubvGTy0ayf4M9ylX45szZK97
uL9/UHh5/B7eGMSB45EMJ0/qvTiflS6SwCxRCoKCW1PpYZlVcOLh5UUBkyREPJZcki1lK7pf
xvG9LkYKnvBP89s2PnO5LlDheEsVR4SqDGEtich/ABEBAAG0JExhdW5jaHBhZCBQUEEgZm9y
IEdOT01FIERvIENvcmUgVGVhbYi2BBMBAgAgBQJJdRV1AhsDBgsJCAcDAgQVAggDBBYCAwEC
HgECF4AACgkQKKggUHdVjdCVeAP+ONJtMFx9MGSJe33YiskagXEG5cQGYdDi5sWWUAP80bP1
Qe+Dsnjs3VKQ9ZZW3M8UNXsoFFN501hgJFBwUUCWIRSGZkzVgKoZZtZOe0Dws39xfV//8JFS
Te/r0oPzrr10iTFupTe/wBR0M9JbKGdY7SvooyqU+W2rf8/LldGx7KE=
=3C2V
-----END PGP PUBLIC KEY BLOCK-----

2. Open up the Software Sources Configuration Menu, and click on the Authentication tab. Then Import Key,

Installing Gnome Do

Open up a gnome-terminal window and type

sudo apt-get update
then type
sudo apt-get install gnome-do

Removing the default gnome panel

Dont worry, you can easily bring it back, we’re just gonna hide it, push ALT+F2 or from a gnome-terminal run
gconf-editor

Navigate to ‘ Apps > Panel > TopLevels > top_panel_screen0 ‘ These are the values I changed to make it dissappear
auto_hide = checked
auto_hide_size = 1
hide_delay = 1
unhide_delay = 10000
x = 0
y = 10000

Select Docky

Launch gnome-do from the terminal or from ALT-F2
gnome-do
Right click on the Gnome Do , launcher, then click on preferences, then click on the Appearence Tab, and select Docky. Now you have a desktop that looks almost as good as mine!! :)

Check out the website for most customization, and features. http://do.davebsd.com/

Written by mnk0

March 19th, 2009 at 4:18 pm

Posted in Desktop, Linux, Ubuntu

Tagged with , , , ,