How to download a list of URLs using more than one process (say wget) at the time?
First, create a file with URLs – one URL per line. Let’s call the file url.txt. Then we need to create N wget processes, each downloading one URL at the time. Thanks to xargs it is trivial:
cat url.txt | xargs -n 1 -P 10 wget
-n 1 will make xargs run command (wget) with only one argument at the time
-P 10 will create 10 parallel processes
Drupal views 2 API allows creating views based on any table. Most of the fields you will be displaying will be based on the table columns but it may sometimes be handy to create a non-database field. Usually it will be a field that you need to compute – maybe based on some other fields from the same table. The point is that the field name will not map to the table’s column name.
I will illustrate it on the example below. Let’s say we have a very simple table named distros that hold Linux-based distributions with just 2 columns:
id – the primary key
name – name of the distribution
I have created a new module called distros with two files:
distros.module with function distros_views_api
distros.views.inc
In distros.views.inc we need to describe our table – it’s easy for the table columns like name:
functiondistros_views_data(){$data=array();$data['distros']['table']=array('group'=>'distros','title'=>'title','help'=>'help');$data['distros']['table']['base']=array('field'=>'id','title'=>'Distro','help'=>'This is distro main table',);$data['distros']['name']=array('field'=>array('title'=>'distro name','help'=>'This is distro main table',),);return$data;}
To add non-database field, we will need a custom field handler. Otherwise Drupal will try to add field name into SELECT clause it’s using – that will obviously cause an error as the column doesn’t exist. Let’s say we want our view to display a quote from Linus Torvalds. Our new, “virtual” field should be named quote and should always display a text: Talk is cheap. Show me the code. We will call our handler distros_handler_field_distro_quote and overwrite two functions:</p>
render – to always display our text
query – to prevent Drupal from querying for quote field
In distros_handler_field_distro_quote.inc :
<?phpclassdistros_handler_field_distro_quoteextendsviews_handler_field{functionrender(){return"Talk is cheap. Show me the code.";}functionquery(){ensure_my_table();$this->add_additional_fields();}}
Now, let’s go back to distros.views.inc and register our new handler:
And finally describe new field by adding to distros_views_data:
$data['distros']['quote']=array('field'=>array('title'=>'Quote from Linus','help'=>'This is non-database field','handler'=>'distros_handler_field_distro_quote',),);
Install your new module and create the view, here is the final effect:
To upgrade nearly all packages with apt-get but “hold” some of them at the current version, you can use dpkg.
Let’s say I would like to upgrade my Debian or Ubuntu system with apt-get and here is what I’m getting:
If I don’t want to upgrade php5 package I can “hold” it:
Switch to root (su or sudo -s)
Execute:
echo php5 hold | sudo dpkg --set-selections
That’s it – after running apt-get upgrade again, the package will be “kept back”:
% sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
php5
I needed to set my Apache Web Server to ignore/block all the HEAD requests but respond to GET requests normally. It is very simple with the mod_rewrite, for instance this can be added to .htaccess:
2) run `./runme –download`. you are to have curl to successfully download patches, so if you do not, install it
3) run `./runme external` and apply patches
4) configure, make, install your kernel
5) make and install your iptables
if you need ipt_account, you can download patches from http://www.svn.barbara.eu.org/ipt_account/wiki/Patches. don’t copy a link to the patch and use wget! for an unknown reason, when wgetting patches, there appear strange distortions in files; open the patch with a browser and do copy-paste for the patches’ text. then unpack them and patch kernel and iptables as usual.
(bios) stage and that bootloader stage when we have a nice lilo/grub prompt.
to enable it in kernel, say “yes” in Processor type and features->kexec system call (EXPERIMENTAL)
make and install your kernel.
we will need also a userspace tool called kexec. at the moment of writing, it is not available as package for debian sarge, but is for etch; the sources can be built and installed without any problems, so i don’t see any problems in downloading it from let’s say http://packages.debian.org/testing/source/kexec-tools; i tested them even with slackware and everything worked perfectly.
to boot with kexec we need first to load a kernel image in memory:
the problem is that here we oversimplify things: we do not term and kill processes, we do not umount filesystems. to make everything to work properly, we just modify /etc/init.d/reboot to look like this:
Device Drivers -> SCSI device support:
-> SCSI device support
-> legacy /proc/scsi/ support
-> SCSI disk support
-> SCSI generic support
-> [SCSI logging facility]
Device Drivers -> USB Support:
-> Support for Host-side USB
-> USB device filesystem
-> USB drives. it may be:
- EHCI HCD (USB 2.0) support
- OHCI HCD support
- UHCI HCD (most Intel and VIA) support
but probably only one driver will be used
-> USB Mass Storage support
File Systems:
-> File Systems -> DOS/FAT/NT Filesystems -> VFAT (Windows-95) fs support
-> Native Language Support -> Codepage 437 (United States, Canada)
make and install your kernel. after reboot plug your USB device in and look at `dmesg`. you should see that kernel has found usb device and attached it as scsi dev. messages differ from one linux distribution to other.
once i was not able to see scsi dev after having done all that. the solution was a newer kernel, so if you fail, check carefully your kernel option and try another kernel.
so now you have a normal device file in /dev, which you can mount, fsck and so on. if you do not have any other scsi devices, it will be /dev/sda, if you already have one scsi, the flash will be added as /dev/sdb and so on. try to cat /proc/scsi/scsi and you will see some info about your flash device; finally, if you do not want to count your scsis, install sg3-utils package (for Debian) and run sg-map – it will show you your flash’s real /dev/sd*.
mount it somewhere: mount -t auto /dev/sda1 /mnt
keeping in mind all advantages of linux filesystems, i however advice you to left vfat fs on your flash – you will be able to use it with windows machines
and, of course, you can format it with let’s say `fsck -t ext3 /dev/sda1`, partition it and even make encrypted filesystem on it. i will try to explain how to do it later