Using systemd in Fedora.....
To permanently enable a service:
# systemctl enable ntpd.service
To start it:
# systemctl start ntpd.service
To view all services:
# systemctl
Wednesday, March 27, 2013
Friday, March 22, 2013
Finding Disk Hogs
Finding disk hogs
# du /home/* | sort -n -r | less
# du /home/* | sort -n -r | less
Wednesday, March 20, 2013
Adding constraints to mysql tables
When we have content in a table that is dependant on another a constraint is required. With Mysql an InnoDB type is required otherwise the constraint is silently ignored. Consider a radios table, models table and a code_plugs table within the radio database.
The constraints would prevent a code_plug or models record being removed if a relative record in the radios table exists.
The create table entries would be:
CREATE TABLE `radios` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`status_id` int(4) NOT NULL DEFAULT '2',
`model_id` int(4) NOT NULL,
`serial_number` varchar(40) NOT NULL,
`software_version` varchar(40) NOT NULL,
`active` int(4) NOT NULL DEFAULT '1',
`remarks` varchar(100) NOT NULL,
`code_plugs_id` int(4) NOT NULL,
`radio_id` int(4) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `serial_number` (`serial_number`),
UNIQUE KEY `radio_id` (`radio_id`),
CONSTRAINT `FK_code_plugs` FOREIGN KEY (`code_plugs_id`) REFERENCES `code_plugs` (`id`),
CONSTRAINT `FK_models` FOREIGN KEY (`model_id`) REFERENCES `models` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1376 DEFAULT CHARSET=latin1;
CREATE TABLE `models` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`model` varchar(20) NOT NULL,
`type` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;
CREATE TABLE `code_plugs` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`name` varchar(40) NOT NULL,
`description` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1112 DEFAULT CHARSET=latin1;
A simple snippet of perl server side code to provide an xml response to a delete attempt would look like:
my $dbh = DBI->connect("dbi:mysql:radio",$dbuser,$dbpass,{RaiseError=>0});
my $id = param("id");
my $table = param("table");
my $rows = $dbh->do("DELETE FROM $table WHERE id = \'$id\';");
my $result;
if($dbh->errstr){
$result = $dbh->errstr;
$result =~ s/([\',\`])+//g;
}else{
$result = $rows;
}
# results are 1 for success and 0E0 for failure
my $xml = '<?xml version="1.0"?>';
$xml .= "\n<options>\n";
$xml .= "<option result=\'$result\' />\n";
$xml .= "</options>";
print "$xml";
A simple javascript handler for the delete may look similar to :
function deleteID(id,table){
if (confirm("Are you sure?")){
var request;
try{
request = new XMLHttpRequest();
}catch(error){
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(error){
return true;
}
}
request.open('GET', '/cgi-bin/deleteUsingID.pl?id=' + id + '&table=' + table,true);
request.onreadystatechange = function(){
if(request.readyState == 4){
var xmlDoc = request.responseXML;
var options = xmlDoc.documentElement.getElementsByTagName("option");
for (var x = 0; x < options.length; x++){
var result = (options[x].getAttribute("result"));
if (result == '1'){
var rid = 'row_' + id;
var oTable = document.getElementById('content_table');
var oTr = document.getElementById(rid);
oTable.deleteRow(oTr.rowIndex);
}else{
alert(result);
}
}
}
}
request.send(null);
}
}
When we have content in a table that is dependant on another a constraint is required. With Mysql an InnoDB type is required otherwise the constraint is silently ignored. Consider a radios table, models table and a code_plugs table within the radio database.
The create table entries would be:
CREATE TABLE `radios` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`status_id` int(4) NOT NULL DEFAULT '2',
`model_id` int(4) NOT NULL,
`serial_number` varchar(40) NOT NULL,
`software_version` varchar(40) NOT NULL,
`active` int(4) NOT NULL DEFAULT '1',
`remarks` varchar(100) NOT NULL,
`code_plugs_id` int(4) NOT NULL,
`radio_id` int(4) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `serial_number` (`serial_number`),
UNIQUE KEY `radio_id` (`radio_id`),
CONSTRAINT `FK_code_plugs` FOREIGN KEY (`code_plugs_id`) REFERENCES `code_plugs` (`id`),
CONSTRAINT `FK_models` FOREIGN KEY (`model_id`) REFERENCES `models` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1376 DEFAULT CHARSET=latin1;
CREATE TABLE `models` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`model` varchar(20) NOT NULL,
`type` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;
CREATE TABLE `code_plugs` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`name` varchar(40) NOT NULL,
`description` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1112 DEFAULT CHARSET=latin1;
A simple snippet of perl server side code to provide an xml response to a delete attempt would look like:
my $dbh = DBI->connect("dbi:mysql:radio",$dbuser,$dbpass,{RaiseError=>0});
my $id = param("id");
my $table = param("table");
my $rows = $dbh->do("DELETE FROM $table WHERE id = \'$id\';");
my $result;
if($dbh->errstr){
$result = $dbh->errstr;
$result =~ s/([\',\`])+//g;
}else{
$result = $rows;
}
# results are 1 for success and 0E0 for failure
my $xml = '<?xml version="1.0"?>';
$xml .= "\n<options>\n";
$xml .= "<option result=\'$result\' />\n";
$xml .= "</options>";
print "$xml";
A simple javascript handler for the delete may look similar to :
function deleteID(id,table){
if (confirm("Are you sure?")){
var request;
try{
request = new XMLHttpRequest();
}catch(error){
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(error){
return true;
}
}
request.open('GET', '/cgi-bin/deleteUsingID.pl?id=' + id + '&table=' + table,true);
request.onreadystatechange = function(){
if(request.readyState == 4){
var xmlDoc = request.responseXML;
var options = xmlDoc.documentElement.getElementsByTagName("option");
for (var x = 0; x < options.length; x++){
var result = (options[x].getAttribute("result"));
if (result == '1'){
var rid = 'row_' + id;
var oTable = document.getElementById('content_table');
var oTr = document.getElementById(rid);
oTable.deleteRow(oTr.rowIndex);
}else{
alert(result);
}
}
}
}
request.send(null);
}
}
Friday, March 8, 2013
Removing files older than 5 minutes.
Quickly list files with time of last modification:
# ls -alt
If you need to remove any that have not been modified lately:
# find ./*.rrd -type f -mmin +5 -exec rm {} \;
Quickly list files with time of last modification:
# ls -alt
If you need to remove any that have not been modified lately:
- verify files that will be worked on by running with ls first
- delete at will without warning
# find ./*.rrd -type f -mmin +5 -exec ls {} \;
# find ./*.rrd -type f -mmin +5 -exec rm {} \;
Thursday, March 7, 2013
Changing Basic Authentication password for an apache web site.
# apachectl restart or service httpd restart or systemctl restart httpd.service
- Move to the folder where we retain the .htpasswd file (and hence want to protect)
- Create or overwrite the .htpasswd file (in this case the user zephir exists already):
- Reboot your browser and you should be challenged again for passwd
# htpasswd -c .htpasswd zephir
New password:
Re-type new password:
Adding password for user zephir
# apachectl restart or service httpd restart or systemctl restart httpd.service
Monday, November 12, 2012
Extending disk space on Ubuntu 10.04 inside a VMware session
Similar to my other post I have successfully expanded the hard disk space on a VMware Ubuntu 10.04 machine. The size before was around 20G and I added 40G. Becuase its s VMware session I DID NOT need to reboot during the whole thing.
Basically it was the same as the Fedora case with a few differences as the Ubuntu used LVM but not GPT.
Heres the situation at the start:
root@HQ-SV-COMS-TILE:~# uname -a
Linux HQ-SV-COMS-TILE 3.0.0-12-server #20-Ubuntu SMP Fri Oct 7 16:36:30 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
root@HQ-SV-COMS-TILE:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/HQ--SV--COMS--TILE-root
18G 17G 172M 99% /
udev 2.0G 4.0K 2.0G 1% /dev
tmpfs 793M 232K 793M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 2.0G 0 2.0G 0% /run/shm
/dev/sda1 228M 24M 193M 11% /boot
Basically it was the same as the Fedora case with a few differences as the Ubuntu used LVM but not GPT.
Heres the situation at the start:
root@HQ-SV-COMS-TILE:~# uname -a
Linux HQ-SV-COMS-TILE 3.0.0-12-server #20-Ubuntu SMP Fri Oct 7 16:36:30 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
root@HQ-SV-COMS-TILE:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/HQ--SV--COMS--TILE-root
18G 17G 172M 99% /
udev 2.0G 4.0K 2.0G 1% /dev
tmpfs 793M 232K 793M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 2.0G 0 2.0G 0% /run/shm
/dev/sda1 228M 24M 193M 11% /boot
root@HQ-SV-COMS-TILE:~# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
root HQ-SV-COMS-TILE -wi-ao 17.74g
swap_1 HQ-SV-COMS-TILE -wi-ao 2.00g
root@HQ-SV-COMS-TILE:~# fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders, total 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009138a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 41940991 20719617 5 Extended
/dev/sda5 501760 41940991 20719616 8e Linux LVM
Disk /dev/mapper/HQ--SV--COMS--TILE-root: 19.1 GB, 19050528768 bytes
255 heads, 63 sectors/track, 2316 cylinders, total 37208064 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/HQ--SV--COMS--TILE-root doesn't contain a valid partition table
Disk /dev/mapper/HQ--SV--COMS--TILE-swap_1: 2143 MB, 2143289344 bytes
255 heads, 63 sectors/track, 260 cylinders, total 4186112 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/HQ--SV--COMS--TILE-swap_1 doesn't contain a valid partition table
Begin creating partitions inside the gaps
root@HQ-SV-COMS-TILE:~# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders, total 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009138a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 41940991 20719617 5 Extended
/dev/sda5 501760 41940991 20719616 8e Linux LVM
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Partition number (1-4, default 3): 3
First sector (499712-125829119, default 499712):
Using default value 499712
Last sector, +sectors or +size{K,M,G} (499712-501757, default 501757):
Using default value 501757
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Selected partition 4
First sector (41940992-125829119, default 41940992):
Using default value 41940992
Last sector, +sectors or +size{K,M,G} (41940992-125829119, default 125829119):
Using default value 125829119
Command (m for help): p
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders, total 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009138a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 41940991 20719617 5 Extended
/dev/sda3 499712 501757 1023 83 Linux
/dev/sda4 41940992 125829119 41944064 83 Linux
/dev/sda5 501760 41940991 20719616 8e Linux LVM
Partition table entries are not in disk order
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
root@HQ-SV-COMS-TILE:~# partprobe
root@HQ-SV-COMS-TILE:~# fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders, total 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009138a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 41940991 20719617 5 Extended
/dev/sda3 499712 501757 1023 83 Linux
/dev/sda4 41940992 125829119 41944064 83 Linux
/dev/sda5 501760 41940991 20719616 8e Linux LVM
Partition table entries are not in disk order
root@HQ-SV-COMS-TILE:~# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
root HQ-SV-COMS-TILE -wi-ao 17.74g
swap_1 HQ-SV-COMS-TILE -wi-ao 2.00g
root@HQ-SV-COMS-TILE:~# vgextend HQ-SV-COMS-TILE /dev/sda3
Volume group "HQ-SV-COMS-TILE" successfully extended
root@HQ-SV-COMS-TILE:~# vgdisplay
--- Volume group ---
VG Name HQ-SV-COMS-TILE
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 19.76 GiB
PE Size 4.00 MiB
Total PE 5058
Alloc PE / Size 5053 / 19.74 GiB
Free PE / Size 5 / 20.00 MiB
VG UUID 01HVUX-Nffq-FDN5-dQam-qelF-wnlF-UMci63
root@HQ-SV-COMS-TILE:~# lvextend -L +5M /dev/HQ-SV-COMS-TILE/root
Rounding up size to full physical extent 8.00 MiB
Extending logical volume root to 17.75 GiB
Logical volume root successfully resized
root@HQ-SV-COMS-TILE:~# resize2fs /dev/HQ-SV-COMS-TILE/root
resize2fs 1.41.14 (22-Dec-2010)
Filesystem at /dev/HQ-SV-COMS-TILE/root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/HQ-SV-COMS-TILE/root to 4653056 (4k) blocks.
The filesystem on /dev/HQ-SV-COMS-TILE/root is now 4653056 blocks long.
root@HQ-SV-COMS-TILE:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/HQ--SV--COMS--TILE-root
18320140 17206020 183920 99% /
udev 2020284 4 2020280 1% /dev
tmpfs 811744 240 811504 1% /run
none 5120 0 5120 0% /run/lock
none 2029356 0 2029356 0% /run/shm
/dev/sda1 233191 23963 196787 11% /boot
root@HQ-SV-COMS-TILE:~# fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders, total 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009138a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 41940991 20719617 5 Extended
/dev/sda3 499712 501757 1023 83 Linux
/dev/sda4 41940992 125829119 41944064 83 Linux
/dev/sda5 501760 41940991 20719616 8e Linux LVM
Partition table entries are not in disk order
Disk /dev/mapper/HQ--SV--COMS--TILE-root: 19.1 GB, 19058917376 bytes
255 heads, 63 sectors/track, 2317 cylinders, total 37224448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/HQ--SV--COMS--TILE-root doesn't contain a valid partition table
Disk /dev/mapper/HQ--SV--COMS--TILE-swap_1: 2143 MB, 2143289344 bytes
255 heads, 63 sectors/track, 260 cylinders, total 4186112 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/HQ--SV--COMS--TILE-swap_1 doesn't contain a valid partition table
root@HQ-SV-COMS-TILE:~# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created
root@HQ-SV-COMS-TILE:~# vgextend HQ-SV-COMS-TILE /dev/sda4
Volume group "HQ-SV-COMS-TILE" successfully extended
root@HQ-SV-COMS-TILE:~# vgdisplay
--- Volume group ---
VG Name HQ-SV-COMS-TILE
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 59.76 GiB
PE Size 4.00 MiB
Total PE 15298
Alloc PE / Size 5055 / 19.75 GiB
Free PE / Size 10243 / 40.01 GiB
VG UUID 01HVUX-Nffq-FDN5-dQam-qelF-wnlF-UMci63
root@HQ-SV-COMS-TILE:~# lvextend -L +40.01G /dev/HQ-SV-COMS-TILE/root
Rounding up size to full physical extent 40.01 GiB
Extending logical volume root to 57.76 GiB
Logical volume root successfully resized
root@HQ-SV-COMS-TILE:~# resize2fs /dev/HQ-SV-COMS-TILE/root
resize2fs 1.41.14 (22-Dec-2010)
Filesystem at /dev/HQ-SV-COMS-TILE/root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of /dev/HQ-SV-COMS-TILE/root to 15141888 (4k) blocks.
The filesystem on /dev/HQ-SV-COMS-TILE/root is now 15141888 blocks long.
root@HQ-SV-COMS-TILE:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/HQ--SV--COMS--TILE-root
59615364 17214100 39375092 31% /
udev 2020284 4 2020280 1% /dev
tmpfs 811744 240 811504 1% /run
none 5120 0 5120 0% /run/lock
none 2029356 0 2029356 0% /run/shm
/dev/sda1 233191 23963 196787 11% /boot
Friday, November 9, 2012
Ejecting invisible usb devices on Mac
I needed to program a DM3601 Motorola radio the other day on my mac. I use virtualbox to run a windows XP session with a copy of CPS to configure the radio via usb cable. Normally usb devices need removing or ejecting from the host machine before the virtualbox has access to the hardware, but in this case it wasnt so easy....
Not knowing what to expect I attached a usb cable to the radio and plugged it to the usb slot on the mac.
After plugging it in there was no usb device to be found, so I looked in the system information (applications->utilities) and thus knew the kernel has loaded something, but there was nothing to eject it as there were no icons anywhere. The solution was to unload the kernel module resonsible for holding the hardware via a terminal session.
I did the following:
Pop up a terminal and run:
...which lists the kernel extensions that have loaded and viola at the bottom of the list is the USB module responsible for the device I just connected.
unload it with this:
Now I could connect the virtualbox to the usb without a glitch.
Not knowing what to expect I attached a usb cable to the radio and plugged it to the usb slot on the mac.
After plugging it in there was no usb device to be found, so I looked in the system information (applications->utilities) and thus knew the kernel has loaded something, but there was nothing to eject it as there were no icons anywhere. The solution was to unload the kernel module resonsible for holding the hardware via a terminal session.
I did the following:
Pop up a terminal and run:
# kextstat
:
:
130 0 0xffffff7f81d01000 0x5000 0x5000 com.apple.driver.AppleHWSensor (1.9.5d0) <5 4 3> 131 3 0xffffff7f80a3a000 0x42000 0x42000 org.virtualbox.kext.VBoxDrv (4.2.4) <7 5 4 3 1> 132 0 0xffffff7f80795000 0x8000 0x8000 org.virtualbox.kext.VBoxUSB (4.2.4) <131 43 30 7 5 4 3 1> 133 0 0xffffff7f8079d000 0x5000 0x5000 org.virtualbox.kext.VBoxNetFlt (4.2.4) <131 7 5 4 3 1> 134 0 0xffffff7f807a2000 0x6000 0x6000 org.virtualbox.kext.VBoxNetAdp (4.2.4) <131 5 4 1> 143 0 0xffffff7f807ab000 0xd000 0xd000 com.apple.nke.asp_tcp (6.0.1) <7 6 5 4 3 1> 144 1 0xffffff7f807b8000 0x12000 0x12000 com.apple.security.SecureRemotePassword (1.0) <4 1> 145 0 0xffffff7f81001000 0x51000 0x51000 com.apple.filesystems.afpfs (9.8.1) <144 7 6 5 4 3 1> 152 0 0xffffff7f807ca000 0x3000 0x3000 com.apple.driver.AppleUSBCDC (4.1.22) <30 4 3>
...which lists the kernel extensions that have loaded and viola at the bottom of the list is the USB module responsible for the device I just connected.
unload it with this:
# kextunload -b com.apple.driver.AppleUSBCDC
Now I could connect the virtualbox to the usb without a glitch.
Subscribe to:
Posts (Atom)