Tuesday, July 31, 2007

Using crontab scheduler

Crontab is a tool for scheduling tasks for the computer to run. It will automate the jobs that needs to be done but will be difficult to be done by human because of time limitation. There are only 4 options for crontab which are -u, -e, -l and -r and the usage is described below:

  • crontab -l - list all the crontab on standard output
  • crontab -e - edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables
  • crontab -r - remove the current crontab
  • crontab -u - specify the user
    • example: $ crontab -u username -l - this command will list the crontab belongs to the username
Crontab is set by running the crontab -e command and add the necessary time and the command to be run on that particular time. Crontab scheduling format are as below:

* * * * * command to be run

1st * is for minutes (0-59)
2nd * is for hour (0-23)
3rd * is for day of month (1-31)
4th * is for month of year (1-12)
5th * is for day of the week (0-7) where 0=Sunday and 7=Sunday

Example:
To backup your pc using rsnapshot everyday at 7.30 a.m.;
  1. $ crontab -e
  2. 30 7 * * * /usr/local/bin/rsnapshot daily
  3. save your crontab setting





Tuesday, July 24, 2007

System backup using rsnapshot

Rsnapshot is a filesystem snapshot utility that we can use for free to backup our system. To use this tool, user must have perl, ssh and rsync installed in their machine. Rsnapshot is an ideal tool for backup because it saves a lot of hard disk space. This can be done because the space needed is roughly the size of one full backup plus a copy of each additional file that is changed. The installation is also simple as shown below:

  1. install rsnapshot
    • -> yum install rcsnapshot
  2. after installation, do some setting in /etc/rsnapshot.conf . Some of the important settings are as below:
    • snapshot_root - change it to your preferred directory
    • cmd_cp - for linux user, uncomment this option
    • backup script
      • backup user@servername:/folder/to/backed-up destination/in/snapshot_root
    • interval - set this to set the frequency of snapshot to be taken. Please note that it must be arranged from smaller unit(hourly) on top to bigger one. For example:
      • interval daily 7 - this means snapshot will be taken 7 times a week
      • interval weekly 4 - this means snapshot will be taken 4 times a month
  3. Test the validation of the config file
    • -> rsnapshot configtest
  4. Test run your command
    • -> rsnapshot -t daily
  5. To backup, just run the below command(for daily)
    • -> rsnapshot daily

Friday, July 20, 2007

Setting system clock and date

To set system clock and date using command, date command can be used.
This is how to do it:

-> date mmddttttyyyy.ss where;
mm - month
dd - day
tttt - time in hours and minutes
yyyy - year
ss - seconds

For example, to set the current date to 17 July 2007, 11:15 a.m., this command below can be used:

-> date 071711152007

To see the current date, the date command without argument can be used.

-> date

Thursday, July 12, 2007

Setting default editor in ubuntu

To change the default editor for your ubuntu machine, here is the step:

  1. type:
    • $ update-alternatives --config editor
  2. Select which editor that you want to set as default by typing its number. For below example, vim(1) is chosen.



Another method to do the similar task is by using command select-editor:

1. type the command
$ select-editor
Select an editor. To change later, run 'select-editor'.
1. /usr/bin/vim.tiny
2. /bin/ed
3. /bin/nano <---- easiest

Choose 1-3 [3]:

2. Choose from the list given. In the case above, if you want vim to be your default editor, type '1' and press 'enter'

3. Finish


Tuesday, July 10, 2007

SSH without password

Using the below steps, you can ssh to the server from client without the entering any password.
The machine which run the ssh command is the client
The machine that the client access using ssh is the server

  1. Run the following command on the client
    • -> ssh-keygen -t dsa
  2. File id_dsa and id_dsa.pub will be created inside $HOME/.ssh
  3. Copy id_dsa.pub to the server's .ssh directory
    • -> scp $HOME/.ssh/id_dsa.pub user@server:/home/user/.ssh
  4. Change to /root/.ssh and create file authorized_keys containing id_dsa content
    • -> cd /home/user/.ssh
    • -> cat id_dsa >> authorized_keys
  5. Change "StrictModes yes" in /etc/ssh/sshd_config to "StrictModes no"
  6. Restart ssh server
  7. You can try ssh to the server from the client and no password will be needed
    • -> ssh user@server
Another alternative to the above steps is to use ssh-copy-id command. The steps are:
  1. Run the following command on the client
    • -> ssh-keygen -t dsa
  2. File id_dsa and id_dsa.pub will be created inside $HOME/.ssh
  3. Copy the id_dsa.pub to the server's .ssh directory
    • -> ssh-copy-id -i ~/.ssh/id_dsa.pub user@server
  4. Change "StrictModes yes" in /etc/ssh/sshd_config to "StrictModes no"
  5. Restart ssh server
  6. You can try ssh to the server from the client and no password will be needed
    • -> ssh user@server
Thanks to nailer for this information

Wednesday, July 4, 2007

Understanding Linux Runlevels

Unlike most non-unix operating system, Linux have many runlevels. They are numbered from 0-6 like below.

0 - halt
1 - Single user mode
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
3 - Full multiuser mode
4 - unused
5 - X11
6 - reboot

This list is taken from /etc/inittab file where init will find its configuration setting. The default runlevel usually is set to runlevel 5 where it is the graphical mode of linux. Halt means shutdown and runlevels 1-3 are non graphical mode. You can switch your runlevel by using;

-> init

To check your current runlevel, you can use;

-> runlevel

To view this list;

-> vi /etc/inittab