Month: July 2011
Some years ago a friend of mine asked me to go over to his house to help him set up access to a Windows PC from an Ubuntu one. To cut a long and frustrating story short, we tried everything we could think of for an entire afternoon and still failed miserably. It was with a heavy heart then, that I turned to that same task again today.
I wanted to have access to a shared drive on a Windows XP laptop. I was amazed to find the answer after only a short period of Googling. These are the steps that I needed. The laptop in question is on a workgroup, and there is no password – it just boots straight up. It is attached wirelessly to the same network that my Ubuntu box is cabled onto.
I created a folder called davetest on the laptop & shared with read/write access. I checked that I could see it and that I had read/write access to it from another Windows laptop just to verify that the share was working. It was.
On my Ubuntu PC I opened a terminal and typed:
sudo apt-get install smbfs
As I understand it (and I’ll gleefully admit I’m no expert in this) SMB (Server Message Block) is a network protocol used to access such things as printers and shares between network nodes. The smbfs package allows Linux to interact with the SMB protocol via the Linux file system (hence smb fs).
I had to create a folder on the Ubuntu PC in the media folder on which the remote share would be mounted:
sudo mkdir /media/laptop
I then had to edit the fstab file:
sudo gedit /etc/fstab
I added the following line to the bottom of the file (note that this should all entered on one long line):
//<IP Address>/davetest /media/laptop cifs guest,uid=1000,iocharset=utf8,codepage=unicode,unicode 0 0
<IP Address> = IP of laptop
davetest = name of shared folder on laptop
uid = The user ID of the user who will take ownership of the mounted files
Finally I used the mount command to mount the shared folder onto the Ubuntu file system at the /media/laptop location:
sudo mount -a
I received no error messages, so I proceeded to the first and simplest test:
This listed the files in the shared folder on the Windows laptop. I experimented further and through the usual means I verified that I could copy files to the location, delete files and change files. The new file system location was accessible through the terminal windows and through Nautilus.
Makes me wonder what the deuce we were doing all those years ago, and why it was such an epic failure.
I had Cron running my recollindex job at the desired time and I had sSmtp set up to email using POP through my gmail email account. The trouble was recollindex gives a lot of output and I was being sent an email with over 22,000 lines in it each time Cron ran the job!
I checked to see if there were command line options I could pass to recollindex to make it run silently or at least more quietly. No joy – recollindex doesn’t support that type of functionality.
I could make it silent by adding a redirect to null on the crontab command line like:
15 01 * * * recollindex >/dev/null 2>&1
But that would mean there would never be any output and there’d never be an email – whether recollindex ran successfully or otherwise.
I Googled a bit and found Chronic. This is a wrapper for Cron jobs. Chronic manages the output from other programs and arranges to only display that output if the command has an error or fails. If the command succeeds, any other output will be hidden. And that means no email. So you only get an email if it doesn’t work. Perfect.
To install Chronic type the following into a terminal:
sudo apt-get install moreutils
And to use it in the crontab listing, precede the command you wish to run with chronic, like this:
15 01 * * * chronic recollindex
And to test? Set the time just a few minutes into the future and let it run. You can use top to watch the process list and see that the processes are launched. If it all works according to plan you shouldn’t get an email.
I then changed the command line again so that it would generate an error. I added an extra x to the recollindex command. Because it was spelled incorrectly Cron wouldn’t be able to find a program by that name and that would generate an error. And because there had been an error I should get an email. So I used crontab and changed the line to say:
15 01 * * * chronic recollindexx
Note the extra x. I set the time to a few minutes in the future, let the job run and then checked my email. I had an email with the following subject:
Cron <dave@Nostromo> chronic recollindexx (failed)
and the following content:
Command ‘recollindexx’ not found in /usr/bin, /bin at /usr/bin/chronic line 44
Finally – success! Cron warns me by email if recollindex fails, and only if it fails. (The last step was to go back into crontab and remove the extra x and reset the time to my desired time of 01:15.)
So. I had Recoll working fine and Cron launching recollindex every night at 01:15 to update the index. I wanted to have Cron email me to let me know that recollindex had been launched successfully each night. That was easily achieved by adding the following line to the crontab file:
I substituted my real email address for the dummy values shown here of course. That told Cron I wanted it to email me. But for Ubuntu to be able to email out it either needs to be set up as an email server or it needs to be able to authenticate against an existing external email server (like Thunderbird does). I didn’t want to have to configure an email server on my Ubuntu PC just for this, so I hunted round for ways to have it authenticate against an external mail server.
Happily, I found sSmtp. sSmtp is an extremely simple, resource conserving, SMTP server that will allow your PC to do just that. It allows processes in your PC to email out, by authenticating against an external mail server. One of my email accounts is a Google mail (gmail) account. I chose to use the gmail mail server as my external mail server.
To install sSmtp type the following into a terminal window:
sudo apt-get install ssmtp
When it had installed I used gedit to edit the ssmtp.conf file.
I added or edited the following lines:
Of course I used my real gmail email adddress details, username and password.
Then I added each account that I wanted to be able to send mail from by editing the revaliases file.
I added two lines, one for root and one for me.
Again, I used my real gmail email address and my Ubuntu local username.
Now all I had to do was configure gmail to accept POP.
Once I had done that I could test the email throughput by sending an email to one of my other accounts using the following terminal command:
sudo ssmtp email@example.com
Use a real, but different email address than your gmail one.
The message must be formatted in the following way:
Subject: Example Message
and then hit Ctrl-D. Note the blank line following the Subject: to line. Everything after that is the body of the email. Then go and check your other email account and see if the email got there. If there are any immediate issues, you will see an error message in the terminal window.
If everything has gone according to plan, you should receive the email. It all worked, and that meant that Cron would be able to email me when the recollindex program was launched each night. And that is what happened. In the wee wee hours of the morning I got an email from Cron. All 22,000 lines of it! The output from recollindex is verbose, to understate the matter somewhat.
And that’s what brought me to Chronic.
Cron is a daemon in Linux systems that runs processes at specified times. A file contains definitions of times and programs. At the specified time it runs the listed program. I wanted to use Cron to launch the recollindex program for me, once a night at 01:15 in the morning. To put entries into the Cron list, you need to use a program called crontab, which maintains the definitions files (cron tables).
You start crontab like this:
I added the following entry at the bottom of the file:
15 01 * * * recollindex
From left to right the tokens mean minutes hours day_of_month month day_of_week. The asterisks mean unrestricted. So in this example it means run the recollindex program at 01:15 every day, every month. As a test I set the time in the crontab to be a few minutes in the future and used the top command to view the running processes. By watching the process list I could see that the recollindex program was indeed launched and executed at the appropriate time. The system seemed to be working. But how would I know if it had worked every night?
By adding the line:
You can get Cron to email you when processes are complete. But that meant setting up my Ubuntu system so that applications could email out from it via an SMTP server (Simple Mail Transport Protocol).
And that brought me to sSmtp.
To help me locate an item of interest amongst the ever growing collection of documents, emails, photographs and other data files I have on my computer, I use a desktop search program. Desktop search programs create and maintain an index of the contents of your files. You can specify a word or phrase that you know is in the file and the program will display the list of files that match your search clue. You can preview or open the file from the list of matches.
A good desktop search program will go further. You should be able to specify the file types to include or exclude from a search, and which files and folders to ignore when indexing.
To be really useful the desktop search program needs to be able to burrow through the databases of other applications, such as the email store of Thunderbird, and index the data it finds there. (Actually the search in Thunderbird is very good on its own, but sometimes I need to search for something and see all matching images, documents and emails in one place.)
The program I’ve settled on in Ubuntu is called Recoll. It is very flexible, it indexes all sorts of files – and the search is fast. Recoll needs to have its index updated periodically to keep it in synch with the changing content of your files. There is a program called recollindex which updates the Recoll index. I didn’t want to have to remember to manually run recollindex, I wanted to find a way to have recollindex started automatically for me.
The answer to that was Cron.