Pages

Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Friday, November 11, 2011

4 Easy Ways To Get Yourself Out Of a Ubuntu Crash


1. Force quit freeze apps
use System Monitor or kill syntax

2. Restart 'X'
Ctrl + Alt + Backspace

3. MagicSys Keys
Alt + SysRQ + K ... this'll kill all process

4. MagicSys Key Combination
If all the three process failed..
Alt + SysRQ .. and press R, E, I, S, U, B

and this is what R E I S U B means:
R: Switch the keyboard from raw mode to XLATE mode
E: Send the SIGTERM signal to all processes except init
I: Send the SIGKILL signal to all processes except init
S: Sync all mounted filesystems
U: Remount all mounted filesystems in read-only mode
B: Immediately reboot the system, without unmounting partitions or syncing

refs:

add:

Monday, August 22, 2011

How to check Memory Utilization by each process

If you use top in batch mode you get a list of all processes:
top -b -n 1 > list_of_processes

Before that, if you want the output sorted by memory usage you can do the following:
top
M (this sorts the output on the screen by memory usage)
W (this writes the sort settings to a configuration file ~/.toprc; this settings are used when you then start top in batch mode as described above)



http://www.unix.com/suse/112679-how-check-memory-utilization-each-process.html

Friday, June 17, 2011

Set Proxy in Linux


Terminal Proxy
If you want to configure proxy for apt-get,aptitude,wget use the following procedure
First you need to edit /etc/bash.bashrc file
gksudo gedit /etc/bash.bashrc
Add your proxy server details in the following format
export http_proxy=http://username:password@proxyhost:port/
export ftp_proxy=http://username:password@proxyhost:port/
Save and exit the file
Update the source list and you can restart your system
sudo apt-get update
http://www.ubuntugeek.com/how-to-configure-ubuntu-desktop-to-use-your-proxy-server.html

Thursday, May 19, 2011

Ubuntu SSH login delay

this is the trick:

vi /etc/ssh/sshd_config

then add:

UseDNS no

Save & reload SSH

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

Wednesday, March 16, 2011

Configure IP on Centos

Static IP

vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:0e:8f:c7
PEERDNS=YES
NETMASK=255.255.255.0
IPADDR=192.168.235.147
GATEWAY=192.168.235.1

Dynamic IP

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:0c:29:0e:8f:c7


http://www.thewebmasterscafe.net/webhosting/how-to-configure-static-ip-address-on-centos-linux.html

Friday, February 25, 2011

Installing Ajaxterm

To install Ajaxterm issue the following commands:

    wget http://antony.lesuisse.org/ajaxterm/files/Ajaxterm-0.10.tar.gz
    tar zxvf Ajaxterm-0.10.tar.gz
    cd Ajaxterm-0.10
    ./ajaxterm.py

Then point your browser to this URL : http://localhost:8022/


source: http://antony.lesuisse.org/software/ajaxterm/

Using netstat to Check Opened Ports

[root@server ssl]# netstat -tulpn


Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      14552/mysqld
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2973/portmap
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      12095/httpd
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      3342/cupsd
tcp        0      0 0.0.0.0:5432                0.0.0.0:*                   LISTEN      3670/postmaster
tcp        0      0 0.0.0.0:5434                0.0.0.0:*                   LISTEN      3645/postmaster
tcp        0      0 0.0.0.0:668                 0.0.0.0:*                   LISTEN      3030/rpc.statd
tcp        0      0 :::22                       :::*                        LISTEN      3324/sshd
tcp        0      0 :::5432                     :::*                        LISTEN      3670/postmaster
tcp        0      0 :::5434                     :::*                        LISTEN      3645/postmaster
udp        0      0 0.0.0.0:56449               0.0.0.0:*                               3572/avahi-daemon:
udp        0      0 0.0.0.0:662                 0.0.0.0:*                               3030/rpc.statd
udp        0      0 0.0.0.0:665                 0.0.0.0:*                               3030/rpc.statd
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               3572/avahi-daemon:
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               2973/portmap
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               3342/cupsd
udp        0      0 :::51891                    :::*                                    3572/avahi-daemon:
udp        0      0 :::5353                     :::*                                    3572/avahi-daemon:

Friday, January 14, 2011

Enable remote access to PostgreSQL

There are few steps:

  • Alow firewall for pgsql port and target IP 
  • Enable client authentication (pg_hba.conf)
    • host all all 10.10.29.0/24 trust
  • Allow TCP/IP socket (postgresql.conf)
    • listen_addresses='*'
    • for version upto 7.x use tcpip_socket = true
refs:

Tuesday, January 11, 2011

Using Apache's htaccess Authentication

At least there are 3 things you should do:
- set the .htaccess and .htpasswd files on target folder. This will protect access to the folder contents, including subfolders.
- configure httpd.conf [make sure AllowOverride All on <Directory "/document/root">]

this link is nice reference:
http://www.sitedeveloper.ws/tutorials/htaccess.htm

Monday, January 10, 2011

Print formatted date in shell script

#!/bin/bash
date=`date +%Y/%m/%d_%H:%M`
if tail -1 /home/asd/testlog|grep Error
then
        echo "$date | ups there's an error! restarting smsd ...">>/home/asd/cron.log;
fi

refs:

Scheduling jobs with Crontab

Crontab Commands
crontab -e    Edit your crontab file, or create one if it doesn’t already exist.
crontab -l      Display your crontab file.
crontab -r      Remove your crontab file.
crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.)
Crontab File Configuration
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
* in the value field above means all legal values as in braces for that column.
The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).
Notes
A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported.
B.) The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .
note: in Ubuntu 10.10, cron activity can be found in /var/log/syslog
reference/further read:
http://adminschoice.com/crontab-quick-reference
http://team.macnn.com/drafts/crontab_defs.html
http://perl.ericdlarson.com/crontab.html
http://www.tutorial5.com/content/view/95/51/
http://www.crontabrocks.org/
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
http://ubuntuforums.org/showthread.php?t=586478
http://www.unixgeeks.org/security/newbie/unix/cron-1.html