Gentoo Blog

The ultimate Gentoo Blog
  • rss
  • Home
  • About

chmod change files or directories recursively to the same value

Simon | February 11, 2010

Recursively change all files in your current working directory including files in subdirectories to 644:

find . -type f -print0 | xargs -0 chmod 644

Recursively change all directories in your current working directory including subdirectories to 755:

find . -type d -print0 | xargs -0 chmod 755

Kommentare
Keine Kommentare »
Kategorien
Gentoo, Stuff, Ubuntu/Debian
RSS Kommentare RSS Kommentare
Trackback Trackback

Useful Mysql Commands

Simon | November 6, 2009

when you see  a # it means use the command from the unix shell. When you see mysql> it means from a MySQL prompt after logging into MySQL.

To login (from unix shell) use -h only if needed.

# [mysql dir]/bin/mysql -h hostname -u root -p

Create a database on the sql server.

mysql> create database [databasename];

List all databases on the sql server.

mysql> show databases;

Switch to a database.

mysql> use [db name];

To see all the tables in the db.

mysql> show tables;

To see database’s field formats.

mysql> describe [table name];

To delete a db.

mysql> drop database [database name];

To delete a table.

mysql> drop table [table name];

Show all data in a table.

mysql> SELECT * FROM [table name];

Returns the columns and column information pertaining to the designated table.

mysql> show columns from [table name];

Show certain selected rows with the value “whatever”.

mysql> SELECT * FROM [table name] WHERE [field name] = "whatever";

Show all records containing the name “Bob” AND the phone number ‘3444444′.

mysql> SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';

Show all records not containing the name “Bob” AND the phone number ‘3444444′ order by the phone_number field.

mysql> SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '3444444' order by phone_number;

Show all records starting with the letters ‘bob’ AND the phone number ‘3444444′.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444';

Show all records starting with the letters ‘bob’ AND the phone number ‘3444444′ limit to records 1 through 5.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444' limit 1,5;

Use a regular expression to find records. Use “REGEXP BINARY” to force case-sensitivity. This finds any record beginning with a.

mysql> SELECT * FROM [table name] WHERE rec RLIKE "^a";

Show unique records.

mysql> SELECT DISTINCT [column name] FROM [table name];

Show selected records sorted in an ascending (asc) or descending (desc).

mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;

Return number of rows.

mysql> SELECT COUNT(*) FROM [table name];

Sum column.

mysql> SELECT SUM(*) FROM [table name];

Join tables on common columns.

mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;

Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password'));
mysql> flush privileges;

Change a users password from unix shell.

# [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password 'new-password'

Change a users password from MySQL prompt. Login as root. Set the password. Update privs.

# mysql -u root -p
mysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere');
mysql> flush privileges;

Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.

# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start

Set a root password if there is on root password.

# mysqladmin -u root password newpassword

Update a root password.

# mysqladmin -u root -p oldpassword newpassword

Allow the user “bob” to connect to the server from localhost using the password “passwd”. Login as root. Switch to the MySQL db. Give privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> grant usage on *.* to bob@localhost identified by 'passwd';
mysql> flush privileges;

Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
mysql> flush privileges;

or

mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;

To update info already in a table.

mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';

Delete a row(s) from a table.

mysql> DELETE from [table name] where [field name] = 'whatever';

Update database permissions/privilages.

mysql> flush privileges;

Delete a column.

mysql> alter table [table name] drop column [column name];

Add a new column to db.

mysql> alter table [table name] add column [new column name] varchar (20);

Change column name.

mysql> alter table [table name] change [old column name] [new column name] varchar (50);

Make a unique column so you get no dupes.

mysql> alter table [table name] add unique ([column name]);

Make a column bigger.

mysql> alter table [table name] modify [column name] VARCHAR(3);

Delete unique from table.

mysql> alter table [table name] drop index [colmn name];

Load a CSV file into a table.

mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3);

Dump all databases for backup. Backup file is sql commands to recreate all db’s.

# [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql

Dump one database for backup.

# [mysql dir]/bin/mysqldump -u username -ppassword --databases databasename >/tmp/databasename.sql

Dump a table from a database.

# [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql

Restore database (or database table) from backup.

# [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql

Create Table Example 1.

mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));

Create Table Example 2.

mysql> create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default 'bato');

Kommentare
1 Kommentar »
Kategorien
Gentoo, Stuff, Ubuntu/Debian
RSS Kommentare RSS Kommentare
Trackback Trackback

Devils and Penguins Save Taz

Simon | March 18, 2009

linux.conf.au 2009: Tuz

Impact: help prevent extinction of species

The Tasmanian Devil is a shy iconic Australian creature named for its
spine-chilling screech.  It is threatened with extinction due to a
scientifically interesting but horrific transmissible facial cancer.

This one is standing in for Tux for one release using the far less-known
Devil Facial Tux Disguise.

Save The Tasmanian Devil  tassiedevil.com.au

This is what he looks like:

20090318tuz

Kommentare
1 Kommentar »
Kategorien
Gentoo, fun
RSS Kommentare RSS Kommentare
Trackback Trackback

3ware RAID Controller

Simon | March 13, 2009

Check the card

To enter the 3ware command line interface, type tw_cli. Enter ? or help to view help. For more information about the 3ware CLI, see the man page or the 3ware knowledge base linked at the bottom of this document.

First we need some info on our setup:

Code: Getting info on setup

3ware CLI> info
List of controllers
Controller 0: 8006-2LP (2)

Here we see that we have one controller 0 with two drives. Let’s get more info on controller 0.

Code: Getting info on controller 0

3ware CLI> info c0
Controller: c0
Driver:   1.02.00.033
Model:    8006-2LP
FW:       FE7S 1.05.00.065
BIOS:     BE7X 1.08.00.048
Monitor:  ME7X 1.01.00.038
Serial #: F14902A4110263
PCB:      Rev5
PCHIP:    1.30-66
ACHIP:    3.20
# of units: 1
Unit 0: RAID 1 111.79 GB ( 234439600 blocks): DEGRADED
# of ports: 2
Port 0: WDC WD1200JD-22GBB0 WD-WMAET1426272 111.79 GB (234441648 blocks): OK(unit 0)
Port 1: WDC WD1200JD-00GBB0 WD-WMAET1626327 111.79 GB (234441648 blocks): OK(unit 0)

Now we can see the RAID at unit 0 is degraded. Let’s find out which disk is giving us a problem. For the rest of the document, I’ll exit from the program and run it as a command instead.

Code: Finding out which disk is degraded

[root@myputer ~]# tw_cli info c0 u0
Unit /c0/u0
Status:        DEGRADED
Unit Type:     RAID 1
Stripe Size:   N/A
Size: 111.79 GB (234439600 blocks)
# of subunits: 2
Subunit 0:    CBOD: OK
Physical Port: 0
Logical  Port: 0
Subunit 1:    CBOD: DEGRADED
Physical Port: 1
Logical  Port: 1

Ok, port 1 is the disk that needs our attention.

Rebuild The RAID

First we need to remove the drive. This is like unmounting a filesystem so that we can work on it.

Code: Removing the drive

[root@myputer ~]# tw_cli maint remove c0 p1
Removing port /c0/p1 ... Done.

Now let’s have the software rescan the drives.

Code: Rescaning the drives

[root@myputer ~]# tw_cli maint rescan c0
Rescanning controller /c0 for units and drives ...Done.

At this point, we need to see if the rescan picked the drive back up. If the port is N/A this is likey a bad drive and isn’t responding. You’ll need to replace the drive and rescan:

Code: Checking if the rescan picked the drive back up

(Third party note: This is confusing, ignore this block. I suspect that this is supposed to be an example of a drive that is N/A, not a continuation of the example.)

[root@myputer ~]# tw_cli info c0 u0
Unit /c0/u0
Status:        DEGRADED
Unit Type:     RAID 1
Stripe Size:   N/A
Size:         111.79 GB (234439600 blocks)
# of subunits: 2
Subunit 0:    CBOD: DEGRADED
Physical Port: N/A
Logical  Port: 0
Subunit 1:    CBOD: OK
Physical Port: 1
Logical  Port: 1

Otherwise all that’s left to do is rebuild the drive.

Code: Rebuilding the drive

[root@myputer ~]# tw_cli maint rebuild c0 u0 p1
Rebuild started on unit /c0/u0

To check the status, just give it the info option

Code: Checking the status

[root@myputer ~]# tw_cli info c0 u0
Unit /c0/u0
---------------------
Status:        REBUILDING (0%)
Unit Type:     RAID 1
Stripe Size:   N/A
Size:          111.79 GB (234439600 blocks)
# of subunits: 2
Subunit 0:    CBOD: OK
Physical Port: 0
Logical  Port: 0
Subunit 1:    CBOD: DEGRADED
Physical Port: 1
Logical  Port: 1

Since it’s rebuilding as it’s running, this could take a really long time.

More Information

3ware Knowledge Base

Man page for tw_cli

Some notes from 3ware support

They said the way it should be done:
Assuming port0 is bad
1.tw_cli maint remove c0 p0
2. remove the Old drive and Hotswap a new drive
3. tw_cli maint rescan c0
This will bring the new drive up
4. tw_cli maint createunit c0 rspare p0
5. tw_cli maint rebuild c0 u0 p0

Check our knowledge base article’s for rebuild information.
http://3ware.com/kb/article.aspx?id=11647
http://3ware.com/kb/article.aspx?id=11956
http://3ware.com/kb/article.aspx?id=11306

This Howto is copied from the old gentoo wiki. Since the wiki is down and i need this information quite often.

Kommentare
Keine Kommentare »
Kategorien
Gentoo
RSS Kommentare RSS Kommentare
Trackback Trackback

How to install grub on a HP Proliant Server

Simon | February 26, 2008

This on took me a while to solve. I got a new server from HP a Proliant DL 380 G5. So i went about installing my favorite distro on it gentoo. So far so good until i reached the step to install grub. Grub would not recognize the hard drives on the smart array controller. This is what i did to fix the problem

E dit the file /boot/grub/device.map to look like this

(fd0) /dev/fd0
(hd0) /dev/cciss/c0d0

Run grub like this:

/sbin/grub --batch --device-map=/boot/grub/device.map --config-file=/boot/grub/grub.conf --no-floppy

grub shell:

grub> root (hd0,0)
grub> setup (hd0)
grub> quit

That’s it your done go compile your kernel or something :)

Kommentare
Keine Kommentare »
Kategorien
Gentoo
RSS Kommentare RSS Kommentare
Trackback Trackback

Gentoo gnome automatic keyring loading

Simon | February 10, 2008

When you log onto a gnome session in ubuntu your gnome keyring automatically gets loaded. So that you can use your WPA or ssh keys in your gnome session. On a gentoo install you get prompted to type in your password to unlock you keyring. So you have to type in your password twice this about how to stop this behavior and pass on your login from gdm to the keyring manager. You must edit a few files in /etc/pam.d

On a gentoo ~x86 system i had to edit the following files all changes i had to make are highlighted in bold text. Please follow the exact order of the statements they are important to make this work.

/etc/pam.d/system-auth

#%PAM-1.0
auth required pam_env.so
auth optional pam_gnome_keyring.so
auth sufficient pam_unix.so try_first_pass likeauth nullok
auth required pam_deny.so

account required pam_unix.so

password required pam_cracklib.so difok=2 minlen=8 dcredit=2 ocredit=2 try_first_pass retry=3
password optional pam_gnome_keyring.so
password sufficient pam_unix.so nullok md5 shadow use_authtok
password required pam_deny.so

session required pam_limits.so
session optional pam_gnome_keyring.so auto_start
session required pam_unix.so

/etc/pam.d/gdm

#%PAM-1.0
auth optional pam_env.so
auth optional pam_gnome_keyring.so
auth include system-auth
auth required pam_nologin.so
session optional pam_gnome_keyring.so auto_start
account include system-auth
password include system-auth
session include system-auth

/etc/pam.d/passwd

#%PAM-1.0
password optional pam_gnome_keyring.so
auth include system-auth
account include system-auth
password include system-auth

/etc/pam.d/gnome-screensaver

#%PAM-1.0
# Fedora Core
auth optional pam_gnome_keyring.so
auth include system-auth
account include system-auth
password include system-auth
session include system-auth

# SuSE/Novell
#auth include common-auth
#account include common-account
#password include common-password
#session include common-session

Source Gentoo forum:

Kommentare
Keine Kommentare »
Kategorien
Gentoo
RSS Kommentare RSS Kommentare
Trackback Trackback

vmware Server /tmp is full and all vms are shutdown

Simon | January 31, 2008

One of our gentoo vmware servers crashed and stopped all running VMs on the server. After looking trough the logs i found out that vmware server had filled the /tmp partion which was 1GB. What i didn’t know is that vmware requires the /tmp partion to  be equivalent to 1.5 times the amount of memory on the host. Otherwise you will experience vm crashes. To change the tmp location edit

/etc/vmware/config

and add the following line tmpDirectory = “/<your>/<new>/<tmp>/<directory>”

Be sure that the specified directory is on a local hard drive and that the user running the VMware software has write permissions for that directory. For more infos check out

http://www.vmware.com/support/gsx3/doc/intro_sysreqs_host_gsx.html

 

 

Kommentare
Keine Kommentare »
Kategorien
Gentoo
RSS Kommentare RSS Kommentare
Trackback Trackback

 

March 2010
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
293031  

Links

  • AGF Clan
  • Gentoo
  • http.net
  • michael-fuchs.net

Categories

  • confixx/Plesk
  • fun
  • Gentoo
  • iptables
  • news
  • Stuff
  • Ubuntu/Debian
  • Xen/Vmware

Search Blog

rss RSS Kommentare valid xhtml 1.1 design by jide powered by Wordpress get firefox