Linux Shell Script Questions and Answers #3

How will you create a swap size in your environment? And how will you find free space in swap and RAM in your environment?

To find RAM size

[oracle@sss-oracle ~]$ grep MemTotal /proc/meminfo
MemTotal:      1035064 kB
[oracle@sss-oracle ~]$ grep SwapTotal /proc/meminfo
SwapTotal:     2097144 kB
[oracle@sss-oracle ~]$ free -l
total       used       free     shared    buffers     cached
Mem:       1035064     867052     168012          0      89100     592468
Low:        904056     761404     142652
High:       131008     105648      25360
-/+ buffers/cache:     185484     849580
Swap:      2097144        820    2096324

If you’re short on swap space, you can temporarily add a swap file to your server. As the root user, run the following commands to add approximately 1GB of swap space:

# dd if=/dev/zero of=tempswap bs=1k count=1000000
# chmod 600 tempswap
# mkswap tempswap
# swapon tempswap
Verify that the swap space was added with the -s option of the swapon command:
# swapon -s
To remove the temporary swap file, as root run the following commands:
# swapoff tempswap
# rm tempswap

After disabling the swap file, you should see the swap space in /proc/meminfo return to its original value.
 

How will you print the 25th line in your file?

$ cat -n filename|grep 25
or
$ head -25 filename | tail -1
 

Write a shell script to  check analyzed objects

#######################################################################
#
#
# check_analyze.sh
#
# Script for checking analyzed objects

#
#########################################################################

for i in `echo $*`
do
echo " "
echo " "
echo "---------- Analyzed status of  $i   -------------"
echo " "
echo " "

sqlplus -s /nolog <<EOF
conn / as sysdba
select table_name,last_analyzed from dba_tables where owner=upper('$i');
exit
EOF
done

output:

[oracle@sss-oracle ~]$ ./check_analyze.sh test scott
 

---------- Analyzed status of  test   -------------
 
 

TABLE_NAME                     LAST_ANAL
------------------------------ ---------
A
 
 

---------- Analyzed status of  scott   -------------
 
 

TABLE_NAME                     LAST_ANAL
------------------------------ ---------
DEPT                                   30-AUG-15
EMP                                     30-AUG-15
BONUS                                30-AUG-15
SALGRADE                         30-AUG-15
B                                          30-AUG-15

Linux Tips

More Linux Questions

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.