Archive

Archive for June, 2009

Adding/Removing Shell scripts

June 26th, 2009

Original Post From: StringOfThoughts

Adding a script

First of all write a script, say test.sh and put it in the directory /etc/init.d . Next we need to make it executable so.

$ sudo chmod +x test.sh

You can check if the script is working by issuing

$ sudo ./test.sh

Assuming the script is working as expected, to make the script run at startup / reboot.

$ sudo update-rc.d -f test.sh start 99 2 3 4 5 . // Run at startup
$ sudo update-rc.d -f test.sh start 1 0 6 .      // Run at reboot

Just a reminder there is dot (.) at the end of command. Don’t forget that!! Now you are done adding a script to run at startup.

Removing a script.

Just a reminder for new users, don’t just go to /etc/init.d and delete the script file :) that wouldn’t help and may cause you trouble. We need a nice little application called rcconf (Debian runlevel configuration tool)

$ sudo apt-get install rcconf

then run rcconf (only root can run rcconf)

$ sudo rcconf

rcconf1

The interface is very simple. It lists the scripts so all you need to do is find out where is your script and toggle “*” using space bar and then select OK. That’s all. The script is now removed but still present in the directory /etc/init.d but you can safely delete it now.

Bonus: My shell script to launch JasperServer at start up:

#!/bin/sh
/opt/jasperserver-3.1/jasperctl.sh start

Coding , , , , ,

Virtual CD/DVD Driver in Ubuntu

June 19th, 2009

Do you want a virtual CD/DVD software like MagicDisc or DAEMON Tools in Windows for your Ubuntu/Linux machine? I can introduce you an acceptable (and free) one: AcetoneISO

AcetoneISO

AcetoneISO, is a feature-rich and complete software application to manage CD/DVD images. Thanks to powerful open source tools such as fuseiso, AcetoneISO will let You mount typical proprietary images formats of the Windows world such as ISO BIN NRG MDF IMG and do plenty of other things.

- From AcetoneISO Homepage

The use of AcetoneISO is pretty easy and much similar to DAEMON Tools. Just give AcetoneISO a try, and save time of burning a CD/DVD :)

P/S: By the way, you can find some interesting information of how to mount a ISO file at UbuntuForums.

Administration, Tips , , , ,

Pidgin cannot connect to Yahoo?

June 18th, 2009

Original Post From: prash-babu.com

In case you use Yahoo with Pidgin, you may sometimes find this error saying “Could not establish a connection with the server: Error resolving scs.msg.yahoo.com. Name or service not known”. Sometimes trying to connect multiple times may solve the issue, but sometimes it may never connect. Now this can get very irritating, so there is a fix for it. If you carefully look at the error, it says “Error resolving ..”. Now this is mostly some communication problem with the pager server scs.msg.yahoo.com. So the fix is like this :

Step 1: Open Pidgin, then go to Accounts -> Add/Edit (or just press Ctrl+A)

Step 2: Then select your Yahoo account and Click on Modify

Step2

Step 3: Then Go to Advanced

Step 4: Now under Pager Server, replace scs.msg.yahoo.com with 66.163.181.166 or 66.163.181.173.

Step4

This ip you get when you ping scs.msg.yahoo.com

$ ping scs.msg.yahoo.com
PING scs.msg.yahoo.com (66.163.181.166) 56(84) bytes of data.
64 bytes from cs101.msg.mud.yahoo.com (66.163.181.166): icmp_seq=1 ttl=52 time=321 ms
64 bytes from cs101.msg.mud.yahoo.com (66.163.181.166): icmp_seq=2 ttl=51 time=320 ms
64 bytes from cs101.msg.mud.yahoo.com (66.163.181.166): icmp_seq=3 ttl=52 time=323 ms

Step 5: Now click on Save and and Enable Your yahoo account again, this time you hopefully should be able to connect. In case you still cant try the second, i have mentioned 2 IPs.

Note: Basically what you are doing is directly providing the IP address of scs.msg.yahoo.com thereby saving time and the need to resolve scs.msg.yahoo.com.

Update: If the above instruction doesn’t work with you, try to update your Pidgin version. You can check out getdeb.net or launchpad.net for the newest one.

Tips , , , ,

How to view .CHM files in Ubuntu

June 18th, 2009

Original Post From: GiannisTsakiris.com

It is easy to open and view Microsoft Compiled HTML Help files (.chm) from Ubuntu. You actually have at least two options: xchm or gnochm.

To install xchm run the following command:

$ sudo apt-get install xchm

To install gnochm run:

$ sudo apt-get install gnochm

To view a .chm file using xchm you just have to run:

$ xchm chm-file

Alternative to open it with gnochm simply run:

$ gnochm chm-file

Or in a simplier way, you can just double-click on the file’s icon.

Tips ,

MySQL error 1045 (28000): Access denied for user …

June 16th, 2009

Hello everybody,

Today, my task is configuring a MySQL server to allow connections from remote computers. The problem I has met is that although port 3306 on the router was already opened, users from internet still could not connect to my MySQL Server. Here is my error message:

tuyent@local:~$ mysql -u tuyent -p -h remote-computer
Enter password: 
ERROR 1045 (28000): Access denied for user 'tuyent'@'local' (using password: YES)

Well, here is my solution:
- Step 1: Double check that the port 3306 is already opened.
- Step 2: Open MySQL configuration file (/etc/mysql/my.cnf), comment the line

# bind-address            = 127.0.0.1

- Step 3: Restart the MySQL server

$ sudo /etc/init.d/mysql restart

- Step 4: Go to mysql command line and grant permission for user

mysql> grant all on *.* to 'tuyent'@'%' identified by 'password';
mysql> grant all on *.* to 'tuyent'@'localhost' identified by 'password';
mysql> flush privileges;

Note: Remember to grant permission on both from localhost and from anywhere (’%’ indicator), and flush all privileges.

Works fine for me :)

Administration, Coding , , , , ,

Backing Up and Restoring MySQL Database with MySQL Commands

June 15th, 2009

Original post from: devshed.com

Do you need to change your web host or switch your database server? This is probably the only time when you really think of backing up your MySQL data. If you’ve got a website with a database or your custom database running for your applications, it is imperative that you make regular backups of the database.

The easiest way to backup your database would be to telnet to the your database server machine and use the mysqldump command to dump your whole database to a backup file.

Playing with mysqldump

If you have either a shell or telnet access to your database server, you can backup the database using mysqldump. By default, the output of the command will dump the contents of the database in SQL statements to your console. This output can then be piped or redirected to any location you want. If you plan to backup your database, you can pipe the output to a sql file, which will contain the SQL statements to recreate and populate the database tables when you wish to restore your database. There are more adventurous ways to use the output of mysqldump.

A Simple Database Backup:

You can use mysqldump to create a simple backup of your database using the following syntax.

mysqldump -u [username] -p [password] [databasename] > [backupfile.sql]
  • [username] – this is your database username
  • [password] – this is the password for your database
  • [databasename] – the name of your database
  • [backupfile.sql] – the file to which the backup should be written.

The resultant dump file will contain all the SQL statements needed to create the table and populate the table in a new database server. To backup your database ‘Customers’ with the username ’sadmin’ and password ‘pass21′ to a file custback.sql, you would issue the command:

mysqldump -u sadmin -p pass21 Customers > custback.sql

You can also ask mysqldump to add a drop table command before every create command by using the option –add-drop-table. This option is useful if you would like to create a backup file which can rewrite an existing database without having to delete the older database manually first.

mysqldump --add-drop-table -u sadmin -p pass21 Customers > custback.sql

Backing up only specified tables

If you’d like restrict the backup to only certain tables of your database, you can also specify the tables you want to backup. Let’s say that you want to backup only customer_master & customer_details from the Customers database, you do that by issuing

mysqldump --add-drop-table -u sadmin -p pass21 Customers customer_master customer_details > custback.sql

So the syntax for the command to issue is:

mysqldump -u [username] -p [password] [databasename] [table1 table2 ....]
  • [tables] – This is a list of tables to backup. Each table is separated by a space.

Read more…

Administration, Coding , , ,

JavaMail – Send a HTML email with attachment using GMail’s SMTP

June 15th, 2009

After a bundle of trying and testing, here is my final version of send a HTML email with attachment using JavaMail API and GMail’s SMTP Server.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
 
public class Mail {
	public void sendMail() throws Exception {
		String SMTP_SERVER = "smtp.gmail.com";
		String SMTP_PORT = "587";
 
		final String from = "your-email@gmail.com";
		final String password = "your-password";
		String to = "your-friend@somewhere.com";
		String fileAttachment = "/path/to/attachment/file";
 
		String mailSubject = "JavaMail API with Attachment";
		String mailContent = "Hello buddy," +
				"<p>This is an example of sending an HTML email with attachment by JavaMail API.</p>" +
				"<p>Enjoy the code,</p>Your name.";
		String mailFileName = "attachment-name";
 
		// Get system properties
		Properties props = System.getProperties();
 
		// Setup mail server
		props.put("mail.smtp.host", SMTP_SERVER);
		props.put("mail.smtp.port", SMTP_PORT);
		props.put("mail.smtp.starttls.enable","true");
		props.put("mail.smtp.auth", "true");
 
		Authenticator pa = null;
		pa = new Authenticator (){
			public PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(from, password);
			}
		};
 
		// Get session
		Session session = Session.getInstance(props, pa);
 
		// Define message
		MimeMessage message = new MimeMessage(session);
		message.setFrom(new InternetAddress(from));
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
		message.setSubject(mailSubject);
 
		// create the message part 
		MimeBodyPart messageBodyPart = new MimeBodyPart();
 
		//fill message
		messageBodyPart.setContent(mailContent, "text/html");
 
		Multipart multipart = new MimeMultipart();
		multipart.addBodyPart(messageBodyPart);
 
		// Part two is attachment
		messageBodyPart = new MimeBodyPart();
		DataSource source = new FileDataSource(fileAttachment);
		messageBodyPart.setDataHandler(new DataHandler(source));
		messageBodyPart.setFileName(mailFileName);
		multipart.addBodyPart(messageBodyPart);
 
		// Put parts in message
		message.setContent(multipart);
 
		// Send the message
		Transport.send(message);
	}
 
	public static void main(String args[])  {
		try {
			new Mail().sendMail();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Tested and works like a charm ;)

Coding , , , , , ,

Linux Remote Desktop For Controlling Windows (rdesktop)

June 15th, 2009

I am responsible for couple of windows servers and windows xp workstations too. When I work from home, I need a way to get into Windows XP/2000/Vista/2003 server for work.

rdesktop

Since I have Debain Linux at home, I needed a way to login into Microsoft windows desktop from Linux OS. Many of us working at tech support use rdesktop to connect to customers’ windows XP box.

Especially it is very useful to configure Outlook or something else when customers do not understand how to configure or troubleshoot problem. This is the best way to fix a problem.

Fortunately, Linux has rdesktop utility. It is a client for remote desktop protocol (RDP), used in a number of Microsoft products including Windows NT Terminal Server, Windows 2000 Server, Windows XP and Windows 2003 Server. You do not need to install VNC server. All you need is rdesktop client on Linux or BSD workstation.

Install rdesktop

$ sudo apt-get install rdesktop

Connect to MS Windows 2000/2003 server from Linux, type the following command at a shell prompt (connect to Windows server called mw2sn100.mycorp.com)

$ rdesktop mw2sn100.mycorp.com

Or connect to windows XP/Vista workstation having IP 192.168.1.17:

$ rdesktop 192.168.1.17

Please note that you must first enable remote desktop connection under Windows Server/XP.

* Go to Windows XP Desktop
* Right Click on My Computer
* Select properties
* Select Remote tab
* Enable Remote desktop.
* Save the changes.

Make sure enterprise firewall allows incoming connection on TCP port 3389. rdesktop supports many other options, see man page of rdesktop or visit main website of rdesktop for more information.

Original Post from: cyberciti.biz

Administration , , , ,

25 Best Programmer WebComic Strips

June 15th, 2009

Original post from: Slashweb

Credit goes to XKCD, Dilbert, phd comics, codecomics and Cowbirds for the images.

#1 Exploits of a Mom

exploits_of_a_mom

#2 Sudo Make Me a Sandwich

sandwich

Read more…

Personal

SSH Tunnel + SOCKS Proxy Forwarding = Secure Browsing

June 15th, 2009

When you are at the coffee shop, or at a conference, and you are not sure that you want to send all your data over the wi-fi network in plaintext, you want a secure tunnel to browse. This happened to me recently and I stumbled across a neat feature of OpenSSH (the ssh client on everyone’s computer). The wonders of ssh never cease to amaze me!

You can use the “-D” flag of openssh to create a SOCKS proxy.

The command first:

$ ssh -D 9999 username@ip-address-of-ssh-server

This of course connects you to the server specified by “ip-address-of-ssh-server”. Needless to say, you (username) must have an ssh account on the server. In addition, this will create a SOCKS proxy on port “9999″ of your computer. This is a tunnel to the server. Now all you have to do is set the preference in Firefox to use a SOCKS proxy. The proxy is, of course, “localhost”, with the port 9999.

Now when you browse, all the connections you make to websites will seem to originate from the server to which you SSH-ed. In addition, all outgoing and incoming data for the browsing session will be encrypted since it passes through the SSH connection.

Source: Ubuntu Blog

Administration , , ,