script to install own sql script
V1.0.0
#!/usr/bin/env bash
echo “Enter the user name who will be the owner of this script \n”
read $user
for sqlfile in $(ls -l *.sql |awk ‘{print $9}’); do
# echo $sqlfilei
echo “sqlplus / as sysdba @$(pwd)/$sqlfile” > ${sqlfile%.*}.sh
install -c ${sqlfile%.*}.sh /usr/local/bindone
chown -R $user:dba .
chmod -R 755 .
Perl format but it has some fault
#!/usr/bin/perl
##use Fcntl; #The Module
$dirtoget=”.”;
opendir(IMD, $dirtoget) || die(“Cannot open directory”);
@thefiles= readdir(IMD);
#closedir(IMD);
chomp($pwd = `pwd`); # running unix command “free”
print “$pwd \n” ;open(TEXT,”>>newtext.txt”);
#printf TEXT “@thefiles”;
foreach $f (@thefiles)
{
unless ( ($f eq “.”) || ($f eq “..”) || ($f eq “creating-file.pl”))
{
$filename=”@” . $pwd . “/” . $f;
print “$filename \n”;open(SCRIPTS,”>>$f”);
printf SCRIPTS “sqlplus / as sysdba $filename \n”;
close(SCRIPTS);
# system(“install -c /usr/local/bin”);
}
}
close (TEXT);
closedir(IMD);
v1.0.1
#!/usr/bin/env bash
echo “Enter the user name who will be the owner of this script \n”
read $user
##############################################################################
# THIS PART OF THE SCRIPT IS GENERATING SOME SHELL SCRIPT
# WHICH WILL CALL SOME SQL SCRIPT
##############################################################################for sqlfile in $(ls -l *.sql |awk ‘{print $9}’); do
# echo $sqlfilei
echo “sqlplus / as sysdba @$(pwd)/$sqlfile” > ${sqlfile%.*}.sh
install -c ${sqlfile%.*}.sh /usr/local/bindone
chown -R $user:dba .
chmod -R 755 .##############################################################################
# THIS PART OF THE SCRIPT IS MAKING SHELL SCRIPTS
# TO BE CALLED FROM ANY USERS’ HOME
##############################################################################for shfile in $(ls -l *.sh |awk ‘{print $9}’); do
install -c $shfile /usr/local/bin
donerm -rf /usr/local/bin/$0
exit 0
Leave a comment
Comments 0