Pages

Monday, April 18, 2011

apt-get Misc Tricks

Config Proxy:

vi /etc/apt/apt.conf


isi dg :

Acquire::http::proxy "http://10.2.164.161:8080/";
Acquire::ftp::proxy "ftp://10.2.164.161:8080/";
Acquire::https::proxy "https://10.2.164.161:8080/";


Auto-install dependencies:

after running apt-get that needs deps..

apt-get -f install

Wednesday, April 6, 2011

How to send email from the Linux command line


The Linux command line can be very powerful once you know how to use it. You can parse data, monitor processes, and do a lot of other useful and cool things using it. There often comes a need to generate a report and mail it out. It could be as simple a requirement as a notification that the day’s backup went through fine, or did not. I’ll help you get started with sending mails from the Linux command line and in shell scripts. We will also cover sending attachments from the command line. We will begin with the “mail” command.

MAIL

First run a quick test to make sure the “sendmail” application is installed and working correctly. Execute the following command, replacing “you@youremailid.com” with your e-mail address.
# mail -s “Hello world” you@youremailid.com
Hit the return key and you will come to a new line. Enter the text “This is a test from my server”. Follow up the text by hitting the return key again. Then hit the key combination of Control+D to continue. The command prompt will ask you if you want to mark a copy of the mail to any other address, hit Control+D again. Check your mailbox. This command will send out a mail to the email id mentioned with the subject, “Hello world”.
To add content to the body of the mail while running the command you can use the following options. If you want to add text on your own:
# echo “This will go into the body of the mail.” | mail -s “Hello world” you@youremailid.com
And if you want mail to read the content from a file:
# mail -s “Hello world” you@youremailid.com < /home/calvin/application.log
Some other useful options in the mail command are:
-s subject (The subject of the mail)
-c email-address (Mark a copy to this “email-address”, or CC)
-b email-address (Mark a blind carbon copy to this “email-address”, or BCC)
Here’s how you might use these options:
# echo “Welcome to the world of Calvin n Hobbes” | mail -s “Hello world” calvin@cnh.com -c hobbes@cnh.com -b susie.derkins@cnh.com

MUTT

One of major drawbacks of using the mail command is that it does not support the sending of attachments. mutt, on the other hand, does support it. I’ve found this feature particularly useful for scripts that generate non-textual reports or backups which are relatively small in size which I’d like to backup elsewhere. Of course, mutt allows you to do a lot more than just send attachments. It is a much more complete command line mail client than the “mail” command. Right now we’ll just explore the basic stuff we might need often. Here’s how you would attach a file to a mail:
# echo “Sending an attachment.” | mutt -a backup.zip -s “attachment” calvin@cnh.com
This command will send a mail to calvin@cnh.com with the subject (-s) “attachment”, the body text “Sending an attachment.”, containing the attachment (-a) backup.zip. Like with the mail command you can use the “-c” option to mark a copy to another mail id.

SENDING MAIL FROM A SHELL SCRIPT

Now, with the basics covered you can send mails from your shell scripts. Here’s a simple shell script that gives you a reading of the usage of space on your partitions and mails the data to you.
#!/bin/bash
df -h | mail -s “disk space report” calvin@cnh.com
Save these lines in a file on your Linux server and run it. You should receive a mail containing the results of the command. If, however, you need to send more data than just this you will need to write the data to a text file and enter it into the mail body while composing the mail. Here’s and example of a shell script that gets the disk usage as well as the memory usage, writes the data into a temporary file, and then enters it all into the body of the mail being sent out:
#!/bin/bash
df -h > /tmp/mail_report.log
free -m >> /tmp/mail_report.log
mail -s “disk and RAM report” calvin@cnh.com < /tmp/mail_report.log
Now here’s a more complicated problem. You have to take a backup of a few files and mail then out. First the directory to be mailed out is archived. Then it is sent as an email attachment using mutt. Here’s a script to do just that:
#!/bin/bash
tar -zcf /tmp/backup.tar.gz /home/calvin/files
echo | mutt -a /tmp/backup.tar.gz -s “daily backup of data” calvin@cnh.com
The echo at the start of the last line adds a blank into the body of the mail being set out.
This should get you started with sending mails form the Linux command line and from shell scripts. Read up the “man page” for both mail and mutt for more options.


Source: http://www.simplehelp.net/2008/12/01/how-to-send-email-from-the-linux-command-line/

Sending e-mail with attachment from command or shell prompt


If you are looking to send email with attachment via shell script or at shell prompt/command line (read as bash prompt), use mutt command.
Mutt is a small but very powerful text based program for reading electronic mail under UNIX /Linux operating systems, including support for color terminals, MIME, and a threaded sorting mode.
Please note that mutt is a pure MUA and cannot send e-mail without proper email server . You need a working Mail Transfer Agent (MTA) such as sendmail or postfix. I am assuming that you have configured email server.

Install mutt

If mutt is not installed, use apt-get or yum or up2date command as follows (login as a root user):
(A) Debian Linux / Ubuntu Linux user use following command to install mutt:
# apt-get install mutt
B) Fedora / CentOS or Red Hat Linux (RHEL) user can use following command to install mutt:
# yum install mutt
OR
# up2date mutt
C) FreeBSD user use following command to install mutt via pkg_add command:
# pkg_add -v -r mutt

How do I send email attachments from a command prompt?

1) Use mutt command as follows to send an email with attachment:
$ mutt -s "Test mail" -a /tmp/file.tar.gz vivek@nixcraft.co.in < /tmp/mailmessage.txt
Where,
  • vivek@nixcraft.co.in - is the recipient
  • /tmp/mailmessage.txt - is the main body of the e-mail (read message from the file "mailmessage.txt")
  • /tmp/file.tar.gz - is an attachment (with option -a)
  • "Test mail" - is a subject line (option -s)
See also:

Source: http://www.cyberciti.biz/tips/sending-mail-with-attachment.html

Virtualization on Linux References


http://virt-manager.et.redhat.com/index.html  The "Virtual Machine Manager" application (virt-manager for short package name) is a desktop user interface for managing virtual machines. It presents a summary view of running domains, their live performance & resource utilization statistics. The detailed view graphs performance & utilization over time. Wizards enable the creation of new domains, and configuration & adjustment of a domain's resource allocation & virtual hardware. An embedded VNC client viewer presents a full graphical console to the guest domain.

http://www.vmware.com/files/pdf/VMware_paravirtualization.pdf
http://publib.boulder.ibm.com/infocenter/lnxinfo/v3r0m0/index.jsp?topic=/liaai/kvminstall/liaaikvminstallstart.htm 

Thursday, March 31, 2011

Citrix XenServer in VirtualBox

If you just like to test out and evaluate XenServer but do not have hardware to install it on, an easy way is to just install it as a VirtualBox VM. Granted there will be no hardware virtualization support so you will not be able to build any real VMs in XenServer, but you will still be able to use XenCenter and get a feel managing a XenServer pool.

To install XenServer as a VBox VM, the VM needs to have adequate resources. I successfully tested installing XenServer 5.5u2 on a VM using Linux 2.6 template with 1GB RAM and 20GB hdd. Anything less than that will screw up the installation.

Edit: Tried to install XenServer 5.6FP1 in a VBox VM but failed miserably, installation will always hang at bootloader even though I tried with different VM memory and hdd configurations. Would like to know if anyone has better luck than me.

Edit: Finally got it installed in VBox successfully. I realized that the problem is with the console device when the installation starts and then got hung. So what I have to do is to enter "menu.c32" at the welcome screen, which shows the install options. Select "install" and press tab to edit the option.

> mboot.c32 /boot/xen.gz dom0_mem=752M com1=115200,8n1 console=com1,vga ---
/boot/vmlinuz xencons=hvc console=hvc0 console=tty0 --- install.img
The above is the original command. What I have to do is to change "console=com1,vga" to "console=tty0".
> mboot.c32 /boot/xen.gz dom0_mem=752M com1=115200,8n1 console=tty0 ---
/boot/vmlinuz xencons=hvc console=hvc0 console=tty0 --- install.img
Source: http://community.citrix.com/display/ocb/2011/01/23/XenServer+in+VirtualBox
Citrix Installation Guide: http://www.citrix.com/site/resources/dynamic/salesdocs/XenServer_Quick_Installation_Guide.pdf