Crontab Code Generator

Written by BinnyVA on June 22, 2009 – 11:39 pm -

Time

JSL Crontab Generator is a GUI application that can be used to create new crontab entries easily. Its a Javascript application – so it will run from your browser – there is no download/install involved. This was created as a demo for my JSL Javascript Library.

crontab syntax

Each line in a crontab file is a job and follows a particular format as a series of fields, separated by spaces or tabs(see example below). Each field can have a single value or a series of values.

crontab Operators

There are multiple ways of specifying several date/time values in a field:

  • The comma(,) specifies a list of values, for example: “1,3,4,7,8”
  • The dash(-) specifies a range. Example: “1-6”, which is equivalent to “1,2,3,4,5,6”
  • The asterisk(*) operator specifies all possible values for a field. For example, an asterisk in the hour time field would be the same as ‘every hour’.

There is also an operator which some extended versions of cron support, the slash(/) operator, which can be used to skip a given number of values. For example, “*/3” in the hour time field is equivalent to “0,3,6,9,12,15,18,21”. So “*” specifies ‘every hour’ but the “*/3” means only those hours divisible by 3.

Example: the following will clear the Apache error log at one minute past midnight each day.

    01 00 * * * echo "" > /www/apache/logs/error_log

Fields

 .---------------- minute (0 - 59) 
 |  .------------- hour (0 - 23)
 |  |  .---------- day of month (1 - 31)
 |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ... 
 |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat 
 |  |  |  |  |
 *  *  *  *  *  <command to be executed>
 

For more information about the cron and crontab, run the command man cron and man crontab.

Javascript Crontab Code Generator

You can use this tool to generate the crontab commands easily. Just enter the command and the intervals it should be executed on – this tool will create a line in crontab syntax that will do the work for you. All you have to do is add the generated line to your crontab file. Once the result line is generated, run the command ‘crontab -e’ – this will open your crontab file in an editor. Just copy the generated line into this editor and save the file – you are done.

Apache Example

For example, lets say you want to clear the apache log file every day at midnight. The command to be executed is…

echo "" > /www/apache/logs/error_log

Enter that command into the command input field in the application. Next click on the ‘Choose’ radio button in the minute and set it to 0. Then select the ‘Choose’ option in Hour and set it to 12 Midnight. Live the rest as it it – we want the command to be executed every day. Now just click on the ‘Create Crontab Line’. The final crontab line will show up in the ‘Result crontab Line’ textarea.

JSL Crontab Generator


Tags: , , , , ,
Posted in Applications, Tools | 5 Comments »

Top 4 Terminal GUI Applications

Written by BinnyVA on June 19, 2009 – 1:19 am -

Terminal

Terminal GUI Apps? Does sound oxymoronic doesn’t it? Well, there are GUI apps in the terminal – and here is a tribute to ones that I find most useful…

top/htop – Process Viewer

From the man page…

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. The types of system summary information shown and the types, order and size of information displayed for tasks are all user configurable and that configuration can be made persistent across restarts.

I always have a processor load displaying applet(System Monitor) in my panel. Whenever I see a spike, I fire up a console and type in the top command – its very useful in finding which process is creating the load. Usually, it is some cron job like updatedb or makewhatis. But occasionally, I find a zombie processes this way.

htop is, for the lack of a better word, a better top. It provides a more colorful display(top has a color mode as well – open top and press ‘z’). It also makes it a bit more easier to kill processes.

htop

mc – File Manager

mc(or Midnight Commander) is a file manager. Sure you can cp and mv your files around, but after a while, it gets tiring. mc is a dual pane file manager -it means you can see two folders at the same time. You can copy/move files from one to the other, delete, rename, view file etc – in short, everything a file manager is expected to have, mc has.

mc

mpg123 – Audio Player

I am not writing too much about this – considering the fact that I have already wrote a post about mpg123/mpg321 in the audio player series.

aptitude

aptitude is a ncurces based GUI for the apt package manage – as a result, this is only available in Debian based systems(Ubuntu, Knopix, etc.). I have not yet seen anyone using aptitude – if they have a GUI system, they use synaptic – and if they are comfortable with the command line, they use apt-get command. But still, there is a middle ground – if for some reason you need it.

aptitude

Thanks to Rajesh for the aptitude screenshot.

Anything Else?

Any other Terminal GUI application? I can only think of these at the moment. If you can think of others, comment.


Tags: , , , , , , , ,
Posted in Applications, Command Line, Reviews, Tools | 12 Comments »

Customizing the Terminal: 6 Command Line Tips and Tricks

Written by BinnyVA on April 26, 2009 – 9:06 pm -

Terminal

A few tips and tricks on the terminal to make you more efficient when using it. If you know of any other tips, add it in the comments section.

1. ls Without ls

When you are trying to cd into a deep folder, you might not know the correct folder name some levels deep. You might have to do something like…

$ cd ~/Scripts/Perl
$ ls
bin	SedGUI       ToSee	Cronjobs  Maintenance
$ cd Maintenance

There is an easier way – go to the wanted folder

$ cd ~/Scripts/Perl

Now, without pressing enter, double tap the TAB key. You will get a list of files. And the command prompt waiting to be filled…

$ cd ~/Scripts/Perl/[TAB TAB]
bin	SedGUI       ToSee	Cronjobs  Maintenance
$ cd ~/Scripts/Perl/_

You can also use double-TAB to auto-complete commands.

2. Searching the history with Ctrl+R

If you have to use a command you have already used before, press CTRL+R and then type a few characters of the command. The latest command with those characters will be shown – if that is the command you want to execute, press enter and it will be executed. If not, just press CTRL+R again and it will show the next command.

You have no idea how useful this tip is if you haven’t been using it. I use this all the time.

For more details, read this article.

3. Open Terminal using a Shortcut

If you are a GUI user, chances are you prefer using a Terminal emulator(like gnome-terminal or konsole) instead of going into the Terminal mode by pressing CTRL+ALT+F1. If so, assign a shortcut to those emulator apps. I prefer using the shortcut ‘Ctrl+Alt+A’ to do this.

Gnome

If you are in gnome, there is a very easy way to do this…

  • Go to System > Preferences > Keyboard Shortcuts
  • Find ‘Run a Terminal’ – assign the shortcut ‘Ctrl+Alt+A’

KDE

  • Right Click on the K-Menu > Menu Editor
  • Find your terminal application in the list(usually System > Terminal Applications > Terminal)
  • Select the ‘Current Shortcut Key’ option and set it to ‘Ctrl+Alt+A’

You can also do this by opening the KHotKeys application.

4. Bash Keyboard Shortcuts

Learn the bash keyboard shortcuts – these are the ones I use the most…

CTRL+R
Search the history. We already talked about this.
CTRL+L
Clears the screen. Use this instead of the clear command.
CTRL+D
Use this instead of the exit command.
CTRL+C
Kill whatever is running
CTRL+Z
Puts whatever is running into a suspended background process. Use fg to restore it.

5. Find Command using apropos

Find the command you want using the apropos command. Just type in a description of the command as the first argument. For example, lets say you want to find the command to list the directory contents. Use the command…

$ apropos "directory contents"
dir                  (1)  - list directory contents
ls                   (1)  - list directory contents
ls                   (1p)  - list directory contents
ntfsls               (8)  - list directory contents on an NTFS filesystem
vdir                 (1)  - list directory contents

The only problem is that I can never spell ‘apropos’ – so I keep this in my .bashrc file…

alias apox='apropos'

6. Learn New Commands

There are a few sites that publish cool commands on a daily/semi-daily basics – subscribe to those and learn new commands…

  • Txt – Linux Commands and Code Snippets – My own site – I wrote about this a while ago.
  • commandlinefu.com
  • shell-fu
  • Bash Snippets
  • Codesnippt.com – Shell Scripts
  • bash code

  • Tags: , , , , , ,
    Posted in Command Line, Configuration, Tools | 5 Comments »

    mpg123/mpg321 – The Command Line MP3 Players

    Written by BinnyVA on February 25, 2008 – 1:25 am -

    Terminal

    So far we looked at the GUI MP3 Players for linux – like Amarok, Exile, XMMS etc. Most linux users need only that – but there are some people who want a simpler system – command line players. The two top players in this area are mpg123 and mpg321.

    mpg123

    mpg123 is a fast, free, minimalist, console MPEG audio player software program for UNIX and Linux operating systems. The development on this project ceased for a long time – but now it has a new maintainer.

    mpg321

    mpg321 is a clone of mpg123.

    Installation

    Most distros have mpg321 in their repositories(not all have mpg123) – so just log in as root and use these commands to install it…
    yum install mpg321 – For RedHat, Fedora, CentOS etc.
    OR
    apt-get install mpg321 – For Debian, Ubuntu, etc.

    Using mpg321

    Using mpg321 is straight forward. Since it has no GUI, just go to the folder with the song and just execute the command…

    mpg321 MP3_FILE_NAME

    If you want to play all the songs in a folder, you have to create a list of files in that folder. Then you have to specify this list as an argument for the mpg321 command. These commands can get the job done…

    Create a list of all MP3 Files in the current folder…

    find . -name "*.mp3"|sed 's/\.\///;'|sort>List.lst

    Use this list as the play list for mpg321

    mpg123 --list List.lst

    Why Use Command Line Players?

    If we have a number of shiny GUI players, why should one use a command line player? Unless you are an anti-GUI command line guru, chances are you don’t need it. But still, it has its uses.

    For example, if you have to restart the X Server often for some reason, then mpg321 is the best player for you. All other player will stop playing when X server is down.

    This actually happend to me – when I bought my second LCD screen, it took me some time to configure it. And that meant editing the xorg.conf file and restarting the X Server to see if it worked. At that time, I opened a virtual terminal(Ctrl+Alt+F1) and opened mpg321 with a bunch of MP3s in the list. It kept playing even if the X server is down. This is propably the reason that I was still sane after around six hours of XOrg configuration. :-)


    Tags: , , , , ,
    Posted in Audio, Command Line, Tools | 11 Comments »

    How to Mount ISO/MDF Images in Linux

    Written by BinnyVA on May 21, 2007 – 12:51 pm -

    Harddisk

    The mount command in Linux is a very powerful command. It can be used to mount any thing from a Samba mount to a ISO image file. The ability of the mount command to read ISO files makes it very useful for me.

    My brother has a habit of saving DVD films as a image file. I believe he uses Alcohol 120% to do this. If he wants to view the Film, he ‘mount’ this image using Daemon Tools. He uses windows to do this. After he is done, he hands me this image. I can mount this image without any special tools in Linux – I just need the mount command.

    mount -t iso9660 -o loop <Image_File> <Mount_Point>

    Mounting Example

    mount -t iso9660 -o loop /home/binnyva/Films/300.iso /mnt/Image

    The ‘-t’ option specifies the filetype – this is optional.

    This command works with both ISO and MDF images.


    Posted in Command Line, Tools | 25 Comments »

    fish(Friendly Interactive Shell)

    Written by BinnyVA on April 8, 2007 – 1:00 pm -

    fish(Friendly Interactive Shell) is a new shell for Linux. I tried it out and have decided to dump bash for fish. Try it out – you will come to the same conclusion as well.

    Features of fish

    Syntax Coloring

    The shell colorizes the commands as you type them – if it is a valid command it will have a green color. For example, lets say I want to see my network interfaces. Recently, I had a lot of use for that – but that is another post. So, I type ifconfig into the shell. When I am at ‘ifco’, the shell will be like this…

    Ifco - Typing completion

    When I have completed the command, ifconfig, the shell will be like this…

    Completed

    Strings, matching etc. are also highlighted as you type.

    Syntax Highlighting

    Tab Completion

    You would not think that this is a new feature. Bash has tab completion. Even Windows XP’s DOS terminal has tab completion. But fish’s tab completion is no ordinary tab completion – think of it as tab completion on steroids.

    fish’s tab completion implements a feature that I really needed – tab completion for subcommands. Subcommand is the command line argument that is given to some programs. For example,

    yum update gimp
    cvs commit file.php

    In the first example, yum is the command an ‘update‘ is the subcommand. Just type ‘yum upd’ and press Tab to complete the command. Similarly in the second case cvs is the command and commit is the subcommand.

    Many other completions are also supported…

    • Commands, both builtins, functions and regular programs.
    • Environment variable names (Eg. $HOME).
    • Usernames for tilde(~) expansion.
    • Filenames, even on strings with wildcards such as ‘*’, ‘**’ and ‘?’.
    • Job id, job name and process names for process expansion. This is very useful when using kill.

    Enough talking. You can download the fish shell from their official website. For Red Hat/Fedora Core users, this command will do the trick.

    yum install fish

    If you are a debian or Ubuntu user, use this command

    apt-get install fish


    Tags: , , ,
    Posted in Command Line, Tools | 5 Comments »