Shell Scripts


Que: -   Advantages/disadvantages of script vs compiled program ?
Ans: -     
Shell
1.    In the shell, every command creates a process itself.
2.    It is Slow Processing and takes the too much size in memory.
3.    It is easy to write a program in a shell script with add-on modules like grep, sed, awk etc.
4.    The whole code of shell is in the text file ASCII Character.
5.    For executing we need to change the permission +x OR sh.
Compiled Program
1.    In the whole Program after compiling, it creates a one executable file.
2.    A one program creates one process in the memory during executing of a program.
3.    Here is the code after compiling it converted into Binary code.
4.    It is a very fast execution and output of a program.
5.    It also has compatibility problems between the different platforms.

Que:- Write a script to list all the differences between two directories.
Ans:- 
echo "Enter First absolute dir path."
read path1
echo "Enter Second absolute dir path."
read path2

if [ $path1 -a $path2 ]
then
    echo path is valid
    p1a=`cd $path1|ls -l |awk -F" " '{print $9}'|wc -l`
    p2a=`cd $path2|ls -l |awk -F" " '{print $9}'|wc -l`

    p1b=`du -h $path1`
    p2b=`du -h $path2`

    echo INFORMATIONS ARE:
    echo -e size of dir is: $p1b == $path1\n
    echo -e size of dir is: $p2b == $path2

    echo -e files in: $p1a == $path1\n
    echo -e files in: $p2a == $path2
   
else
    echo path is not valid
fi

Que:- Write a program in any language you choose, to reverse a file.
Ans:-     
1. sed –n ‘1!G; $p; h filename
2. perl     -e ‘print reverse  <>’ filename
3. cat cc|while read line
    do
        a=`echo $line|wc -c`
        i=1
        while [ $a -ge $i ]
        do
            aa=`echo $line|cut -c$a`
            echo -e "$aa\c"
            a=`expr $a - 1`
        done
        echo -e "\n"
    done > bb

4. sed -n '1!G; $p ;h' bb
5. cat file|rev
6. perl –e ‘print scalar reverse <>’ filename

Que:- write a shell script to find ward in the result of displaying all employee name?
Ans:-  
a=`sqlplus -S / as sysdba<<eof
set heading off;
set feedback off;
set pagesize 200
connect scott/tiger;
select ename from emp;
exit
EOF`
echo $a|awk '{print $4}'

 Que:- Send email from your machin to your gmail account?
Ans:-
mailx -s "subject" email@identity
"type something........"
ctrl-d to close

Que:- See the result of SQL statements in Browser with CGI?
Ans:-
In the ORACLE
"create a file with any name and write these contant in this fil"
echo Content-Type: text/html
export ORACLE_HOME=/u0/oracle/product/10.2.0/db_1
export ORACLE_SID=aman
export PATH=$PATH:/usr/local/bin:/usr/ccs/bin:/usr/sfw/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
echo ""
echo ""
echo ""
echo ""
echo ""

sqlplus -S scott/tiger << EOF
set feedback off
set markup html on
select * from emp;
exit
EOF

AFTER we open recent upper file in BROWSER
hostname:80/"filename"

Que:- Download and Install JDeveloper on Solaris?
Ans:-
run java -jar oc4j.jar -install
You run upper command without "INSTALL" option you open it on browser with port no 8888
http://rajesh:8888
set JavaHome
chmod 755
./jdev &

Que:- Using JDeveloper write a java program to connect to DBA and find out the ename from scott table?
Ans:-
IN View Tab --> connection navigator---> click
click on DATABASE tab and create an SQL connection with username or passwd(scott/tiger)
and test connection ("listener and oracle must be running")
right click on created connection and select SQL worksheet.
write SQL statement (select * from emp);
click on the upper execute tab;
after that, you show the list of all employee tables.


Que: Write a shell script for import/export zipped a file and copy to other location and send an email once it was done.
Ans:-
vi expprvn8p1full.sh
echo "Export Started at: `date`"
expdp system/pump5k1n directory=DPUMP dumpfile=PRVN8P1_REQTASK0578156_FULL.dmp logfile=PRVN8P1_REQTASK0578156_FULL.log FULL=Y 
gzip /u002/exp/PRVN8P1/PRVN8P1_REQTASK0578156_FULL.dmp
scp -p /u002/exp/PRVN8P1/PRVN8P1_REQTASK0578156_FULL.dmp.gz oracle@dloradb15:/u001/PRVN8D1
scp -p /u002/exp/PRVN8P1/PRVN8P1_REQTASK0578156_FULL.log oracle@dloradb15:/u001/PRVN8D1
ssh oracle@dloradb15 chmod 644 /u001/PRVN8D1/PRVN8P1_REQTASK0578156_FULL.dmp.gz
ssh oracle@dloradb15 chmod 644 /u001/PRVN8D1/PRVN8P1_REQTASK0578156_FULL.log
echo -e "$ORACLE_SID : Full DB Export completed, File: PRVN8P1_REQTASK0578156_FULL.dmp.gz has been copyed with log.\n\n Thanks & Regard \n Rajesh"|mailx -s "Export Job: $ORACLE_SID Completed on `date`" -c joan.reilly1@bms.com rajesh.kumar16@hpe.com
echo "Finished: `date`"


nohup sh expprvn8p1full.sh > expprvn8p1full.log &



No comments: