This blog covers Unix system administration HOWTO tips for using inline for loops, find command, Unix scripting, configuration, SQL, various Unix-based tools, and command line interface syntax. The Unix OS supports tasks such as running hardware, device drivers, peripherals and third party applications. Share tips/comments. Read the comments. But most importantly: Read Disclaimer - Read Disclaimer.
Wednesday, September 27, 2006
Change User/Group Attributes to a File
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
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
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
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
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
#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
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
/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
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
# 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 .*
Be CARFEUL!!! If you do rm -rf .* you will delete the entire disk (because .* applies to .. as well)