Uppercase to lowercase or vice versa
The bash version 4.x+ got some interesting new features. Type the following commands to convert $VAR into uppercase:
VAR="All THIS will be in UppER Case"
echo "${VAR^^}"
Sample outputs:
ALL THIS WILL BE IN UPPER CASE
Type the following commands to convert $VAR into lowercase:
VAR="All THIS will be in lOWer Case"
echo "${VAR,,}"
Sample outputs:
all this will be in lower case
Tuesday, February 16, 2016
Thursday, November 19, 2015
Shell Script for log file cleanup
Problem :
lets find the list of file that are older than 30days. That has extension of *.log
-rw-r--r-- 1 oracle oinstall 513 Jul 28 08:27 change_pass.sql
-rw-r----- 1 oracle oinstall 188416 Jul 30 11:37 testnetlink.dmp
-rw-r--r-- 1 oracle oinstall 1477 Jul 30 11:37 impi_temp.log
-rw-r--r-- 1 oracle oinstall 1433 Jul 30 12:58 impi1_temp.log
Requirement :
Now I want to remove the files that are older than 30 days and at same time I want keep a log of the files that are being deleted.
### Script starts here ###
#!/usr/bin/ksh
cd /u01/app/oracle/dpump; ## location where I want to cleanup the log files
echo " we are now in : `pwd`"
for FILE in `find /u01/app/oracle/dpump/*.log -mtime +30`
do echo $FILE
rm -f $FILE ##2>/dev/null # Gets rid of directory or permission errors
done 2>&1 1> /u01/app/oracle/dpump/log.txt
sample output of log file :
lets see what is captured in cleanup log file.
cat u01/app/oracle/dpump/log.txt
u01/app/oracle/dpump/AUDIT_PART1.log
/u01/app/oracle/dpump/impi1_temp.log
/u01/app/oracle/dpump/impi_temp.log
/u01/app/oracle/dpump/test1.log
lets find the list of file that are older than 30days. That has extension of *.log
-rw-r--r-- 1 oracle oinstall 513 Jul 28 08:27 change_pass.sql
-rw-r----- 1 oracle oinstall 188416 Jul 30 11:37 testnetlink.dmp
-rw-r--r-- 1 oracle oinstall 1477 Jul 30 11:37 impi_temp.log
-rw-r--r-- 1 oracle oinstall 1433 Jul 30 12:58 impi1_temp.log
Requirement :
Now I want to remove the files that are older than 30 days and at same time I want keep a log of the files that are being deleted.
### Script starts here ###
#!/usr/bin/ksh
cd /u01/app/oracle/dpump; ## location where I want to cleanup the log files
echo " we are now in : `pwd`"
for FILE in `find /u01/app/oracle/dpump/*.log -mtime +30`
do echo $FILE
rm -f $FILE ##2>/dev/null # Gets rid of directory or permission errors
done 2>&1 1> /u01/app/oracle/dpump/log.txt
sample output of log file :
lets see what is captured in cleanup log file.
cat u01/app/oracle/dpump/log.txt
u01/app/oracle/dpump/AUDIT_PART1.log
/u01/app/oracle/dpump/impi1_temp.log
/u01/app/oracle/dpump/impi_temp.log
/u01/app/oracle/dpump/test1.log
Thursday, November 5, 2015
shell script to find files in a directory
####This script starts here ####
###This script cheks if the a file exist current Directory ##
## script will propmt for filename ##
#!bin/ksh
echo "eneter Filename :"
read DUMPFILE;
echo " **** checking if the File exists **** "
if [ -e ${DUMPFILE} ];
then
echo " **** Given file exists in directory `pwd` ****"
else
echo " **** ERRR : Given file does not exist in directory `pwd` ****"
fi
Lets see how to use this code :
atoorpu@Linux01:[~/scripts] $ ls -al testfile
ls: testfile: No such file or directory
atoorpu@Linux01:[~/scripts] $ . check_file.sh
eneter Filename :
testfile
**** checking if the File exists ****
**** ERRR : Given file does not exist in directory /home/atoorpu/scripts ****
atoorpu@Linux01:[~/scripts] $ touch testfile
atoorpu@Linux01:[~/scripts] $ ls -al testfile
-rw-rw-r-- 1 atoorpu atoorpu 0 Oct 23 14:03 testfile
atoorpu@Linux01:[~/scripts] $ . check_file.sh
eneter Filename :
testfile
**** checking if the File exists ****
**** Given file exists in directory /home/atoorpu/scripts ****
atoorpu@Linux01:[~/scripts] $
atoorpu@Linux01:[~/scripts] $
using UNIX pipes to export oracle table and compress
Script explanation:
This script is to export the dump file and compress the exported data using UNIX pipes. This method is best suited when there is not enough space on disk. The file exported and compressed at same time, this method will not require much space while exporting the dumpfile.
Note: Using of UNIX pipe's will also speed up the export process & yes there will consume a good amount of CPU.
#!/usr/bin/ksh:
This script is to export the dump file and compress the exported data using UNIX pipes. This method is best suited when there is not enough space on disk. The file exported and compressed at same time, this method will not require much space while exporting the dumpfile.
Note: Using of UNIX pipe's will also speed up the export process & yes there will consume a good amount of CPU.
#!/usr/bin/ksh:
#### This script will export the dumpfile and compress at same time using linux pipe
#### You can use normal gunzip cmd to unzip the zipped file
####
export mydate=`date "+%d%b%Y"`;
export TEST_BAK=TEST_MKNOD_"$mydate";
DUMPFILE=$TEST_BAK".dmp"; ## Setting dumpfile name here
LOGFILE=$TEST_BAK".log"; ## Setting logfile name here
DPUMP=/u01/app/oracle/dpump; ## Setting target directory for dump & log
## create exp
## you can use the pipe for compress the file
mknod $DPUMP/exp.pipe p
## compress dmp with file using pipe
gzip < $DPUMP/exp.pipe > $DPUMP/$DUMPFILE.gz &
exp USERNAME/PASSWORD@ORCL file="$DPUMP"/exp.pipe log="$DPUMP/$LOGFILE" tables=TEST statistics=none
## remove the pipe created
rm $DPUMP/exp.pipe
echo $' \n ';
echo " export completed "
Shell script - Check if the files exists in a file
#!/usr/bin/kshecho " File name please : "read FILENAME;dataDir=/u01/app/oracle/dpump; ### Directory to look for a file ###sourceFile=SCOTT.dmp; ### file name to search for ###cd /u01/app/oracle/dpump;echo " Present directory : " `pwd`"";##Did we get a file?if [ -e ${dataDir}/${sourceFile} ];thenecho "Found file !! "elseecho " No file found !!! "fi |
Backup unix files and folders using tar - compress and backup files
Because of various reasons some of which hearken back to the era of tape drives, Unix uses a program named tar to archive data, which can then be compressed with a compression program like gzip, bzip2, 7zip, etc.
In order to "zip" a directory, the correct command would be
tar -zcvf archive.tar.gz directory/
This will tell tar to c (create) an archive from the files in directory (tar is recursive by default), compress it using the z (gzip) algorithm, store the output as a f (file) named archive.tar.gz, and v (verbosely) list all the files it adds to the archive.
To decompress and unpack the archive into the current directory you would use
----------------------------------
ARCHIVE FOLDER CONTENTS & CREATE NEW BACKUP FILE:
----------------------------------
atoorpu@linux01:[~] $ tar -zcvf Output_File.tar.gz SourceFile
ziptest/
ziptest/readme1.txt
--->>> Output_File.tar.gz >>> output file
--->>> SourceFile >>> source directory
atoorpu@linux01:[~] $ ls
oswbb733.tar patches readme.txt sys_checker.sh ziptest.tar.gz
p19543113_851499_Linux-x86-64.zip pitt_4_21_2014.dmp.gz scripts ziptest1
LIST CONTENTS OF TAR FILE:
atoorpu@linux01:[~] $ tar -ztvf ziptest.tar.gz
drwxrwxr-x atoorpu/atoorpu 0 2015-08-27 14:16:41 ziptest/
-r--r--r-- atoorpu/atoorpu 50 2015-08-27 14:14:20 ziptest/readme1.txt
----------------------------------
EXTRACT/UNTAR THE FILE USE :
----------------------------------
To extract one or more members from an archive, enter:
$ tar -zxvf {file.tar.gz}
If your tarball name is backup.tar.gz, enter the following at a shell prompt to extract files:
$ tar -zxvf backup.tar.gz
To extract resume.doc file from backup.tar.gz tarball, enter:
$ tar -zxvf backup.tar.gz resume.doc
Simple Shell script to execute a sql from UNIX
This is a simple shell script to execute a sql from UNIX shell script.
#!/usr/bin/ksh
export ORACLE_SID=ORCL
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export PATH=$ORACLE_HOME/bin:/usr/local/bin:$PATH
export mydate=`date "+%d%b%Y"`
echo " ************** EXECUTING SQL STARTS HERE ************ "
sqlplus -s USERNAME/PASSWORD@ORCL > /u01/app/oracle/dpump/test.log <<EOF
SET SERVEROUTPUT ON;
SET FEED OFF;
select name from v\$database;
SET SERVEROUTPUT OFF;
EOF
echo " ************** END OF SQL HERE ************ "
Subscribe to:
Posts (Atom)