Mysql trigger

If you want to trigger an action to another table you can create a trigger:

CREATE TRIGGER `update_menus` AFTER INSERT ON `usuarios` FOR EACH ROW insert into sys_user_roles set sys_roles_id=(select sys_roles_id from sys_roles where roles_name=NEW.tipo),user_id=NEW.user_id

CREATE TRIGGER `update_totals_after_delete` AFTER DELETE ON `pedidos_detalle` 
FOR EACH ROW 
update pedidos set subtotal = (select sum(importe) from pedidos_detalle where folio=OLD.folio) 
where folio=OLD.folio

CREATE TRIGGER `update_totals_after_insert` AFTER INSERT ON `pedidos_detalle` 
FOR EACH ROW 
update pedidos set subtotal = (select sum(importe) from pedidos_detalle where folio=NEW.folio) 
where folio=NEW.folio

mysql generated columns (same table)

This is to add a column in a table with calculated values from the same table.

ALTER TABLE pedidos add column impuesto float generated always as (subtotal*.16) VIRTUAL;

ALTER TABLE pedidos add column total float generated always as (subtotal*1.16) VIRTUAL;

ALTER TABLE pedidos add column flete float generated always as (case when total < 6000 then 1000 else 0 end) virtual

import OVM Repository from another server

if you replicated a LUN containing a repository you need to import it

– fsck the volume
fsck.ocfs2 /dev/mapper/xxxxxxxxxxxxxxxxxxxxx <—-find the correct one if you have other iSCSI luns connected

– Update the cluster id:
tunefs.ocfs2 –update-cluster-stack /dev/mapper/xxxxxxxxxxxxxxxxxxxxxxxxx

– Mount the file system into a temporay mount point. (Perhaps mounting to the final uuid works, but I prefer umount later on and let OVM manager do the job)

mkdir /OVS/Repositories/temp
mount /dev/mapper/xxxxxxxxxxxxx /OVS/Repositories/temp

– Change OVS_REPO_MGR_UUID in .ovsrepo to the correct uuid (i picked up the one from the already presented repository. I don’t know yet where this uuid can be taken from if you have no other repository)
(check that OVS_REPO_UUID has no duplicate)

– umount /OVS/Repositories/temp

– Form the manager, refresh the shared file system, Present the Repository to servers ans refresh that Repository.

Quick Solaris expect script to change password

#!/bin/bash
cat dbausers | while read u;do
cat << EOF > /tmp/chpw_${u}.exp
#!/usr/bin/expect -f
set force_conservative 0
if {\$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s — $arg
}
}
set timeout -1
spawn passwd $u
match_max 100000
expect -exact “New Password: ”
send — “Sssspwd@1234\r”
expect -exact “\r
Re-enter new Password: ”
send — “Sssspwd@1234\r”
expect eof
EOF
chmod 755 /tmp/chpw_${u}.exp
/tmp/chpw_${u}.exp
done

Solaris 11 unshare ZFS NFS share

Remove the share by identifying the share-name name. For example:

# zfs set -c share=name=data rpool/data
share 'data' was removed.

Remove the share by identifying the share-path name. For example:

# zfs set -c share=path=/data rpool/data
share 'data' was removed.