January 11

Linux: Crontab

What Is Crontab?

A crontab is a simple text file that holds a list of commands that are to be run at specified times. These commands, and their related run times, are controlled by the cron daemon and are executed in the system’s background. More information can be found by viewing the crontab’s man page. We will run through a simple crontab example later.

How Does It Work?

The system maintains a crontab for each user on the system. In order to edit or create a crontab, you must use the text editor that is specified by your system. The nano text editor is the default text editor on my system. This text editor must be opened with the command crontab using the -e option. To create a crontab open a term and type:

Code:
crontab -e

The nano text editor will open with a blank window for the desired times and commands to be entered. Each line represents a seperate crontab entry – also known as a “cron job”. If you are not familiar with the nano text editor you should obtain a tutorial for it as that information is beyond the scope of this post.

Crontab Sections

Each of the sections is separated by a space, with the final section having one or more spaces in it. No spaces are allowed within Sections 1-5, only between them. Sections 1-5 are used to indicate when and how often you want the task to be executed. This is how a cron job is layed out:

minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command

Code:
01 04 1 1 1 /usr/bin/somedirectory/somecommand

The above example will run /usr/bin/somedirectory/somecommand at 4:01am on any Monday which falls on January 1st. An asterisk (*) can be used so that every instance (every hour, every weekday, every month, etc.) of a time period is used. Code:

Code:
01 04 * * * /usr/bin/somedirectory/somecommand

The above example will run /usr/bin/somedirectory/somecommand at 4:01am on every day of every month.

Comma-seperated values can be used to run more than one instance of a particular command within a time period. Dash-seperated values can be used to run a command continuously. Code:

Code:
01,31 04,05 1-15 1,6 * /usr/bin/somedirectory/somecommand

The above example will run /usr/bin/somedirectory/somecommand at 01 and 31 past the hours of 4:00am and 5:00am on the 1st through the 15th of every January and June.

The “/usr/bin/somedirectory/somecommand” text in the above examples indicates the task which will be run at the specified times. It is recommended that you use the full path to the desired commands as shown in the above examples. The crontab will begin running as soon as it is properly edited and saved.

Crontab Options

The -l option causes the current crontab to be displayed on standard output.
The -r option causes the current crontab to be removed.
The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.

After you exit from the editor, the modified crontab will be checked for accuracy and, if there are no errors, installed automatically.

Crontab Example

Below is an example of how to setup a crontab to run updatedb, which updates the slocate database: Open a term and type “crontab -e” (without the double quotes) and press enter, type the following line, substituting the full path for the one shown below, into the editor:

Code:
45 04 * * * /usr/bin/updatedb

Save your changes and exit the editor.

Crontab will let you know if you made any mistakes. The crontab will be installed and begin running if there are no errors. That’s it. You now have a cron job setup to run updatedb, which updates the slocate database, every morning at 4:45.

Note: The double-ampersand (&&) can also be used in the “command” section to run multiple commands consecutively.

Code:
45 04 * * * /usr/sbin/chkrootkit && /usr/bin/updatedb

The above example will run chkrootkit and updatedb at 4:45am daily – providing you have all listed apps installed.

I hope this little tutorial is of help to the community.

By: Ardchoille
__________________________________________________________________________

You can overwrite system editor by running

Code:
EDITOR=vi && crontab -e

replace vi with your favorite one

– To make permanent:

Just put this line in your .bashrc, if you want to use gedit (for exemple) when you type crontab -e :

Code:
export EDITOR=gedit

By: Gandolf & Frodon

Category: Linux | Comments Off on Linux: Crontab
December 16

Linux: Ubuntu 11 getting rid of the overly scroll bar

One of the following two methods should remove the poorly designed overlay scroll bar on Ubuntu 11

1. sudo su echo “export LIBOVERLAY_SCROLLBAR=0” > /etc/X11/Xsession.d/80overlayscrollbars

Restart your computer.

If the above solution doesn’t work, you can also try removing the overlay scrollbars packages:
2. sudo apt-get remove overlay-scrollbar liboverlay-scrollbar-0.1-0

Category: Linux | Comments Off on Linux: Ubuntu 11 getting rid of the overly scroll bar
December 16

Linux: How to format multiple file systems within one file?

The following requires elevated privileges

sudo aptitude install multipath-tools
sudo kpartx -a disk.img #it maps (mounts) found partitions to /dev/mapper/loop...
sudo mkfs.vfat -F 32 -n boot /dev/mapper/loop0p1
sudo mkfs.ext3 -L rootfs /dev/mapper/loop0p2
:

By: pjc50

Category: Linux | Comments Off on Linux: How to format multiple file systems within one file?
December 15

Linux: Searching for a UUID

I ran into a situation where after restoring a linux filesystem and fixing grub the UUID for the swap partition was no longer being recognized.

Using blkid and the partition dev location I was able to retrieve the new UUID and replaced the incorrect one in /etc/fstab

eg. blkid /dev/sda4
UUID=”2db3acb7-cfe7-455c-8d88-da4f00011b3d” TYPE=”swap”

Category: Linux | Comments Off on Linux: Searching for a UUID
December 8

Linux: dos2unix and unix2dos

The big question is why would you want to use unix2dos in this world of modern and advanced software?

In general the answer is you probably do not, but in some cases you might.

One key area it could quickly help is if you are working in a Linux environment that does not have X Windows.

If you open a document file that was created in Windows there is a fair chance that it look something like this:

cat test.txt
This is a test file^M
That contains the annoying mark up language^M
That works well inWindows, but not so much in Linux^M

User the command dos2unix test.txt will get you the following results:
cat test.txt
This is a test file
That contains the annoying mark up language
That works well inWindows, but not so much in Linux

unix2dos will add the carriage returns back.

Not a huge deal, but can help in a pinch sometimes.

Category: Linux | Comments Off on Linux: dos2unix and unix2dos