Monday, July 09, 2012

Unix / Linux Miscellaneous Commands

Miscellaneous however important commands used in UNIX/Linux environments.
  1. netstat
  2. 'tar' command
  3. tape archive scripts
 
1. netstat
 
Netstat command examples:
 
# netstat -a | more
/* List all ports (both listening and non-listening ports) */
# netstat -at
/* list all TCP ports */
# netstat -au
/* list all UDP ports */
# nestat -an | grep
/* will check if a port is listening for any service */
# netstat -ap | grep
/* on which port a program is running eg. netstat -ap | grep tnslsnr; netstat -ap | grep ssh; */
# netstat -lx
/* list only the listening UNIX ports */
# netstat -ie
/* display extended information on the interfaces (similar to ifconfig) */
# netstat -r
/* display the kernel routing information */
 
 
2. 'tar' command
 
Good practice for compressing a file is to archive the files first and then compress them. So to create an archive of a disk archive that contains a group of files or an entire directory , we should use the tar utility. Another advantage of the tar is that it also compresses the file to some extent. So using tar with gzip means double layer compression. To use the tar we should need to know some of its options:
 
     c: (c)reate an archive
     x: e(x)tract from an archive
     t: lis(t) the files in archive
     f: (f)ile instead of tape
 
# tar cvzf  $ORACLE_HOME
/* will compile all files in $ORACLE_HOME into a single compressed (.gz) into the location from where
it is executed. */
# tar -zxvf weekly_bkp.tar.gz
/* will extract the compressed tar file into the location from where it is executed. ensure the compressed
archived folder is not already existing, otherwise it will overwrite. */
# tar -cvf cold_rman.tar cold/ rman/
/* will generate a single tar file with 'cold/' and 'rman/' folders. */
# tar -xvf cold_rman.tar
/* will extract the 'cold/' and 'rman/' into the current location from where it is run */
# tar -cf archive.tar myDirectories/
/* creates a tape archive. 'v' flag prints out extra messages, as verbose mode, though it's not related to
extracting files. */
# tar -tf archive.tar
/* it's generally a good idea to preview the contents of tape archives before unpacking them. */
# tar -xf archive.tar
/* extracts archive.tar into the current location */
# tar -xf archive.tar
/* will extract the target file */
# tar -xf dbuat01_bkp.tar rman/dbuat01_controlfile_trace.txt
/* will extract the partial pieces from the archive (eg. 'rman/dbuat01_controlfile_trace.txt') */
# tar -czvf archive.tgz cold/ rman/
/* will generate a single compressed archive with 'cold/' and 'cold/' */
# tar -zxvf cold_rman.tgz
/* will extract the compressed tar file into the current location. list the contents first before
extracting the files or folders */
# find . -type d -mtime -7 | xargs tar -rf weekly_backup.tar # gzip weekly_backup.tar # tar -zxvf weekly_backup.tar.gz
/* 1. will tar all files or folders. '-r' option appends files to an archive 2. will zip the target tar file
3. will unzip and untar the archive to the current location from where it is run */
# tar -cvzf # tar -cvzf jpg_archive.tar.gz /path/to/images/*.jpg
/* will archive and compress */
# gunzip jpg_archive.tar.gz
/* will unzip */
# tar -xvf jpg_archive.tar
/* will untar */
# tar cvf - cold/ rman/ | gzip > dbuat01_bkp.tar.gz
/* will generate a single compressed archive */
 
 
3. tape archive scripts
 
The following script will archive a backup location to media tapes:
 
#!/bin/ksh
export log_loc="/u02/backup/logs/dbuat01_rman_bkp_logs"
echo 'DBUAT01 DAILY RMAN BACKUP'
cd /
date > `date "+$log_loc/dbuat01_cold_rman_bkp_%d_%h_20%y_%H_%M_start_time"`
tar -cvf /dev/rmt0 /u02/oradata/dbuat01/backup/cold/ /u02/oradata/dbuat01/backup/rman/
date > `date "+$log_loc/dbuat01_cold_rman_bkp_%d_%h_20%y_%H_%M_end_time"`
date > `date "+$log_loc/dbuat01_cold_rman_bkp_%d_%h_20%y_%H_%M_verify_start_time"`
tar -tvf /dev/rmt0 > `date "+$log_loc/dbuat01_cold_rman_bkp_%d_%h_20%y_%H_%M_contents_list"`
date > `date "+$log_loc/dbuat01_cold_rman_bkp_%d_%h_20%y_%H_%M_verify_end_time"`
exit
 
Another example:
 
#!/bin/ksh
log_loc="/u02/backup/logs/dbuat01_rman_bkp_logs"
export log_loc
echo 'DAILY RMAN BACKUP OF DBUAT01'
cd /
date > `date "+$log_loc/%d_%h_20%y_%H_%M_DBUAT01_Daily_Bkp_Start_Time"`
tar -cvf /dev/rmt2 /u02/oradata/backup/dbuat01/
date > `date "+$log_loc/%d_%h_20%y_%H_%M_DBUAT01_Daily_Bkp_Stop_Time"`
date > `date "+$log_loc/%d_%h_20%y_%H_%M_DBUAT01_Daily_Bkp_Verify_Start_Time"`
tar -tvf /dev/rmt2 > `date "+$log_loc/%d_%h_20%y_%H_%M_DBUAT01_Daily_Bkp_Contents_List"`
date > `date "+$log_loc/%d_%h_20%y_%H_%M_DBUAT01_Daily_Bkp_Verify_End_Time"`
exit
 
[ Top ]
 
Last modified: Jul 05, 2012 11:45 IST

No comments: