Thursday, May 21, 2009

Cron and Crontab commands

The cron command starts a process that schedules command execution at specified dates and times.

crontab - maintain crontab files for individual users.Similar to other commands this to have options .
-u It specifies the name of the user whose crontab is to be tweaked.
-l The current crontab will be displayed on standard output.
-r The current crontab will be be removed.
-e This option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.

Usage :
#crontab -u [user_name] - e
An entry under crontab for user specified by the user_name will be made and saved automatically on exiting the editor.
#crontab -u [user_name] - l
Shows the cron jobs for the user specified.

The cron jobs deceleration needs to be done in a 5 column format consisting of
  1. minute (0-59)
  2. hour (0-23)
  3. day of the month (1-31)
  4. month of the year (1-12)
  5. day of the week (0-6 with 0=Sunday)
Taking the example that if the 'root' user desires to setup a cron job,which displayes massage "Hello Jack" on the user's [Jack] terminal at 01:45 AM everyday ,the process will go like this

#crontab -u jack - e
45 01 * * * /bin/echo "Hello Saurabh"
save and exit using ':wq' if using VI editor.

Viewing the cron job to edit
#crontab -u jack - l

Deleting the cronjob
#crontab -u jack - r

Shorthand at the Linux CLI

Some of the very useful shortcuts of the CLI are
  • / :- root directory
  • ./ :- current directory
  • ./command_name :- run a command in the current directory when the current directory is not on the path
  • ../ :- parent directory
  • ~ :- home directory
  • $ :- typical prompt when logged in as ordinary user
  • # :- typical prompt when logged in as root or superuser
  • ! :- repeat specified command
  • !! :- repeat previous command
  • ^^ :- repeat previous command with substitution
  • & :- run a program in background mode
  • [Tab][Tab] :- prints a list of all available commands. This is just an example of autocomplete with no restriction on the first letter.
  • x[Tab][Tab] :- prints a list of all available completions for a command, where the beginning is ``x''
  • [Alt][Ctrl][F1] :- switch to the first virtual text console
  • [Alt][Ctrl][Fn] :- switch to the nth virtual text console. Typically, there are six on a Linux PC system.
  • [Alt][Ctrl][F7] :- switch to the first GUI console, if there is one running. If the graphical console freezes, one can switch to a nongraphical console, kill the process that is giving problems, and switch back to the graphical console using this shortcut.
  • [ArrowUp] :- scroll through the command history (in bash)
  • [Shift][PageUp] :- scroll terminal output up. This also works at the login prompt, so you can scroll through your boot messages.
  • [Shift][PageDown] :- scroll terminal output down
  • [Ctrl][Alt][+] :- switch to next X server resolution (if the server is set up for more than one resolution)
  • [Ctrl][Alt][-] :- change to previous X server resolution
  • [Ctrl][Alt][BkSpc] :- kill the current X server. Used when normal exit is not possible.
  • [Ctrl][Alt][Del] :- shut down the system and reboot
  • [Ctrl]c :- kill the current process
  • [Ctrl]d :- logout from the current terminal
  • [Ctrl]s :- stop transfer to current terminal
  • [Ctrl]q :- resume transfer to current terminal. This should be tried if the terminal stops responding.
  • [Ctrl]z :- send current process to the background
  • reset :- restore a terminal to its default settings
  • [Leftmousebutton] :- Hold down left mouse button and drag to highlight text. Releasing the button copies the region to the text buffer under X and (if gpm is installed) in console mode.
  • [Middlemousebutton] :- Copies text from the text buffer and inserts it at the cursor location. With a two-button mouse, click on both buttons simultaneously. It is necessary for three-button emulation to be enabled, either under gpm or in XF86Config.