rm `fgrep -lir searchstring *`
Tuesday, 27 October 2009
Search files for text and delete
I had to do this when a mail queue ended up with hundreds of bounce messages. I needed to delete these messages and keep the rest.
Saturday, 24 October 2009
Preparing for Karmic
With less than a week to go until Karmic goes live you might want to avoid the rush and pre-download the packages you will need for when you decide to upgrade.
Do this by using the "download only" flag in apt-get
First, change your sources.list file to point to the Karmic repositories.
Next, do a "download only" upgrade.
At the end of the process, instead of stepping to the "Installing packages" stage you will see a message "Download complete and in download only mode"
Cool.
Finally, do the same for a distribution upgrade
If you have more than one PC on your network to be upgraded, you probably want to use apt-cacher so that you only need to download all those packages once.
Come the time to do the upgrade proper, repeat these steps (simply to update any packages that have changed since you downloaded them into your cache).
Then, when you do the upgrade for real, it will skip past the normally lengthy download stage and straight to the "installing packages" phase while all the other plebs are fighting over bandwidth trying to download packages on the release day!
Do this by using the "download only" flag in apt-get
First, change your sources.list file to point to the Karmic repositories.
Next, do a "download only" upgrade.
sudo apt-get -d upgrade
At the end of the process, instead of stepping to the "Installing packages" stage you will see a message "Download complete and in download only mode"
Cool.
Finally, do the same for a distribution upgrade
sudo apt-get -d dist-upgrade
If you have more than one PC on your network to be upgraded, you probably want to use apt-cacher so that you only need to download all those packages once.
Come the time to do the upgrade proper, repeat these steps (simply to update any packages that have changed since you downloaded them into your cache).
Then, when you do the upgrade for real, it will skip past the normally lengthy download stage and straight to the "installing packages" phase while all the other plebs are fighting over bandwidth trying to download packages on the release day!
Wednesday, 21 October 2009
Copy files to /dev/null
I have a suspected hard disk problem. What happens is when I do a large amount of disk reading (as in performing a backup) somewhere along the line the system freezes and needs to be reset. System logs show nothing useful.
So, what I want to do is basically read a whole bunch of files and directories and see if the failure occurs on a specific file (or files)
This is the first command I used;
Basically it does a find for all files and then does a 'cat' of each file to /dev/null and finally appends the console output for that action to a file called "readtest".
The idea was that if it fails on a file I should be able to consult the "readtest" file which will tell me the last file which successfully copied.
You can watch the console output 'live' by using the tail command
The problem was that the 'find' command doesn't find files in alphabetical order so it is difficult to identify what the next file it was copying would be, so I modified my procedure.
First I created a small shell script called 'testfile'
Made it executable with
then reran a slightly modified version of the above command;
This will printout the file it is about to test beforehand so that if the system locks up during the reading of a file, I can consult the readtest log to see which file it was reading.
So, what I want to do is basically read a whole bunch of files and directories and see if the failure occurs on a specific file (or files)
This is the first command I used;
find . -type f -print -exec sh -c 'cat "$1" >/dev/null' {} {} \; > readtest&
Basically it does a find for all files and then does a 'cat' of each file to /dev/null and finally appends the console output for that action to a file called "readtest".
The idea was that if it fails on a file I should be able to consult the "readtest" file which will tell me the last file which successfully copied.
You can watch the console output 'live' by using the tail command
tail -f readtest
The problem was that the 'find' command doesn't find files in alphabetical order so it is difficult to identify what the next file it was copying would be, so I modified my procedure.
First I created a small shell script called 'testfile'
#!/bin/sh
echo "Testing $1"
cat "$1" >/dev/null
Made it executable with
chmod +x testfile
then reran a slightly modified version of the above command;
find . -type f -print -exec sh -c './testfile "$1"' {} {} \; > readtest&
This will printout the file it is about to test beforehand so that if the system locks up during the reading of a file, I can consult the readtest log to see which file it was reading.
Tuesday, 20 October 2009
Joining Video Files
Sometimes I want to join together two Video files.
Firstly, we need to have mencoder installed.
Now, lets assume that we have two avi files called f1.avi and f2.avi.
The first step is to join the files together;
If you have more than two files simply include them all (in the correct order of course)
Next, we need to ensure that the audio syncing has not been messed up;
Firstly, we need to have mencoder installed.
sudo apt-get install mencoder mplayer
Now, lets assume that we have two avi files called f1.avi and f2.avi.
The first step is to join the files together;
cat f1.avi f2.avi > f1f2.avi
If you have more than two files simply include them all (in the correct order of course)
cat f1.avi f2.avi f3.avi > f1f2f3.avi
Next, we need to ensure that the audio syncing has not been messed up;
mencoder -forceidx -oac copy -ovc copy f1f2.avi -o final.avi
Wednesday, 7 October 2009
Run a script at user login
When a user opens a bash shell, there is a script that runs (~/.bashrc) which configures the shell with the users preferences.
Sometimes you want to run a similar sort of script when a user logs in to the gnome desktop as well.
To do this you need to create a .desktop file and place it in ~/.config/autostart. Here is an example;
You also need to place an executable script (in this case /home/brettg/test.sh) that will hold the commands you want to execute.
More details here and here
Sometimes you want to run a similar sort of script when a user logs in to the gnome desktop as well.
To do this you need to create a .desktop file and place it in ~/.config/autostart. Here is an example;
[Desktop Entry]
Type=Application
Name=TestScript
Exec=/home/brettg/test.sh
Comment=Testing autostart
You also need to place an executable script (in this case /home/brettg/test.sh) that will hold the commands you want to execute.
More details here and here
Monday, 5 October 2009
DHCP and DNS using DNSMasq
If you are not configuring an internet facing nameserver to resolve your own FQDN then you really don't want to use ISC BIND.
In cases where you want to simple domain in a home or office with caching and dhcp then the by far the simplest tool to set up is dnsmasq.
Once installed you can configure it by editing dnsmasq.conf
The config file is very well documented and should be self explanatory. For a simple DNS setup you probably want to modify the following two lines;
For server use your upstream (usually your ISP) dns server.
For local use the domain you want to use on your LAN.
To use DHCP modify these lines;
You can do some other neat stuff too, like assign static addresses by hostname or mac address, specifiy specific servers for specific domains and other geeky fun things. Most of it is documented in the config file, I encourage you to read through it.
If you put IP and name entries into /etc/hosts then dnsmasq will use that to resolve names and pass them on to clients, easy peazy!
In cases where you want to simple domain in a home or office with caching and dhcp then the by far the simplest tool to set up is dnsmasq.
sudo apt-get install dnsmasq
Once installed you can configure it by editing dnsmasq.conf
sudo vi /etc/dnsmasq.conf
The config file is very well documented and should be self explanatory. For a simple DNS setup you probably want to modify the following two lines;
server=202.27.184.3
local=tuxnetworks.com
For server use your upstream (usually your ISP) dns server.
For local use the domain you want to use on your LAN.
To use DHCP modify these lines;
domain=tuxnetworks.com
dhcp-range=10.1.1.10,10.1.1.150,12h
You can do some other neat stuff too, like assign static addresses by hostname or mac address, specifiy specific servers for specific domains and other geeky fun things. Most of it is documented in the config file, I encourage you to read through it.
If you put IP and name entries into /etc/hosts then dnsmasq will use that to resolve names and pass them on to clients, easy peazy!
Subscribe to:
Posts (Atom)