Linux
Some random Linux tips: mutt 127 exec error and rsync operation not supported error
I’ve been fixing a few issues with my Linux server recently and had to search to find the fixes, so I though I’d post the fixes here.
Up until about a week ago, I was using ssmtp as my mail server to allow my Ubuntu server to email me certain things. It uses the gmail ssmtp server to send me mail. It was working fine for about a year, but suddenly stopped working recently, so I thought I would sort the problem out. I ended up removing ssmtp and installing postfix, which now is installed by default on ubuntu systems, using the guide from here. It worked very well, except my default user wasn’t able to send email using the default mail client I was using (mutt). I kept on getting the same error: Error sending message, child exited 127 (Exec error.)
It turns out I had a .muttrc file in my home folder, from an earlier failed attempt to set up an email server that had some stupid settings, most noticeably a sendmail setting. I simply deleted the .muttrc file and the above error went away.
However, it turned out that installing postfix meant that my server started emailing me whenever cron ran a job from /etc/crontab. Which in some cases was every two minutes! So, I found out that simply adding: " >/dev/null 2>&1 " to the end of every entry would stop the results being emailed to me.
This turned out to be quite useful, since cron emailed me with the results of my daily back up, that uses rsync, saying that it had failed with litteraly hundreds of the following error: /bin/cp: cannot create link Operation not supported some more googling revealed that this usually occurs when cp (copy) is trying to make a symlink on a disk that does not support symlinks, such as a Windows formatted NTFS disk. This was exactly my situation, so I simply reformatted my backup disk using gparted as ext3 and now rsync is much happier.
Automount a drive in Ubuntu
I wrote this as a post on XBMC forum, but I thought I should share the wealth. The following is a guide to automounting a drive in a minimal install of Ubuntu with no GUI or desktop, only CLI access.
To manually get a minimal install of Ubuntu to auto-mount a USB drive at boot:
First off, you need command line access (also called The Terminal) to your installation and also you need to boot WITHOUT your USB drive connected. So, shutdown your box and then disconnect your USB drive. Now restart the box. Then, when XBMC has loaded, press Alt and F7 together, which should bring up a new Terminal screen with a log in.
Then log in using your username and password that you set up when you installed Ubuntu.
Next you need to type the following:
tail -f /var/log/syslog
This basically prints out the system log as it changes. Once you have typed this, plug in your USB drive. You should see a load of new stuff being printed in your terminal, this is the Ubuntu system recognising and loading your USB drive (though not mounting it). You should see something like this:
Jan 8 13:13:34 xpuntu kernel: [ 1671.616121] usb 2-2: new high speed USB device using ehci_hcd and address 5
Jan 8 13:13:34 xpuntu kernel: [ 1671.750917] usb 2-2: configuration #1 chosen from 1 choice
Jan 8 13:13:34 xpuntu kernel: [ 1671.752477] scsi6 : SCSI emulation for USB Mass Storage devices
Jan 8 13:13:34 xpuntu kernel: [ 1671.752815] usb-storage: device found at 5
Jan 8 13:13:34 xpuntu kernel: [ 1671.752820] usb-storage: waiting for device to settle before scanning
Jan 8 13:13:39 xpuntu kernel: [ 1676.753513] usb-storage: device scan complete
Jan 8 13:13:39 xpuntu kernel: [ 1676.754606] scsi 6:0:0:0: Direct-Access WDC WD16 00AABB-56PUA0 7H00 PQ: 0 ANSI: 2 CCS
Jan 8 13:13:39 xpuntu kernel: [ 1676.755793] sd 6:0:0:0: Attached scsi generic sg2 type 0
Jan 8 13:13:39 xpuntu kernel: [ 1676.756402] sd 6:0:0:0: [sdb] 312581808 512-byte logical blocks: (160 GB/149 GiB)
Jan 8 13:13:39 xpuntu kernel: [ 1676.757163] sd 6:0:0:0: [sdb] Write Protect is off
Jan 8 13:13:39 xpuntu kernel: [ 1676.757171] sd 6:0:0:0: [sdb] Mode Sense: 00 38 00 00
Jan 8 13:13:39 xpuntu kernel: [ 1676.757176] sd 6:0:0:0: [sdb] Assuming drive cache: write through
Jan 8 13:13:39 xpuntu kernel: [ 1676.761108] sd 6:0:0:0: [sdb] Assuming drive cache: write through
Jan 8 13:13:39 xpuntu kernel: [ 1676.761119] sdb: sdb1
Jan 8 13:13:39 xpuntu kernel: [ 1676.774572] sd 6:0:0:0: [sdb] Assuming drive cache: write through
Jan 8 13:13:39 xpuntu kernel: [ 1676.774583] sd 6:0:0:0: [sdb] Attached SCSI disk
You want to look out for the reference to “[sd*]“, in my case it is [sdb]. This is the name that Ubuntu has given to your USB drive.
Next stop the tail command, so press:
Ctrl and C
This stops the tail command, then type the following:
sudo blkid
You will have to enter your password. This should give you something like the following:
/dev/sda1: UUID="1024B74F24B73696" TYPE="ntfs"
/dev/sda5: UUID="015273a3-e1a8-4d53-867f-ffec83b3df60" TYPE="swap"
/dev/sda6: UUID="50b2512a-4d07-4a83-860e-be608a5b2cb7" TYPE="ext4"
/dev/sdb1: LABEL="" UUID="48D3-B1C9" TYPE="vfat"
What you see should be different from this. This basically lists all the drives attached to your system, alongside two important pieces of info, the drives UUID number and what the drive is formatted as. You need to find the reference to the “sd*” that you found out earlier, so in my case it is /dev/sdb1. Then, make a note of the UUID number and the TYPE as well, in my case it is vfat.
So, now we know where our USB drive is and what it is called.
Next, we want to tell Ubuntu to automount it each time it boots.
So, you need to edit the /etc/fstab file that tells Ubuntu what drives to mount at boot. Be careful here, don’t delete or change anything that is already in this file, since it will stop your device from booting. It is ok to add new stuff to this file however. To be safe, we shall make a backup of the /etc/fstab file, just incase we mess up. If we do mess up, simple copy this backup over the /etc/fstab file and reboot and everything will be back as we found it. So, to make a backup simple type:
sudo cp /etc/fstab /etc/fstabackup
This copies the /etc/fstab file to /etc/fstabackup, which we can use as a backup.
To edit the /etc/fstab file, you need to use the command line Text editor called Vi ([url]http://en.wikipedia.org/wiki/Vi[/url] and [url]http://www.cs.colostate.edu/helpdocs/vi.html[/url]) I would recommend reading about it first, since it is a bit of an arse to use in Terminal mode.
Start Vi to edit your file using:
sudo vi /etc/fstab
Use your arrow keys to move down to the very end of the file. Then press “a” to Append stuff to the end of the file. Press Return to start a new line and then type the following:
UUID=YOURUUIDNUMBERHERE /home/xbmc/usb vfat defaults 0 0
Add your own UUID number after the = and change the TYPE if yours wasn’t vfat. /home/xbmc/usb is where you will be mounting your USB drive, this can be anything you want, but to make your life easy, since XBMC defaults to showing your home directory in the file browser, put it under your home directory, so in my case, the main user on my box is xbmc, so I use /home/xbmc/usb.
Press Enter again after typing that, then press Escape, then press and hold Shift and press Z twice, this saves and exits Vi.
Next, you need to make the folder that the drive will be mounted in, so type:
mkdir /home/xbmc/usb
Replace /home/xbmc/usb with whatever you put in the /etc/fstab file earlier.
Finally, that is it. Hopefully, if all went well, you can now simply reboot, with your USB drive attached, and the drive will be found at /home/xbmc/usb which you can navigate to from XBMC.
Best of luck!!
Getting Conky and Ubuntu 9.04 to play nice
Ever since the most recent upgrade to Ubuntu (9.04) my conky installation just has not been happy. I am guessing it is something to do with the fancy desktop effects provided by Compiz, and until there is a fix, you kinda have to implement a hack.
First, the only way to ensure that conky doesn’t overlay ALL your windows, is to use these settings in your .conkyrc:
# Create own window instead of using desktop (required in nautilus)
own_window yes
# If own_window is yes, you may use type normal, desktop or override
own_window_type override
Then, you need to create a little script that you run each time you boot up your computer. The script has to say:
killall conky
conky
Run this script after the computer has booted up, and conky behaves nicely, and stays on the desktop as it is meant to.
If anyone has a better solution than this then give me a shout, but this is the only way I have found of getting conky to not sit on top of everything else, not blank out all icon on the desktop, or not completley dissapear
fsck.ext3: Bad magic number in super-block
So, every so often after upgrading my Ubuntu server, I occasionally get an error during boot, saying the following:
fsck.ext3: Superblock invalid, trying backup blocks…
fsck.ext3: Bad magic number in super-block while trying to open /dev/sdc1
fsck died with exit code 8
After some rooting around, it turns out to be an error on my part. It is all down to my /etc/fstab file (a text file which tells Ubuntu how and where to mount all the hard drives in your system). A while ago, Ubuntu changed the way it records drives details, whereas it use to use /dev/sdX to refer to a drive (with X being a-z) it now uses UUIDs instead. These are unique ID numbers that the system gives to a drive. It changed from /dev/sdX to UUID since occasionally the sdX number would change upon a reboot.
This was exactly what was happening to me. In my fstab file I used /dev/sdc1 to refer to one USB hard drive, and a UUID to refer to another. fstab correctly mounted the UUID drive, but the /dev/sdc1 had changed from the original USB drive it referred to, to the same USB drive that I mounted via the UUID number, thus it failed to mount. When fsck (Ubuntu’s file checking program) runs, it uses fstab to find out info about the hard drives you have. If you have a situation like mine where two entries where referring to the same hard drive, fsck freaks out and dies, thus the error.
To fix this, you need to edit your fstab. Now, if you are lucky, you can simply type EXIT at the prompt you get when this error occurs and the system will boot up. If not, I’d recommend using an Ubuntu LiveCD to boot up the system and then edit your fstab file.
So, open /etc/fstab in a text editor, make sure you use a user with the correct privileges to do this. Then, open a command prompt and type
sudo fdisk -l
This will list all your hard drives, allowing you to identify them. Next, type:
sudo blkid
This will list all your hard drives and their UUID numbers.
Using the info from the first command, fdisk and the UUID number from the second command, blkid, you can work out which device has which UUID number. Then make sure in your /etc/fstab file, you refer to devices using UUID=XXXXXXXXXXXXXXX instead of /dev/sdXX.
This way, your disks will always mount correctly and you shouldn’t get anymore fsck errors on boot, well until your hard drive dies lol!
Finding missing packages when building from source on Ubuntu
So, you are building a program from source on Ubuntu and you have run into dependency issues, what do you do?
One solution is to use apt-file. Install this with sudo apt-get install apt-file. Then run apt-file update to update it’s cache. Now, you can use it to search for your missing dependencies by running apt-file search mymissingfile.so (replace mymissingfile.so with whatver you want) and it will show you what packages provide that dependency. The go ahead and install that package to solve your problems, it even shows you where that dependency is installed to!
Bluetooth controlled motion start-up script
So, after messing with ZoneMinder and creating a bluetooth script for it, I am now messing with motion instead, and have modified the script accordingly.
For kicks, I have hosted it on google code
http://code.google.com/p/bluetoothmotion/
It also details a fix for the problem with motion on Ubuntu and the /etc/init.d/motion stratup script.
motion 1 zoneminder 0
So, after messing around with ZoneMinder for a few weeks, I finally gave up. I then decided to try out motion instead, which I had heard a lot about, but largely ignored because it didn’t have a fancy website or nice looking web GUI.
Oh how wrong I was. Motion is so much better than ZoneMinder, I am sorry to say. It has a very basic web interface, allowing you to start and stop motion detection and view a live stream from one camera at a time. However, it really beats ZoneMinder into a cocked hat when you look at support for webcams. I had so many problems getting my webcams working in ZoneMinder, but in motion, you just tell it your video device locations (/dev/video0 etc) and off it goes.
There are some additional php packages out there allowing you to create webcam stream montages and view previous alerts created by motion. Although all configuration is done via a text config file, the file is well laid out and well commented and thus easy to understand.
I would highly recommend motion over ZoneMinder and am using it now as my main geek project. I am thus updating my bluetooth script to work with motion and will post the new version soon.
Turn programs on and off with Bluetooth in Ubuntu
Having recently been messing around with ZoneMinder for home security, I wanted to turn on and off the program using Bluetooth. Basically, the idea being that when I am around, the server will sense my presence (no Darth Vadar jokes please
) via the Bluetooth on my phone and turn off ZoneMinder. Then, if I leave the location of the server, it will no longer be able to sense Bluetooth on my phone and thus will turn on ZoneMinder.
So, I hunted around for such a program, I came across bluemon and BlueProximity, but they both only worked on proximity, i.e. they relied on you being near by, as far as I could tell, there was no option of running an action when the phone was completely unavailable.
So, I decided to write my own script to do what I wanted. Now, bear in mind I have very little skill when it comes to Bash and scripting and what I wrote was a result of trial and error. It all revolves around a tool called hcitool that can be used in Linux to control Bluetooth connections.
The first attempt at my script can be found here and with another link below.
It is only designed to work with ZoneMinder and there isn’t much advice within the code, but I shall update it as time goes by to make it more useful
Here is the full link to the script:
The Quest For Security
So, I have been pretty quiet of late, sorry about that. Well, the main reason was it was Xmas a while back, but also, I have been doing LOADS of research into security on the web.
For the past few months I have been toying with the idea of implementing a security device on my network that would take all the leg work of antivirus and intrusion detection and prevention off each PC on the network and get a dedicated machine to do it.
It turns out there are lots of options out there to do this, so I dabbled with a few.
The first I checked out was http://www.untangle.com/. Untanlge basically is a special Debian distro with lots of preconfigured security tools, like ClamAV for antivirus, snort_inline for intrusion prevention and iptables for a firewall. It comes with a very easy to use web interface making it idiot proof. However, I came across a few problems. First, it needs a PC with two NICS to be used as a dedicted server, something I didn’t have. Second, you can use it on a Windows XP machine, but it installing a Virutal Machine via VMPlayer, it then automagicaly reconfigures your network so that all traffic is routed through it first. However, this also wasn’t a great solution since it means you need to have a machine effectively running to OSs at once (Windows XP and the Virtual Machine) and also it did not work with my Vista lappie. Finally, it also prevented me from browsing gmail, so it was a no go for me – although some fix to do with Socks5 was the cure.
Second, I tried rolling my own system using snort_inline (http://snort-inline.sourceforge.net/), ClamAV, iptables and Ubuntu. This is what has taken me an age. I have never built any app from source before and it took me a long time to figure out what to do. Plus, I wanted to run this on a low power box and the only one I had available that had two NICS was an old thin client that runs of a USB 2.0 harddrive, so it aint that fast at all. However, I have finally managed got snort_inline running, with a ClamAV preprocessor and logging to mySQL. So far it is only scanning all the traffic coming into my network, I haven’t yet got it to actually prevent anything yet.
I finally tried out an interesting solution http://packetprotector.org/. This is kinda like the untangle solution, except that it all runs off your router. Sadly, all the routers it currently runs off are pretty hard to get hold of here in the UK, but from what I see, it might be the best solution. You get an advanced iptables firewall, snort_inline, dansguardian (content filtering) and ClamAV all running on top of OpenWRT. The only negative I can see is you need to be a bit of a linux guru to know what you are doing if you want to start to customise it (though it does come with the WebIF interface) and that it can bog down pretty quickly. However, to me it seems the best solution, until I get some super powerful server that I can run untangle, or monowall or IPcop or EasyIDS on. There are loads of solutions out there, you just need the right old PC to run it on, or a PC that you think is going to be quiet enough
Linux commands to be aware of
Just came across this excellent little article about some dangerous commands that the less than chivalrous Linux user might give out to Linix noobies, for a joke. The only problem is, these jokes will kill your hard drive and/or PC. Not cool.
