Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. 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

Use your GPRS phone as modem in Ubuntu

'Bunch of me: Linux Redux: Use your GPRS phone as modem in Ubuntu tells how to do it.

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, 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.