Tags » Shell Script

Netezza: get database names into a Bash shell variable

Set a variable DATABASES to loop through later in a for loop:

DATABASES=`nz_get_database_names`

then loop like this

for DATABASE in $DATABASES; do 
    export NZ_DATABASE=\"$DATABASE\"
    # Get the INITIAL list of table names (or schemaname.tablenames)
    if [ "$MultiSchema" = "" ]; then 
           export period_delimiter=$DELIMITER ; 
           unset NZ_SCHEMA ; 
    fi
    TABLES=`nz_get_table_names`
    unset period_delimiter
... 41 more words

SFTP - Secure FTP

Example:

sftp root@192.168.0.1:/etc/http/httpd.conf

When we will go use a connection sftp in some script, we need to generate a authentic key. To generate a key you need to do: 64 more words

Sysadmin

bash root 권한 확인

Bash 스크립트 작성시 ROOT 여부 확인

아래와 같이 코드를 도입부에 추가하면 루트 권한이 있는 경우에만 실행 되도록 할 수 있습니다.

#!/bin/bash
ROOT_UID=0
E_NOTROOT=67

if [ "$UID" -ne "$ROOT_UID" ]
then
    echo "Script have to execute on ROOT mode"
    exit $E_NOTROOT
fi
Programming

Shell Script to Monitor Oracle Tablespace and Send Email Alert Only If Threshold Exceeds


export MMSG=/tmp/$$.mail
export ADDR="email address here"
export ORACLE_HOME=/u02/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=appdev1

file=/tmp/${$}_`date +%Y%m%d`

sqlplus -s system/password << .eof > $file
set pages 0
select df.tablespace_name tspace,
round(sum(fs.bytes)/(df.bytes) * 100) "%_free",
round(sum(fs.bytes)/(1024*1024)) free_ts_size,
df.bytes/(1024*1024) tot_ts_size
from dba_free_space fs, (select tablespace_name, sum(bytes) bytes from dba_data_files
group by tablespace_name ) df
where fs.tablespace_name = df.tablespace_name
group by df.tablespace_name, df.bytes
having round(sum(fs.bytes)/(df.bytes) * 100) < 20;
exit;
.eof
#list all datafile below
egrep "SOE|APEX|SYSAUX|SYSTEM|TEMP|UNDOTBS1|USERS|AUDIT_TBS|APP_ENCRYPTED" /tmp/${$}_`date +%Y%m%d` >/tmp/table${ORACLE_SID}.txt
check_stat=`cat /tmp/table${ORACLE_SID}.txt|wc -l`;
oracle_num=`expr $check_stat`
if [ $oracle_num -ne 0 ]
then
echo "tablespace less than 20% for $ORACLE_SID : $oracle_num" > $MMSG
mail -s "TABLESPACE WITH LESS THAN 20% FREE SPACE" $ADDR < $MMSG
mail -s "TABLESPACE WITH LESS THAN 20% FREE SPACE IN DATABASE $ORACLE_SID" $ADDR < /tmp/table$ORACLE_SID.txt
fi

rm -f $MMSG > /dev/null 2>&1
rm $file

Database

Simple Shell Script to Check Diskspace and Send Email on AIX

The below simple shell script will check all filesystems and create output file for only filesystems which are more than 80% full and send the log by email. 57 more words

Two modes to create a function -.-

First syntax:

function limpa_fs {

commands

return 0 # out function
}

Second Syntax (older)

limpa_fs () {

commands

return 0 # out function
}

Shell Script

>&2 - WHAT?? kkkkk

To quickly explain what the others missed:

echo “hey” >&2

redirect standard output (implicit 1>)

& what comes next is a file descriptor, not a file (only for right hand side of >)

26 more words
Shell Script