1. check the current version you use:
"uname -r"
2. see all the installed kernel images in your system:
"ls /boot/vmlinuz*"
3. remove the old kernels:
"sudo apt-get remove linux-image-[version]-generic"
4. update the grub
"sudo update-grub"
my memo
2011年2月2日 星期三
2010年9月15日 星期三
Sending email with attachments via a SSL smtp server by java
1. First you need to download the library "javamail". Please download and extract it. There should be a file "mail.jar" in it. Setting the environment variable CLASSPATH to $CLASSPATH:/your_dir/mail.jar
2. You may(or may not) need to download the certification of your smtp and put it to the trust list. Please refer to this page http://blogs.sun.com/andreas/entry/no_more_unable_to_find . And get the InstallCert.java here: http://blogs.sun.com/andreas/resource/InstallCert.java
3. Refering to the program shown below:
====
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.security.*;
public class SendFileMail {
public static void main (String [] args) {
// some parameters
String to = "the target";
String from = "your email address";
final String username = "your email address on the smtp server";
final String pass = "your password of your smtp server";
String host = "your smtp server name";
int port = 465; // for SSL, it is usually 465
// SSL setting
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// setting the certification
// only need this line for adding the certification of your smtp server to the trust list
System.setProperty("javax.net.ssl.trustStore", "jssecacerts");
// setting the properties
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
properties.setProperty("mail.smtp.socketFactory.fallback", "false");
properties.setProperty("mail.smtp.port", Integer.toString(port));
properties.setProperty("mail.smtp.socketFactory.port", Integer.toString(port));
properties.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(properties,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication () {
return new PasswordAuthentication(username, pass);
}
});
// create the message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("The Subject");
Multipart multipart = new MimeMultipart();
// adding the text message
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("text body");
multipart.addBodyPart(messageBodyPart);
// adding a file
messageBodyPart = new MimeBodyPart();
String file_name = "the file name";
DataSource source = new FileDataSource(file_name);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(file_name);
multipart.addBodyPart(messageBodyPart);
// send message
message.setContent(multipart);
Transport.send(message);
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
====
2. You may(or may not) need to download the certification of your smtp and put it to the trust list. Please refer to this page http://blogs.sun.com/andreas/entry/no_more_unable_to_find . And get the InstallCert.java here: http://blogs.sun.com/andreas/resource/InstallCert.java
3. Refering to the program shown below:
====
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.security.*;
public class SendFileMail {
public static void main (String [] args) {
// some parameters
String to = "the target";
String from = "your email address";
final String username = "your email address on the smtp server";
final String pass = "your password of your smtp server";
String host = "your smtp server name";
int port = 465; // for SSL, it is usually 465
// SSL setting
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// setting the certification
// only need this line for adding the certification of your smtp server to the trust list
System.setProperty("javax.net.ssl.trustStore", "jssecacerts");
// setting the properties
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
properties.setProperty("mail.smtp.socketFactory.fallback", "false");
properties.setProperty("mail.smtp.port", Integer.toString(port));
properties.setProperty("mail.smtp.socketFactory.port", Integer.toString(port));
properties.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(properties,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication () {
return new PasswordAuthentication(username, pass);
}
});
// create the message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("The Subject");
Multipart multipart = new MimeMultipart();
// adding the text message
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("text body");
multipart.addBodyPart(messageBodyPart);
// adding a file
messageBodyPart = new MimeBodyPart();
String file_name = "the file name";
DataSource source = new FileDataSource(file_name);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(file_name);
multipart.addBodyPart(messageBodyPart);
// send message
message.setContent(multipart);
Transport.send(message);
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
====
2010年6月22日 星期二
Some useful EC2 command line tools
Since the AWS web console crashes so frequently, using ec2 command line tools is neccessary.
Some useful usage of command line tools:
Look up the AMIs:
where_your_ec2_certifications/ec2-describe-images -o YOUR_12_DIGITS_ACCOUNT_NUMBER
Start up an Instances:
where_your_ec2_certifications/ec2-run-instances AMI_ID -k KEY_PAIR_NAME -g SECURITY_GROUP_NAME
Describe the Status of Instances:
where_your_ec2_certifications/ec2-describe-instances
Terminate an Instance:
where_your_ec2_certifications/ec2-terminate-instances i-xxxxxxxx (your instance id)
My Reference:
http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
Some useful usage of command line tools:
Look up the AMIs:
where_your_ec2_certifications/ec2-describe-images -o YOUR_12_DIGITS_ACCOUNT_NUMBER
Start up an Instances:
where_your_ec2_certifications/ec2-run-instances AMI_ID -k KEY_PAIR_NAME -g SECURITY_GROUP_NAME
Describe the Status of Instances:
where_your_ec2_certifications/ec2-describe-instances
Terminate an Instance:
where_your_ec2_certifications/ec2-terminate-instances i-xxxxxxxx (your instance id)
My Reference:
http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
2010年6月7日 星期一
Creating your own Amazon Machine Image (AMI) on Elastic Compute Cloud (EC2)
Creating your own Amazon Machine Image (AMI) on Elastic Compute Cloud (EC2)
Two References I Read:
1. http://www.philsergi.com/2009/10/customizing-ec2-ami.html
2. http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
Before Everything You Sart:
You need a AWS account. I assume that you already have one.
Download the Amazon EC2 API Tools:
Download it by google or "wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip".
Note that the following sections just provides some solutions work for me.
You may have your own solutions with/without this tool set.
After unzipping the tool set, create a dir "~/.ec2" and moving everything to here.
Create/Modify "~/.bash_profile":
This should be done on your LOCAL machine.
Please open the file "~/.bash_profile" and add these lines:
====
export EC2_HOME=$HOME/.ec2
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=$EC2_HOME/pk-xxxxxx.pem
export EC2_CERT=$EC2_HOME/cert-xxxxxx.pem
export JAVA_HOME=/usr/lib/jvm/java-6-sun
====
Note that you need to change your shell to be bash. You can use "chsh" to change your longin shell to bash.
Note that the pathes shown above are just examples. Please specify your pathes.
I will explain how to get pk-xxxxxx.pem and cert-xxxxxx.pem in coming section.
Once you acquire these file, you need to replace the "xxxxxx" to your code.
Acquiring X.509 Certifications and Key Pairs:
You need to go to the "Security Credentials" page.
https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key
For X.509 Certifications, got to "Access Credentials" section, the "X.509 Certificates" tag and create a new Certificates.
Then you can download the certification and private key. They are the pk-xxxxxx.pem and cert-xxxxxx.pem.
For the key pair, you can just go to the AWS console and create one.
https://console.aws.amazon.com/ec2/home
Go the the "NETWORKING & SECURITY" section, "Key Pairs" tag, create one, and download another .pem file.
Launch an Instance:
Please Lauch an Instance. You can do it via AWS console.
Please select the key pair name which is the same as the one you just created.
Wait for the status of the instance to be "running" and ssh to the "public DNS".
SSH to the Instance:
My solution is using putty. Please specify the authentication under "SSH -> Auth".
The file you should specify is the "key pairs" .pem file.
Upload the pk-xxxxxx.pem and cert-xxxxxx.pem to the instance. You can use arbitrary way. My solution is using sftp command.
Then do "cp pk-xxxxxx.pem /mnt" and "cp cert-xxxxxx.pem /mnt".
Bundle the Customized AMI:
Please do this on EC2 Instance:
ec2-bundle-vol -d /mnt -k /mnt/pk-xxxxxx.pem -c /mnt/cert-xxxxxx.pem -u aws_account_id-s 10240 -r i386
For the aws_account_id, it is a 12 digits number. You can find it by logging into AWS and going to personal information page.
It is your account-number.
Upload AMI Bundle To S3:
Please do this on EC2 Instance:
ec2-upload-bundle -b bucket_name_key -m /mnt/image.manifest.xml -a access_key_id -s secret_access_key;
You can find the access_key_id and secret_access_key id on "Security Credentials".
http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
Go to the "Access Credentials" section and "Access Keys" tag.
Register the AMI:
You can do this on LOCAL machine:
ec2-register bucket_name_key/image.manifest.xml
But, in fact, you can do it on AWS console.
Go the the AMI tag and register the AMI. Note that the bucket_name_key should be the exactly same with the name you specify in the "Upload AMI Bundle To S3" step.
Two References I Read:
1. http://www.philsergi.com/2009/10/customizing-ec2-ami.html
2. http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
Before Everything You Sart:
You need a AWS account. I assume that you already have one.
Download the Amazon EC2 API Tools:
Download it by google or "wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip".
Note that the following sections just provides some solutions work for me.
You may have your own solutions with/without this tool set.
After unzipping the tool set, create a dir "~/.ec2" and moving everything to here.
Create/Modify "~/.bash_profile":
This should be done on your LOCAL machine.
Please open the file "~/.bash_profile" and add these lines:
====
export EC2_HOME=$HOME/.ec2
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=$EC2_HOME/pk-xxxxxx.pem
export EC2_CERT=$EC2_HOME/cert-xxxxxx.pem
export JAVA_HOME=/usr/lib/jvm/java-6-sun
====
Note that you need to change your shell to be bash. You can use "chsh" to change your longin shell to bash.
Note that the pathes shown above are just examples. Please specify your pathes.
I will explain how to get pk-xxxxxx.pem and cert-xxxxxx.pem in coming section.
Once you acquire these file, you need to replace the "xxxxxx" to your code.
Acquiring X.509 Certifications and Key Pairs:
You need to go to the "Security Credentials" page.
https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key
For X.509 Certifications, got to "Access Credentials" section, the "X.509 Certificates" tag and create a new Certificates.
Then you can download the certification and private key. They are the pk-xxxxxx.pem and cert-xxxxxx.pem.
For the key pair, you can just go to the AWS console and create one.
https://console.aws.amazon.com/ec2/home
Go the the "NETWORKING & SECURITY" section, "Key Pairs" tag, create one, and download another .pem file.
Launch an Instance:
Please Lauch an Instance. You can do it via AWS console.
Please select the key pair name which is the same as the one you just created.
Wait for the status of the instance to be "running" and ssh to the "public DNS".
SSH to the Instance:
My solution is using putty. Please specify the authentication under "SSH -> Auth".
The file you should specify is the "key pairs" .pem file.
Upload the pk-xxxxxx.pem and cert-xxxxxx.pem to the instance. You can use arbitrary way. My solution is using sftp command.
Then do "cp pk-xxxxxx.pem /mnt" and "cp cert-xxxxxx.pem /mnt".
Bundle the Customized AMI:
Please do this on EC2 Instance:
ec2-bundle-vol -d /mnt -k /mnt/pk-xxxxxx.pem -c /mnt/cert-xxxxxx.pem -u aws_account_id
For the aws_account_id, it is a 12 digits number. You can find it by logging into AWS and going to personal information page.
It is your account-number.
Upload AMI Bundle To S3:
Please do this on EC2 Instance:
ec2-upload-bundle -b bucket_name_key -m /mnt/image.manifest.xml -a access_key_id -s secret_access_key;
You can find the access_key_id and secret_access_key id on "Security Credentials".
http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
Go to the "Access Credentials" section and "Access Keys" tag.
Register the AMI:
You can do this on LOCAL machine:
ec2-register bucket_name_key/image.manifest.xml
But, in fact, you can do it on AWS console.
Go the the AMI tag and register the AMI. Note that the bucket_name_key should be the exactly same with the name you specify in the "Upload AMI Bundle To S3" step.
2010年2月21日 星期日
kill a process on a specific port
For example, to kill a process on port 9999, first using
"lsof -w -n -i tcp::9999"
or
"fuser -n tcp 9999"
to inspect the process on the port. Then using "kill -9 pid" to eliminate it.
2008年6月25日 星期三
Get host name in perl script.
Situation:
Want to get the host name which the perl script running on.
====
Solution:
The macro `hostname` helps us to get host name.
Note that `hostname` is not 'hostname'. You need to use `, the key which also send ~ on keyboard.
i.e.
$host_name = `hostname`;
Want to get the host name which the perl script running on.
====
Solution:
The macro `hostname` helps us to get host name.
Note that `hostname` is not 'hostname'. You need to use `, the key which also send ~ on keyboard.
i.e.
$host_name = `hostname`;
Get the script location, full name rather than working directory.
Situation:
Want to get the location of the script rather than the working directory.
For example, there is a perl script "C:\ooxx\xxoo\aabb.pl". You want to get the directory "C:\ooxx\xxoo".
====
Solution:
For code,
If you at "C:" and give the command "C:\ooxx\xxoo\aabb.pl", then the current working directory would be "C:".
To get "C:\ooxxx\xxoo", the location of the script, just use
at the start of the code. When the script just start, the $0 stores the script's full path, that is "C:\ooxx\xxoo\aabb.pl". You can derive the location of the script from the script's full name.
Want to get the location of the script rather than the working directory.
For example, there is a perl script "C:\ooxx\xxoo\aabb.pl". You want to get the directory "C:\ooxx\xxoo".
====
Solution:
For code,
use Cwd; $workingDir = getcwd; |
If you at "C:" and give the command "C:\ooxx\xxoo\aabb.pl", then the current working directory would be "C:".
To get "C:\ooxxx\xxoo", the location of the script, just use
$theSciptFullName = $0; |
at the start of the code. When the script just start, the $0 stores the script's full path, that is "C:\ooxx\xxoo\aabb.pl". You can derive the location of the script from the script's full name.
訂閱:
文章 (Atom)