Wednesday, September 27, 2006

Change User/Group Attributes to a File

It's very simple.

For User:
chown username filename
chown username directoryname

Recursively:
chown -R username directoryname

For Group:
chgrp groupname filename
chgrp groupname directoryname

Recursively:
chgrp -R groupname directoryname

-----
Change groupname and username at the same time.
chown username:groupname filename
Change username and groupname at the same time recursively.
chown -R username:groupname directoryname

File Permissions -- Solaris

To change the mode on a file or directory. I prefer the octal (0-7) format.

r -- read (has value of 4)
w -- write (has value of 2)
x -- execute (has value of 1)

rwxrwxrwx chmod 777 filename
rw-rw-rw- chmod 666 filename
r--r--r-- chmod 444 filename
-w--w--w- chmod 020 filename
--x--x--x chmod 001 filename
--------- chmod 000 filename

To make it recursive, use the -R option.

e.g. #chmod -R 777 directoryname

Dump File and Load File -- Sybase

We have a script to dump user created databases on daily basis via a cron job. However, you can dump and recover a user database on demand.

Here are the steps.

To dump a user database to file:
Ensure that you have permissions to write to the destination directory.
1>use master
2>go
1>dump database databasename to '/raid/sybdumps/dump.dat'
2>go

To recovered from a database dump file:
Ensure that you have permissions to read the dump file.
1>use master
2>go
1>load database databasename from '/raid/sybdumps/dump.dat'
2>go
1>online database databasename
2>go
1>quit
2>go

Exit Sybase interactive mode

Monday, September 25, 2006

Archived one RAID to Another

We archived the contents of one RAID to another. It takes awhile but it works.

Here’s what we did in single user mode.

#mount /dev/dsk/c1t3d0s0 /DATA1
#mount /dev/dsk/c1t4d0s0 /DATA2

#cd /DATA1; tar cvfp - . | (cd /DATA2; tar xvfp -)

mount – utility used to mount the UFS block devices to /DATA1 and /DATA2 directories
UFS – UNIX File System
cd – change directory utility
tar – tape archive utility

Sunday, September 24, 2006

Create a Database Table -- Oracle

A co-worker and I added a table into one of our Oracle databases. Here's what we did.

sql> create TABLE tablename
(columnname1 number(4),
columnname2 varChar2(10),
columnname3 varChar2(10),
columnname4 varChar2(10)
);
Table created.
sql>

create – command

TABLE – type of object to be created

tablename – name given to table, e.g. car

( – begins parameter list

columnname – attribute information, e.g. color

number – datatype e.g. 4, 5 and column width e.g. (4)

varChar2 – datatype e.g. Phoenix123 and column width e.g. (10)

); – ends parameter list

Friday, September 22, 2006

Finding a User With Niscat

Today, I was asked to lookup a user who left over a year ago. We maintain three different name services. The local name service is files and the organizational name service is NIS+. The third one is DNS, which is used to lookup external addresses.

How did I quickly find the user via command line?

I used the following commands:
For files: more /etc/passwd | grep -i username (if you know it or some other known string)
For NIS+: niscat passwd.org_dir | grep -i username

By the way, the user was located in the NIS+ domain. The user was deleted.

Thursday, September 21, 2006

Create an Index for Manual Pages

Built a Solaris box today. I had to search for a couple utilities to complete the task, but the OS doesn't come configured with an index. I executed the catman utility to build the windex database. Here's the syntax:
#catman -w

Now I can use the man -k pattern to search the database. The -k is the keyword option.

e.g. man -k hme (finds 100Mb NIC interface information)

Restrict Row Count (Database) -- Sybase

Yesterday, a co-worker of mine asked me how to restrict the number of rows for his select statements. He only wanted 10-20 row returns but his queries returned thousands. By the way, we are running Sybase 12.0 DBMS.

Here's what we came up with.
1>use database
2>go
1> set rowcount 10
2> go
1> select * from table where ID='XXXXX'
2> go

Reset to default definition.
1> set rowcount 0
2> go

Wednesday, September 20, 2006

Extracting an Archive From 4mm/8mm Tape

I'm continuing to build on my last post. Moreover, I use tar to extract archive files and directories from tape. This is a lifesaver when you have to restore critical file(s) or directories.

1. tar xvfp /home/directory/filename.tar directoryname

e.g. #tar xvfp /home/esofthub/esofthub.tar esofthub

The aforementioned action extracts the esofthub directory from the esofthub.tar file.

tar – Tape archive utility
xvfp – Extract, verbose, file, preserves permissions -- flags/options
/home/esofthub/esofthub.tar – A tarball
esofthub – The esofthub directory and its contents

2. #tar xvfp /dev/rmt/0 /home/esofthub/esofthub.tar
/dev/rmt/0 – Here’s how to extract a tarball file from tape.

3. #tar xvfp /dev/rmt/0
/dev/rmt/0 – Here’s how to extract all the contents from tape.

Monday, September 18, 2006

Creating an Archive to 4mm/8mm Tape

Tape archive is another utility that I use frequently. I used it to archive files and directories. It is really handy when you want to ftp a group of files or directories.

1. tar cvfp /home/directory/filename.tar directoryname

e.g. #tar cvfp /home/esofthub/esofthub.tar esofthub

tar – Tape archive utility
cvfp – Create, verbose, file, preserves permissions -- flags/options.
/home/esofthub/esofthub.tar – A tarball file
esofthub – The esofthub directory and its contents

2. #tar cvfp /dev/rmt/0 /home/esofthub/esofthub.tar
/dev/rmt/0 – Here’s how you archive to a tape device.

Saturday, September 16, 2006

An Inline Shell Script with a For Loop

Often I'm asked how to traverse a list of items in a file. You can easily go through a list of items using a for loop. Here's an example of copying selected contents of originalDir to destinationDir via the command line.

#sh
#for i in `cat /home/esofthub/mylist.dat`
#do
#cp -pr /originalDir/$i /destinationDir/.
#echo $i done
#done

sh – shell

cat – lists each item in the list one iteration at a time

cp – the copy utility for a local workstation (plain files and directories, no symbolic links)

-pr – these options preserve the permission, "p" and copies recursively, "r"

echo – lists the item copied

Perform Recursive Searches for Strings in Hidden Files

I am often asked how to locate certain strings in a directory path. Most of the time, the user is looking for a string they saved into a file in their home directory. But often they forget which file the string was saved to and only remember parts of the string. I had one user who forgot he saved a control sequence to a hidden file. He only remembered a few characters of the string.

This is only an example and for illustration purposes.

# cd $HOME
# find . -type f | xargs grep -i 43Y
./.futureref:43YJJI16
./mydir1/.controlstrings:43Y1ZHFE
./saved/future/.futureref:43YTHI14

Note: More info on hidden files (Find, Copy or Delete Hidden Files)

Find, Copy or Delete Hidden Files in a Directory

I'm often asked where are the hidden files located on a system. My response to a user: Mostly in your home directory. Most are probing for their .profile or .cshrc file. I tell them to use the ls command coupled with the "-a" option. The "-a" shows the hidden files.

# cd /home/esofthub
# ls -la

Bonus: Copy hidden files or directories to a directory or delete hidden files and directories from a directory (per reader's request).

# cp -p .hiddenfile my_destination_directory
# cp -p .login my_destination_directory
# cp -pr .hiddendirectory my_destination_directory
# cp -pr .* my_destination_directory (copies all hidden files and hidden directories recursively)

To delete a hidden file or directory, make sure you know where you are at before performing the activities below.

# pwd
# rm .hiddenfile
# rm -r .hiddendirectory

To delete hidden files and directories as a wildcard (deletes all hidden files in the current directory and directories recursively)
# rm -r .*

Even though I was referring to $HOME, this reader makes a good point...watch where you are at on the system - pwd

Petr Smid said...

Be CARFEUL!!! If you do rm -rf .* you will delete the entire disk (because .* applies to .. as well)