mercoledì 19 dicembre 2012

Is it possible to pass passwords on a bash shell script?

Yes, it is possible.

One way is this :


#!/bin/bash
printf "Password please: "
stty -echo
read pass
stty echo
printf '\n'

Stay tuned.


martedì 2 ottobre 2012

Script SQL to calculate averange row size and total table size

Today an sql script to calculate averange row len and total table size (Is extracted from the Knowledge Xpert for Oracle Administration library).

REM LOCATION: Object Management\Tables\Utilities
REM FUNCTION: Display the average row size of table and total table
REM size
REM TESTED ON: 10.2.0.3, 11.1.0.6 (should work with Oracle 9iR2)
REM PLATFORM: non-specific
REM REQUIRES: dba_tables, dba_extents
REM
REM INPUTS: Owner of table and name of table to report on
REM NOTE: This report requires that the table be analyzed.
REM
REM
REM This is a part of the Knowledge Xpert for Oracle Administration library.
REM Copyright (C) 2008 Quest Software
REM All rights reserved.
REM
REM ******************** Knowledge Xpert for Oracle Administration ********************
UNDEF ENTER_OWNER_NAME
UNDEF ENTER_TABLE_NAME
SET PAGESIZE 66 HEADING ON VERIFY OFF
SET FEEDBACK OFF SQLCASE UPPER NEWPAGE 3
UNDEF ENTER_OWNER_NAME
UNDEF ENTER_TABLE_NAME
COLUMN table_name format a30 wrap
COLUMN avg_row_len format 9,999,999,999 heading "Average|Row|Length"
COLUMN actual_size_of_data format 9,999,999,999 heading "Total|Data|Size"
COLUMN total_size format 9,999,999,999 heading "Total|Size|Of|Table"
TTITLE left _date center "Table Average Row Length and Total Size Report"
WITH table_size AS
(SELECT owner, segment_name, SUM (BYTES) total_size
FROM dba_extents
WHERE segment_type = 'TABLE'
GROUP BY owner, segment_name)
SELECT table_name, avg_row_len, num_rows * avg_row_len actual_size_of_data,
b.total_size
FROM dba_tables a, table_size b
WHERE a.owner = UPPER ('&INSERT_OWNER_NAME')
AND a.table_name = UPPER ('&INSERT_TABLE_NAME')
AND a.owner = b.owner
AND a.table_name = b.segment_name;

Stay tuned.

lunedì 4 giugno 2012

giovedì 31 maggio 2012

Advanced Bash-Scripting Guide


Today I want to recommend an excellent manual on programming ofadvanced bash shell.


These are the links :


(html version) http://www.tldp.org/LDP/abs/html/
(pdf version) http://www.tldp.org/LDP/abs/abs-guide.pdf


Stay tuned

Bash shell script to see who is logged on or logged out every 3 seconds

Today a simple bash shell script to check every 3 seconds what user is logged in or logged out.
This script use "who" linux/unix command, result of these command is saved on a file that is checked every 3 seconds with new who execution :


#!/bin/bash
# + Giovanni Palleschi
# + 05/30/2012 13:23
# + Who is logged on or logged out every 3 seconds
echo 'The current time is:'
date
echo ' '
# List Current Users Connected
echo 'The current users are:'
who | cut -d' ' -f1 | sort -u > ./list_user_before
cat ./list_user_before
# Loop control login - logout every 3 seconds
while [ 1 ]; do
   sleep 3
# List Current Users Connected
   who | cut -d' ' -f1 | sort -u > ./list_user_after
# List of New Users Connected
   echo ' '
   diff ./list_user_before ./list_user_after | grep "^>" | cut -d' ' -f2 |
   while read new_user_login
   do
     echo 'User' $new_user_login 'has logged in.'
     echo ' '
   done
# List of Users Disconnected
   diff ./list_user_before ./list_user_after | grep "^<" | cut -d' ' -f2 |
   while read new_user_login
   do
     echo 'User' $new_user_login 'has logged out.'
     echo ' '
   done
   tot_users_diff=$(diff ./list_user_before ./list_user_after | wc -l)
   if [ $tot_users_diff -eq 0  ]; then
     echo 'No user has logged in/out in the last 3 seconds.'
   fi
# Move file list user after in file user before  for next control
   mv -f ./list_user_after ./list_user_before
done

Stay tuned.

giovedì 17 maggio 2012

Ksh script to remove shared memory

Today a simple script to remove shared memory in ksh :


#!/bin/ksh


#
# Shell Script to remove shared memory MVNO Instance
#


PID=$(ipcs -m | grep 0x000000a[0-9a-b] | awk '{print $2}'|xargs)
for one_pid in ${PID}; do
    ipcrm -m ${one_pid}
    echo 'Removed shm : ' ${one_pid}
done

This script remove all shared memory from address 0x000000a0 to 0x000000ab. You must modify this expression to remove another shared memory.

Stay tuned.


lunedì 5 marzo 2012

Arithmetic calculation on real numbers in Ksh Script

Today a simple program to execute arithmetic calculation with ksh script :

#!/bin/ksh
echo "Enter the Price of the item \$ \c"
read price
echo "What Percentage of discount is available \c"
read per
echo "Your Total Savings are \c"
sav=`echo "scale=3\n(($price * $per) / 100)" | bc -l`
echo $sav

Is important see this command :

sav=`echo "scale=3\n(($price * $per) / 100)" | bc -l`

With "scale=3" we are fixing number of decimals to print.
With "bc -l" we are calculating with unix command bc the discout applied, with
($price * $per) / 100.

Stay tuned.


Dice simulator

Today a simple shell script to simulate rolls of two dices :

#!/bin/ksh

fc=1

while [ fc -eq 1 ]; do

clear

echo ' How many rolls : \c'
read times

ind=1
while [ $ind -le $times ]; do

echo 'Roll Dice ' $ind
dice1=$RANDOM
dice2=$RANDOM

echo 'dice1 :' $(( dice1%6+1 ))
echo 'dice2 :' $(( dice2%6+1 ))

ind=$(( $ind + 1 ))
done

echo ' Continue(y/n) : \c'
read ans

if [ $ans = 'N' ] || [ $ans = 'n' ]; then
fc=0
fi

done


Stay Tuned.

mercoledì 29 febbraio 2012

Awk

Hello everyone

Today i want share a good awk tutorial :


Stay tuned.

Substring variable length record with awk.

The daily problem is this : I must print from third field to end of all records in a file where fields are separated from Tab character.

To resolve this problem i use awk in this way :

cat | awk -F" " '{ printf "%s\n",substr($0,index($0,$3)) }'

Where in -F awk option I specify tab character, and I use substr with index function of third field in each record read.

Stay tuned.





giovedì 23 febbraio 2012

giovedì 12 gennaio 2012

Year 2012

Another year :-) 2012.

See now my 2011 objectives :
  • Improve my English Level : So and so
  • Improve my Chess Level : So and so
  • Improve my incomes : Failed
  • Be a better Christian : So and so
  • Learn at least two new programming languages : Failed (Just Perl)

Very very bad results.

So here there is my new list, for 2012, equal to 2011 :
  • Improve my English Level
  • Improve my Chess Level
  • Improve my incomes
  • Be a better Christian
  • Learn at least two new programming languages
I hope that in January 2013 results are better ;-)

Stay tuned.

Check first quarter 2024

 Hi all Today, 1st May I'll check my 2024 goals. This is the first time I check it. For me it's a good way to reach more objective p...