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.
Tuesday, July 31, 2007
View the Value of a UNIX Variable
Set variable
# csh
# setenv ESOFT /export/home/esofthub
or
# sh
# ESOFT=/export/home/esofthub; export ESOFT
View variable contents
# echo $ESOFT
/export/home/esofthub
# env | grep ESOFT
ESOFT=/export/home/esofthub
Other miscellaneous uses
# cd /
# cd $ESOFT; pwd
# ls $ESOFT
# $ESOFT/myscript.csh
THIS IS A TEST
Monday, July 30, 2007
Copy the Contents of a Magnetic Tape to Another
# mt -f /dev/rmt/0 rewind
# mt -f /dev/rmt/1 rewind
# tcopy /dev/rmt/0 /dev/rmt/1
Clear the Terminal Screen
# clear
Saturday, July 07, 2007
Send Message to Users with Write All Command
This message is just for illustration purposes and hardly constitutes an emergency.
# wall
I hope everyone had a great and safe 4th of July weekend.
control+d
Using the Common UNIX Find Command
# cd /export/home/esofthub
Find a file or directory
# find . -name TEMP -print
or
# find . -name TEMP -exec echo {} \;
Find core files in this directory tree and remove them
# find . -name "core" -exec rm -f {} \;
Find junk directories and remove their contents recursively
# find . -name "junk" -exec rm -rf {} \;
Find files not starting with "junk" OR not ending with "log"
# find . ! \( -name "junk*" -o -name "*log" \) -print
Find a pattern in a file using the recursive grep (ignore case)
# find . -type f | xargs grep -i MYPATTERN
# find . -name '*.sh' -exec grep -i MYPATTERN {} \;
Find files modified in the past 7 days
# find . -mtime -7 -type f
Find files owned by a particular user
# find . -user esofthub
Find all your writable directories and list them
# find . -perm -0777 -type d -ls
or
# find . -type d -perm 777 -print
Find all your writable files and list them
# find . -perm -0777 -type f -ls
or
#find . -type f -perm 777 -print
Find large file sizes and list them or output to file
# find . -type f -size +1000 -ls
or
# find . -type f -size +1000 -print
# find . -type f -size +2000K | tee filename
Find how many directories are in a path (counts current directory)
# find . -type d -exec basename {} \; | wc -l
53
Find how many files are in a path
# find . -type f -exec basename {} \; | wc -l
120
Find all my pipe files and change their permissions to all writable
# find . -name "pipe*" -exec chmod 666 {} \;
Find files that were modified 7 days ago and archive
# find . -type f -mtime 7 | xargs tar -cvf `date '+%d%m%Y'_archive.tar`
Find files that were modified more than 7 days ago and archive
# find . -type f -mtime +7 | xargs tar -cvf `date '+%d%m%Y'_archive.tar`
Find files that were modified less than 7 days ago and archive
# find . -type f -mtime -7 | xargs tar -cvf `date '+%d%m%Y'_archive.tar`
Find files that were modified more than 7 days ago but less than 14 days ago and archive
# find . -type f -mtime +7 -mtime -14 | xargs tar -cvf `date '+%d%m%Y'_archive.tar`
Find files in two different directories having the "test" string and list them
# find esofthub esoft -name "*test*" -type f -ls
Find files in two different directories having the "test" string and list them
# find esofthub esoft -name "*test*" -type f -ls
Find files in two different directories having the "test" string and count them
# find esofthub esoft -name "*test*" -type f -ls | wc -l
12
Find files and directories newer than CompareFile
# find . -newer CompareFile -print
Find files and directories older than CompareFile
# find . ! -newer CompareFile -print
Find files and directories but don't traverse a particular directory
# find . -name RAID -prune -o -print
Find all the files in the current directory
# find * -type f -print -o -type d -prune
Find files associated with an inode
# find . -inum 968746 -print
# find . -inum 968746 -exec ls -l {} \;
Find an inode and remove
# find . -inum 968746 -exec rm -i {} \;
Friday, July 06, 2007
Enable Stop-A or Disable Stop-A
To enable Stop-A, prepend an asterisk, "*", to the following line in the /etc/system file.
# vi /etc/system
...
*set abort_enable = 0
OR
set abort_enable = 1
:wq!
# init 6
To disable Stop-A, add "set abort_enable = 0" to the /etc/system file
# vi /etc/system
...
set abort_enable =0
:wq!
# init 6
Disable C2 Security Audits on Solaris
Go to single user state
# init s
# cd /etc/security
# ./bsmunconv
This script is used to disable the Basic Security Module (BSM).
Shall we continue the reversion to a non-BSM system now? [y/n] y
bsmunconv: INFO: moving aside /etc/security/audit_startup.
bsmunconv: INFO: restore /etc/rc2.d/S92volmgt.
bsmunconv: INFO: removing c2audit:audit_load from /etc/system.
bsmunconv: INFO: stopping the cron daemon.
The Basic Security Module has been disabled.
Reboot this system now to come up without BSM.
# init 6
Enable C2 Security Audits on Solaris
# cd /etc/security
# ./bsmconv
This script is used to enable the Basic Security Module (BSM).
Shall we continue with the conversion now? [y/n] y
bsmconv: INFO: checking startup file.
bsmconv: INFO: move aside /etc/rc2.d/S92volmgt.
bsmconv: INFO: turning on audit module.
bsmconv: INFO: initializing device allocation files.
The Basic Security Module is ready.
If there were any errors, please fix them now.
Configure BSM by editing files located in /etc/security.
Reboot this system now to come up with BSM enabled.
# init 6
By the way, the binary audit files (default directory /var/audit) are a bit cryptic. Use the praudit command to convert files to a ASCII format. Also, the /etc/rc2.d/S92volmgt file was moved to /etc/security/spool.
Thursday, July 05, 2007
Drop User From a Sybase Database
Denying user access to a database is a fairly simple task. The sp_dropuser stored procedure makes this task possible. However, there are some things you need to ensure beforehand. First, ensure the user doesn't own any objects in the database and has grant privileges or owns the database. Usually, I like to verify the action was performed by performing a quick select on the affected table. Here is the syntax for dropping a user in Sybase.
1> sp_dropuser esofthub
2> go
1> select * from sysusers
2> go
Drop a Sybase Group
1> sp_dropgroup esoftdb_group
2> go
Change a Sybase User's Group
The user "esofthub" belongs to the mynewgroup and public.
1> sp_changegroup mynewgroup, esofthub
2> go
To remove a user from a group affiliation, here's an example.
1> sp_changegroup "public", esofthub
2> go
Create a Sybase Group
# isql -Usa -Ppassword
1> use esoftdb
2> go
1> sp_addgroup esoftdb_group
2> go
Determine groups in a database
# isql -Usa -Ppassword
1> use esoftdb
2> go
1> sp_helpgroup
2> go
Determine users in a specific group
1> sp_helpgroup esoftdb_group
2> go
Dumping Sybase Transaction Log
Here is the syntax.
# isql -Usa -Ppassword
1> use esoftdb
2> go
1> dump tran esoftdb with no_log
2> go
Display Sybase Login Information
The sp_displaylogin reports information on a login in Sybase. It gives detailed information such as, user identification, full name, roles, and account status. Here is its syntax.
For privilege roles
This example provides information about a privileged user.
# isql -
1> sp_displaylogin esofthub
2> go
For non-privilege roles
# isql -Uesofthub -Panypassword
1> sp_displaylogin
2> go
Change Default Database for Sybase User
Here is a quick way to change the default database for a user in Sybase. This is a fairly common database administration (DBA) task which I have done on several occasions. The change can be done with the sp_modifylogin stored procedure. In the SQL example below, the esofthub login is being assigned the esoftdb as its default database. Here is its syntax.
# isql -
1> sp_modifylogin esofthub, defdb, esoftdb
2> go
Tuesday, July 03, 2007
Change Password for a Sybase User
Changing passwords for a Sybase user is a fairly straightforward process. The first example deals with changing the “sa” password (privilege user) or another user's password. The second example is when a user changes their password. Here is the syntax.
Note: If your password string begins with a number, enclose it in "quotes."
# isql -
1> sp_password old_password, new_password, sa
2> go
Changing another user's password
# isql -
1> sp_password old_password, new_password, esofthub
2> go
Any user can change their own password
# isql -Uesofthub -Pesofthub_password
1> sp_password old password, new_password
2> go
Reset sa Password for Sybase
Run a tail -f to observe the new SSO password in the log.
# tail -f SYBASE.log
The dataserver should not be running
# ps -ef | grep dataserver
Append the following entry, -psa, to this file
# vi RUN_ESOFTHUB_SVR
...
-psa
:wq!
Starts the dataserver
# startserver -f RUN_ESOFTHUB_SVR
Observe the new password in the console or SYBASE.log
# vi RUN_ESOFTHUB_SVR
...
-psa (delete this line)
:wq!
# isql -Usa -Pfrom_the_log_file
Now use sp_password to change the "sa" password to something permanent.
Monday, July 02, 2007
Using UNIX Redirection Symbols for Sybase
# isql -Usa -Pyourpassword -Syourserver_name << ESOFT > myoutput
use esoftdb
go
select count(*) from mysoft_table
go
ESOFT
View the results
# cat myoutput
Read SQL from a file
# isql -Usa -Pyourpassword -Syourserver_name < ESOFTFILE > myoutput
View the results
# cat myoutput
Start a Sybase Adaptive and Backup Server
Starts only the Adaptive Server
# startserver -f RUN_ESOFTHUB_SVR
Starts both the Adaptive and Backup servers
# startserver -f RUN_ESOFTHUB_SVR -f RUN_SYB_BACKUP
Starts only the Backup Server
# startserver -f RUN_SYB_BACKUP
If you want to shutdown the dataserver, go to this post:
Shutdown DBMS (Sybase)
Sunday, July 01, 2007
Terminate or Kill a Sybase Process
From time to time, you may need to kill an internal Sybase process or processes. This requires using Sybase’s sp_who command ascertain the process identification or PID. Then you will use the kill command. Here is a run of how to kill a process via SQL.
1> sp_who
2> go
1> kill PID
2> go
I always like to reconfirm that the process or processes was/were killed.
1> sp_who
2> go
For a specific login
1> sp_who esofthub
2> go
1> kill esofthub_PID
2> go