This article should continue my Linux lame articles, which I post here. I am starting to think to rename the “Hacking” category to “Lamer” :). Maybe later…
Today I had another Linux-newbie problem to solve. It’s simple, it’s newbie, and although I’m Linux user since 1994, I never had need to sove similar problems, or I never wrote my experience about such. So now I decided to write it here, and when I need it again after 5 years, I will just consult my blog ;).
The problem: I had to force SIM to erase some history files regularly. Usually, people just redirect the needed history file(s) to /dev/null, but strangeously why, my SIM-ICQ 0.9.3 was not able to accept such solution (**really** weird things started to happen with all accounts, which had their history files as links to /dev/null, so I quit trying that solution).
I had to create a script, and make it run each day on the morning. I wanted even more – I wanted cron to force all scripts, placed in given directory, to run at given time.
The really **big problem** was the fact that I was lazy to read! I wanted to solution right now in my hands, so I had to ask Veselin Kolev, one of the Linux gurus, for help. I know it’s a shame to waste experienced people time like that, but again, I was lazy to read, and Veso was online :).
He told me in few lines the solution. And here it is:
- First, I had to create the folder in my home directory. I chosed the name “.cron”, because it was looking nice to me, and it’s a hidden folder – it would not bother me when browsing my home with Konqueror;
- Now it was turn to make the script. So I did, I placed the script in that folder.
- Now it was time for root access. I modified /etc/crontab – I added the following line to it:
# `doncho` scripts
00 6 * * * doncho run-parts /home/doncho/.cron >> /dev/null 2>&1 - Now, all the scripts from directory “/home/doncho/.cron” will run each day at 6:00 AM.
During our conversation, Veso explained me how to use the “at” command for tasks, which I need to run once at given scheduled time. His brief explanations were:
- You create a script, and place it somewhere. Example – the following script (named ~/download), which downloads some site at some dir:
#!/bin/bash
wget --directory-prefix=/home/doncho/dobwload http://nana_download_server - Now we must schedule the execution using the “at” command:
at -f ~/download 23:00 05182004
- This script will run on May 18th 2004 at 23:00
- If the computer was switched off at that time, the script will run as soon as the computer gets up later, i.e. it would not be forgotten if the computer was offline when that time comes.
That’s all for today :). I hope you did not get too bored :).