Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Sunday, April 06, 2008

I/O Redirection in shell or shell scripting

You will come across this situation when you want to run a process in background. Mostly, you want to capture the output or the errors thrown by the process.

As you must be already knowing, three file descriptors are available by default in any programming language. Similar is the case for a shell or shell scripting. The three are standard input (stdin), standard output (stdout) and standard error (stderr). Their corresponding file descriptors are 0, 1 and 2.

You can use these file descriptors while redirecting your input/output.

Syntax for redirection is as follows
M>N
# "M" is a file descriptor, which defaults to 1, if not explicitly set.
# "N" is a filename.
# File descriptor "M" is redirect to file "N."


Example: To redirect stdout to filename
1>filename
To redirect stderr to errorlog
2>errorlog

Another format is
M>&N
# "M" is a file descriptor, which defaults to 1, if not set.
# "N" is another file descriptor.


Example: To redirect both stderr and stdout to the same file
1>somefile 2>&1

More about I/O redirection here.

MySQL: Purge Master Logs

Binary logs sometime take up too much space on the server. I wanted space so I had to delete the database logs. They were taking up around 2GB space.

http://dev.mysql.com/doc/refman/5.0/en/purge-master-logs.html --> this link will tell you how to delete the logs.

If you want to turn off the logs, then edit /var/mysql/my.cnf on Ubuntu and comment out the following lines
  • line starting with log_bin
  • line starting with expire_log_days
  • line starting with max_binlog_size
If you want to save space and also want the logs then you can ignore commenting log_bin line and try reducing the values for expire_log_days and max_binlog_size.

expire_log_days will tell you the number of days for which the logs will be kept. If it's value is 2. Then all logs older than 2 days will be deleted.

max_binlog_size is the maximum size of the log file. If a log file reaches this limit, then a new log file will be created and appended to. Note, the old log file will not be deleted unless expire_log_days condition satisfies.

Tuesday, April 01, 2008

Move running process to background in Linux

Use the following sequence of keystrokes if you want to move a running process to background in Linux.

CTRL+Z

bg


CTRL+Z will suspend the process and the command prompt will return to you. Type bg and press enter to send the process to background.

If you want to logout but keep the process running even after logging out then type disown -a. This will detach the process and it will continue to run even if you log out.

To start a process in detached mode, use nohup command.

nohup <command to start the process>

man nohup for more details.

Wednesday, February 27, 2008

Ignoring files in subversion

Two lessons for today
  1. How to ignore files in subversion
  2. How to create a transcript
1. How to ignore files in subversion
To ignore a directory: svn propedit svn:ignore
The above command will open an editor, add the directory you want to ignore in the editor and exit from the editor. Note that the directory you are trying to ignore is not added to the repository or else it won't work.
To ignore a file: svn propedit svn:ignore
Again in the editor, add the files you want to ignore and exit. You can even use wildcards when you enter the file names. Ex: '*' to ignore all the files in the directory.

I have shown a method to ignore files using propedit. The same can be done using propset also. Details are here and here.

2. How to create a transcript

You will most probably be asked for a transcript while you are asking for help on IRC channels. Transcript is a copy of the text printed on the terminal. Whatever you have typed and whatever has been printed to the terminal by the commands that you executed.

The simplest way to create a transcript in Linux is to run the script command. After running the script command, run/type whatever commands you want to and when done, type 'exit' to stop the script. A file with the name typescript is created which will have the transcript of whatever you have done on the terminal.

Tuesday, February 19, 2008

Configuring Bluetooth on Ubuntu

This article on LinuxQuestions.org explains clearly how to configure bluetooth on Ubuntu to send/receive files to/from bluetooth devices and also how to set up bluetooth keyboard and mouse.

Few useful linux commands

- To see how long your machine has been running
$ uptime
- To see some computer stats
$ lspci
- To see system temperature and battery charge
$ acpi -t
- To see a list of all running processes
$ ps aux
- To view the current date, time and year
$ date
- For a simple calendar
$ cal
- To see what programs are running with path names
$ ps -aux
- To see your current IP address
$ ifconfig -a
- To see what your system is doing at startup
$ dmesg
- To see information about the computer users
$ finger -l

More commands later...

Saturday, February 09, 2008

Accessing ext2 or ext3 file systems on windows

Ext2 or Ext3 file systems are commonly used by the Linux operating system. Support for these file systems is not by default built in to windows operating systems.

I remember trying to access windows file systems (FAT and NTFS) from linux and linux file systems (ext2 and ext3) from windows while I was in college. Back then, there wasn't a stable driver for NTFS on linux. Drivers could read from NTFS partitions but weren't stable enought for writing to it. But now, there are drivers that can read/write to both FAT/NTFS and are pretty stable. And you can find these drivers included in linux distributions by default.

I was surprised to see the windows drives mounted automatically on ubuntu and delighted to find out that I could write to those drives. This solved half my problems of sharing data between my two operating systems - windows vista and ubuntu linux. I was further delighted after seeing the search results for "accessing ext3 from windows". I found three results useful. The first one was for Explore2fs - a GUI tool for accessing ext2/ext3 file systems from windows. I had already used this while I was in college and know it's limitations. Windows programs cannot access those file systems, and files had to be copied to a windows drive to be accessed from programs. The other two results (Ext2 file system drivers) were of much interest to me this time. I chose Stephan Schreiber's implementation and installed it on vista. This implementation comes with an installer. Can be uninstalled from Add/Remove programs. Provides the ability to mount the file systems in read only mode along with support for large files (files larger than 2GB). My linux partition was mounted as a new drive and I could access it from all windows programs just as other windows drives. Now, I no longer have to worry about where to put my data so that it can be easily accessed from both the operating systems.

FYI, the ext2 file system driver I didn't mention above was Ext2Fsd, an open source project available on sourgeforge.

Monday, February 04, 2008

How to Debug PHP with Vim and XDebug on Linux

XDebug is definitely a wonderful tool for debugging PHP. I tried using Eclipse IDE for remote debugging but it had some version conflicts and so I searched for some other IDE but I didn't imagine that Vim will turn out to be the one.

This Box.net blog tells you how to do debug PHP with Vim and XDebug on Linux.

Saturday, November 10, 2007

Java on Ubuntu

Ubuntu has GCJ installed by default. A different version of Java can be installed using the Synaptic Package Manager. Sun's Java 1.5 and 1.6 are available through the package manager.

The problem is, even after installing Sun's Java, GCJ is the default.

The default version of java can be changed using the update-java-alternatives command.

update-java-alternatives -l will give the list of all installed java packages.
example output:
java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
java-gcj 1042 /usr/lib/jvm/java-gcj


update-java-alternatives -s java-1.5.0-sun will set Sun's java as the default.

For some applications like Ant, Tomcat to run, you nee to set the JAVA_HOME environment variable like below
export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun

The above export can be put in /etc/bash.bashrc (for all users) or /home/<user>/.bashrc (for a particular user) so that JAVA_HOME is available on logon.

Wednesday, August 08, 2007

A Roundup of Free Operating Systems

By David Chisnall

Whenever people think of a free operating system (if they do), the odds are that they will think of Linux, a clone of UNIX from 1991. They also might think of one or more of the BSDs, UNIX-derivatives dating back to the early ’80s. Let’s face it, though—UNIX is pretty boring. It was great for a PDP-11, and it gets the job done now, but it’s not exactly exciting.
Fortunately, the Free Software community has some much more interesting projects which, even if they might not be as useful, are much more fun.

Complete article is here

(c) Article is provided courtesy of Prentice Hall PTR.

Wednesday, March 29, 2006

Print system information under Linux

'uname' prints information about the machine and operating system it is run on.
% uname -a

Linux localhost.localdomain 2.4.20-8 #1 Thu Mar 13 17:18:24 EST 2003 i686 athlon i386 GNU/Linux

Use this command if you want to know any of the following information
kernel name
network node hostname
kernel release
kernel version
machine hardware name
processor type
hardware platform
operating system

If you are interested in knowing information about the kernel distribution then use `cat /etc/issue` The output of which will be something as below (on Red Hat ofcourse)
Red Hat Linux release 9 (Shrike)
Kernel \r on an \m

Thursday, March 09, 2006

Proxy Settings - Enviroment Variables

Proxy can be set up using environment variables automatically for all users by creating the following file,

/etc/profile.d/proxyenv.sh
http_proxy="192.168.36.204:8080"
https_proxy="192.168.36.204:8080"
ftp_proxy="192.168.36.204:8080"

export http_proxy, https_proxy, ftp_proxy

If you are using csh instead of bash then create the following file,

/etc/profile.d/proxyenv.csh
setenv http_proxy="192.168.36.204:8080"
setenv https_proxy="192.168.36.204:8080"
setenv ftp_proxy="192.168.36.204:8080"

Reference: Unofficial ISS Linux Web Pages