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.
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.
There are multiple ways of specifying several date/time values in a field:
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
.---------------- 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
.
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.
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.
]]>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…
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.
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.
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 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.
Thanks to Rajesh for the aptitude screenshot.
Any other Terminal GUI application? I can only think of these at the moment. If you can think of others, comment.
]]>I have a unique problem with my firefox – and as far as I know I am the only one who has this issue. Firefox is very slow to scroll pages that has a fixed background image. Ajaxian is an example of such a site. This problem exists in all profiles of Firefox(not a extension issue) – but it works without any issue in other browsers – like Konqueror. Does anyone else have this issue?
This problem is only present in my desktop – a Fedora 8/KDE with Firefox 3.0.8 – with nVidia drivers installed. No issues on my laptop(Kubuntu). I still have no idea what’s causing this. But I did solve the issue.
I created a greasemonkey script that disables fixed background anywhere in the page. Changes all fixed background images to normal background image(scrolls with the page). Here is the script if anyone has the same issue.
Remember, this is a beta version – let me know if you find any issues with the script.
]]>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.
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.
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.
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.
If you are in gnome, there is a very easy way to do this…
You can also do this by opening the KHotKeys application.
Learn the bash keyboard shortcuts – these are the ones I use the most…
clear
command.exit
command.fg
to restore it.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'
There are a few sites that publish cool commands on a daily/semi-daily basics – subscribe to those and learn new commands…
There are some settings that are very useful if you work on the terminal a lot. Many of the cool ones are not enabled by default – this is a small list of the configuration settings that I use to make my terminal usage more productive.
This is part 3 of the Customizing the Terminal series. Already published posts in this series are…
I like to title case my folders and files’ names. The folders in my home are ‘Scripts’, ‘Documents’, ‘Temp’ etc. The first character is in upper case. But when I work on the command line, I don’t always remember to uppercase the first character when trying to cd into a folder. Consequently, the tabbing will not work. Fortunately, there is an option that auto corrects the case for you. Just open a terminal and type in this command…
shopt -s nocaseglob
Other useful shopt option are…
By default, all commands you type in are stored in the history. You can pick and chose the commands you want to store by putting the option…
export HISTCONTROL=ignorespace
in your ~/.bash_profile
file. This will make sure that bash don’t store any command beginning with the space character. So if you want bash to forget that you typed in ‘ls’, just type in ‘ ls'(<space>ls).
As I said earlier, all commands you type are stored – even the duplicate ones. You can prevent this by putting this text in your .bash_profile
file…
export HISTCONTROL=ignoredups
If you want to ignore spaced commands and want to prevent storing of duplicate commands, use the option…
export HISTCONTROL=ignoreboth
Picture this – you type in ‘ssh’ and press the ‘Page Up’ key – and bash automatically fetches the last command that starts with ssh – and completes the command for you. Well, its possible – add the following line in your ‘.bash_profile’ file…
export INPUTRC=$HOME/.inputrc
Now, create a file called .inputrc
in your home and enter this into it…
#Page up/page down
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Yes, I am aware of the up Ctrl+R trick – that comes in the next post.
You can increase or decrease the size of the history by adding this line in the .bash_profile
file…
export HISTSIZE=500
export HISTFILESIZE=500
This will limit the commands to be stored in the history to 500. If you want to remove the limit use these lines…
unset HISTSIZE
unset HISTFILESIZE
There is a good chance that this will make your history file quite huge – use with care.
Please share your configuration settings for bash in the comments.
This is part two of the ‘Customizing the Terminal’ series. Part one is ‘Customizing the Terminal: The Prompt‘. In this part, we’ll see how to create aliases to make working in the console easier.
You can create a temporary alias using this command…
alias new_name='old command'
This will stop working when you exit the terminal. If you want to make the alias permanent, put the same command in your ~/.bashrc
file.
There is another way to create an alias – create a executable file and place it in a folder in your path. This is not technically an alias – but it works the same way. I use this for alias that tend to change often. Its easier to find a file in a folder and edit it. YMMV.
This is a incomplete list of the aliases I use. Feel free to copy them to your .bashrc file.
Create an alias to jump to folders you have to visit often. This is my list…
alias www='cd /var/www/html'
alias e='cd /mnt/x'
The above jumps are absolute jumps – relative jumps are possible too…
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
Some prefer this syntax…
alias ..='cd ..'
alias ..2='cd ../..'
alias ..3='cd ../../..'
alias ..4='cd ../../../..'
If you use some commands a lot, create smaller alternative for it…
alias x='exit'
alias q='exit'
alias rmdir='rm –rf'
Many of my own scripts are also alias’ed this way…
alias bk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncBackup.pl"'
alias rbk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncRemoteBackup.pl"'
alias nbk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncNetworkBackup.pl"'
alias bdb='perl "/home/binnyva/Scripts/Perl/Maintenance/Database Backup/Dbbackup.pl"'
Create a short version of long and complex command using alias…
alias gitstat='git status | perl -pe "exit if(/Untracked files\:/)"'
alias ra='ruby script/server'
alias wikipedia='cd /mnt/x/Data/Wikipedia/mywiki; firefox "http://localhost:8001/"; python manage.py runserver 8001; '
alias sup='svn update'
and more.
When I came from Windows to Linux, I was used to the dos commands – but not to the linux’s mv,cp commands. So I used to have aliases for those(I don’t have these now)
alias move='mv'
alias copy='cp'
alias ren='mv'
alias del='rm'
If you go from Red Hat/Fedora to Debian/Ubuntu(or vise versa), you can set up a few alias to make the change easier…
alias yum='apt-get'
You can get a lot of ideas for more aliases by looking at others .bashrc files.
Now tell me you aliases…
]]>Most Linux ‘gurus’ spend a lot of time working in the terminal. If you belong to that group, this post is for you. This is a tutorial to configure the terminal prompt to the best possible value for your use. Note: This tutorial is for bash users – these instructions will not work in other shells.
You must have seen the prompt if you have use the terminal – it is the first few characters in each line. Usually, it will be…
[username@localhost] ~ $
In this case, the user is shown three piece of information in the prompt –
This post will show you how to customize this prompt to your needs.
Editing the prompt is very simple – you just have to edit a shell variable. To see the current prompt’s value, open a shell and type the command…
echo $PS1
The result will be something like this(in Ubuntu)…
binnyva@binlap:~$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
Which is functionally the same as…
\u@\h:\W\$
To edit this variable, run the command…
export PS1=<New Prompt Value>
Most desktop systems don’t need the username and hostname in the prompt – this is only relevent if your are connected to a remote system. So the first thing to do, if you are on a desktop system, is to remove those two. To do that, run the command…
export PS1="[\W]\$ "
This will change the prompt in the current terminal. To make it permanent, edit the ~/.bashrc and set the PS1 variable there. Just add this line at the end of the file…
export PS1="[\W]\$ "
Currently, the prompt has the basename of the current working directory. That is, if we are in ‘~/Sites/Lindesk/posts’, the prompt will be ‘[posts]$ ‘. This is good enough for most people. But I have a problem with this. If I go to another folder, say, ‘~/Sites/OpenJS/posts’, the prompt is still ‘[posts]$ ‘. The prompt is a bit ambiguous in this case. This can be done using a different character – in this case \w(small ‘w’ – the default was capital ‘W’).
[posts]$ export PS1="[\w]$ "
[~/Sites/OpenJS/posts]$ _
This is nice – but you will have a problem if the directory you are in is several levels deep. It might be something like this…
[/var/www/html/sites/Lindesk/lindesk.com/wp-content/plugins/eventr/langs]$ _
That’s long – and inconvenient. There are better ways of doing this.
A better way of doing this is to cut of a part of the folder – so the above path will look something like…
[/var/www/html.../eventr/langs] $ _
This option will show the first 15 characters of the path and then the last 15 characters – if the directory path is bigger than 30 characters. To enable this mode, open up the file ~/.bashrc
and add this code…
PROMPT_COMMAND='DIR=`pwd|sed -e "s!$HOME!~!"`; if [ ${#DIR} -gt 30 ]; then CurDir=${DIR:0:12}...${DIR:${#DIR}-15}; else CurDir=$DIR; fi'
PS1="[\$CurDir] \$ "
There is yet another method – I got this idea from the fish shell. In this approach, the big path will appear as…
[/v/w/h/s/L/l/w/p/e/langs] $ _
In this option, only the first character of each parent folder will be shown. Only the base folder name will be shown entirely. This is the approach I use. If you want to use this, open the ~/.bashrc
file and add this…
PROMPT_COMMAND='CurDir=`pwd|sed -e "s!$HOME!~!"|sed -re "s!([^/])[^/]+/!\1/!g"`'
PS1="[\$CurDir] \$ "
The other values you can insert into the prompt are…
Ramesh, who blogs at The Geek Stuff have released a free eBook ‘Linux 101 Hacks‘. Go download it – if you haven’t done it already.
There are total of 101 hacks in this book that will help you build a strong foundation in Linux. All the hacks in this book are explained with appropriate Linux command examples that are easy to follow.
Its kinda like my txt site on Linux Commands – except for the fact that the explanation on the book is much better than my site.
Here is a copy-paste of the table of contents for the book.
Ramesh Natarajan is the blogger behind The Geek Stuff. To know more about him and the site, take a look at the about page.
This is what he has to say about himself…
]]>My name is Ramesh Natarajan. I live in Los Angeles, California. I have been adding 1â€s and 0 â€s for more than 15 years in the IT industry. I am very much interested in anything that runs on electricity. I have done intensive programming on several languages and C is my favorite. I have done lot of work on the infrastructure side in Linux system administration, DBA, Hardware and Storage (EMC).
I have upgraded my laptop(Kubuntu 8.10) to KDE 4.2. And all is well. The laptop did not, I repeat, did not explode. As a matter of fact, its been on KDE 4.2 for the last whole week – I never got to write anything about it because of my busy schedule. For the rest of the article, I have to write ‘KDE 4.2’ lots of time. To save some time, I am going to short it to 42. Seems appropriate. So when ever you see ’42’, mentally replace it with ‘KDE 4.2’
42 looks good. And by ‘looks good’ I don’t mean all those fancy effects. I mean it’s usable – unlike its 4.x predecessors. You can actually get things done on it. You don’t have to hit save every other second because you know that the inevitable crash is just around the corner. 42 fixes most of the glaring errors in the earlier releases.
And it does look good – yes, visually this time. They really got into gradients and shadows in this release. Lots of fancy effects as well. Some of them are actually useful, to my surprise. Usually, I just ignore the shiny things – but the ‘Present Windows’ mode have changed my mind. It is a effect that actually has a use. To enable it, go to System Settings > Desktop > Desktop Effects. Now set the ‘Effect for Switching Windows’ to Present Windows.
For all you screenshot fans, here is a nice one…
Still, I have some complaints…
I am not really worried about these – I am sure the KDE team will add these soon. If they fail, there is always KDE-Look.org. If they don’t have one, well, I could always write one myself. Tinkerability is one of the main reason I love FOSS!
There is still a few bugs left – and for some reason, most of the bugs I notice seems to be in the panel side.
I have two panels – the bottom(with taskbar, system tray, pager, etc) and top panel(clock, quick launch, etc). Unfortunately, my top panel is having a lot of troubles. I cannot position the icons correctly – some widgets(like clock, quick launch, etc.) try to take up way more space that they actually need.
Also the folder view desktop mode seems to have a problem remembering the icon positions.
Again, not too worried – nothing big enough to cause me any trouble.
Even though 42 is much more stable than 4 or 4.2 beta(Nightly neon) its still has a long way to go before it can reach the reliability of KDE 3.5. Still, since I am working on a laptop and not on a server, 42 is more than enough.
Anyway, whenever 42 crashes on you, use this mantra, as I do. Just tell yourself…
]]>It could be a lot worse – I could be using Windows
As most of you know, Ext3 file system don’t have to be defragmented like the FAT32 or NTFS file systems. This is a nice feature – but this has a bad side effect as well. You cannot recover deleted files. This is a good trade-off in a server environment. Its not practical to run a defragmenter on a live server. It might take hours to complete – and disk access will not be allowed in that time. And most server environment have very strong backup mechanisms – so data recovery is not a big issue. But when it comes to the desktop environment, this is a very Bad Thing.
From a desktop user perspective, it is not a huge deal to run a defragmenter once in a while. I used to do it once every month or so when I was on windows. But accidental deletion is a huge problem as most desktop users don’t have a very strong backup system in place.
In Windows(FAT32 or NTFS) if you want a deleted file back, there are file recovery software available that might recover the file. There is a good chance of getting back the file in one piece if you try to recover the file soon. But this is not possible in Ext3 – the way the file system is designed makes it next to impossible. This is because the file system will overwrite the deleted portions – to prevent fragmentation of files. The advantage of this method is that fragmentation will be avoided. The disadvantage is, well, you will not be able to recover deleted files.
There is a very simple solution to this problem – but it is something no self respecting geek will use. The Recycle Bin. The Trash Can. Use it.
The problem is I have not seen anyone other than total newbies delete files into the Trash. Most people I know use the Shift+Delete shortcut to delete. I use a slightly different shortcut – Shift+Delete, Enter. That means I don’t even see the deletion confirmation prompt. And
I have several backup systems in place – but you know the Murphy’s law when in comes to backups…
You have a backup of everything – except the file that was deleted
So, start using the Trash – do a delete instead of a shift+delete. I would advice removing the confirmation dialog on the delete action to make it go faster. You can do it easily in Konquorer…
I am sure this is possible in Nautilus as well – but I am not sure how to do it. If any of my readers is a gnome user, please post a comment on how to do it.
One last thing – remember to clean the trash once every two days or so.
]]>