Tag Archives: PATH

How to exit a script with error ?

By Salil Gupta

Hi,

I have a script ABC which calls another script XYZ. Function of XYZ is to ftp a file from one server to another.

code for ABC:

Code:

#!/bin/ksh
PATH=/usr/bin

home/user/xyz "$@"

exit $?
~


code for xyz:

Code:

#!/bin/ksh
HOSTNAME=$1
SRCNAME=$2
DSTNAME=$3

### This file holds the outget of the FTP commands for success checking
FTPCHK=/tmp/ftpchk.$$
#touch $FTPCHK
echo "" > $FTPCHK

SRCFILE=$SRCNAME

DSTFILE=$DSTNAME

echo Source Host: $HOSTNAME
echo Source File Name: $SRCFILE
echo Destination File: $DSTFILE

echo `date` Beginning FTP download...
ftp -v ${HOSTNAME} <>$FTPCHK 2>&1
ascii
nlist ${SRCFILE}
get ${SRCFILE} ${DSTFILE}
quit
EOF

### Check for FTP errors
CHK1=`grep -c "226 Transfer complete." $FTPCHK`
CHK2=`grep -c "226 ASCII Transfer complete." $FTPCHK`
CHK3=`grep -ic "226 transfer complete" $FTPCHK`
CHK4=`grep -ic "226 File send OK." $FTPCHK`

### In NT, There should transmissions complete:
### One for the data transfer,
### One for the nlist

if [ $CHK1 -eq 2 ] || [ $CHK2 -eq 2 ] || [ $CHK1 -eq 1 -a $CHK2 -eq 1 ] || [ $CHK3 -eq 2 ] || [ $CHK4 -eq 1 ]; then
RC=0
echo "OK: FTP Transmission Worked"
echo '--------------------------------------------------------------'
cat $FTPCHK
echo '--------------------------------------------------------------'

else
RC=1
echo "ERROR: FTP Transmission Failed"
banner "ERROR"
echo '--------------------------------------------------------------'
cat $FTPCHK
echo '--------------------------------------------------------------'
fi

date
ls -al ${DSTFILE}

rm $FTPCHK

echo '---------------------------------------------------------------------'

exit $RC


In script XYZ, I am trying to ftp a file. So during ftp , whenever it shows that space is less than size of file, it should ftp the partial according to the available space and prompt a message about it and also prompt a message to outer script that inner script could not complete successfully. Hence resulting in the failure of outer script, due to partial ftp of file.

Also please post the comments about the each step of script to explain what is happening in that step. Thanks a lot in advance.

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Fetching variable from config file

By rafa_fed2

I am using . .profile in my script below
I want to fech it it from my configuration file .id_pass_file.txt(it has all user_name and passwords)
how can i do this

Code:

PROFILE_PATH=. .profile
AND IN MY SCRIPT
$PROFILE_PATH
IS THIS CORRECT


Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

## /path/to/profile .This is required for crontab to work as bip.sh uses environmental variables.
. .profile

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select distinct account_no from adj WHERE ADJ_TRANS_CODE=-2401 and request_status=1 and bill_ref_no=0
order by account_no;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
sh $SCRIPT_DIR/bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 180
done
fi

###Removing temporary log files generated

if [ -f "$CUR_DIR/bip_log_1.txt" ]
then
rm "$CUR_DIR/bip_log_1.txt"
echo "file bip__log_1.txt removed"
fi

if [ -f "$CUR_DIR/sql_output.txt" ]
then
rm "$CUR_DIR/sql_output.txt"
echo "sql_output.txt removed"
fi

rm $CUR_DIR/error.log


…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Issue with cron and environmental variable

By rafa_fed2

My shell script it.sh.I am calling bip.sh from it.sh

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f $CUR_DIR/bip_log_1.txt ]
then
`rm $CUR_DIR/bip_log_1.txt`
echo "file bip__log_1.txt removed"
fi

if [ -f $CUR_DIR/sql_output.txt ]
then
`rm $CUR_DIR/sql_output.txt`
echo "sql_output.txt removed"
fi


Code:

59 04 * * * /arbor/integ_fx/rahul_raj/itsr_5652/it.sh /arbor/integ_fx/rahul_raj/itsr_5652


my error.log file

Code:

LOGGING STARTS 07-22-2013 05:22:00

SQLPLUS CONNECTION
SQLPLUS Connection Successful
bip 1016 is running
cat: cannot open /.arborpw
file bip__log_1.txt removed
sql_output.txt removed.
ERROR: $ARBORDBU environment variable is not set

This script requires that the $ARBORDBU environment variable be set.


MY BIP.SH

Code:

#!/bin/sh
ARBOR_DB_PASSWD=`cat $ARBORDIR/.arborpw`; export ARBOR_DB_PASSWD
DB_PASS=$ARBOR_DB_PASSWD; export DB_PASS;
ORACLE_SID=$ARBOR_CATALOG_DATABASE; export ORACLE_SID;
ARBORCTRLRPT03=$ARBORDATA/reports/ctrl; export ARBORCTRLRPT03;

Usage(){
echo "nn Usage is: `basename $0` n"
echo " where is a number between 01 and 99"
echo " is a number. Use 0=production, 3=proforma, 6=backout"
echo " is an arbor accout numbernn"
exit 0
}

# Check number of arguments
if [ "$#" -ne 3 ] ; then
Usage
fi

# Check to see if ARBORDBU is set
if [ -z "${ARBORDBU}" ] ; then
echo "ERROR: $ARBORDBU environment variable is not setn"
echo "This script requires that the $ARBORDBU environment variable be set.nn"<br ...read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Scheduling issues

By rafa_fed2

I AM ON SOLARIS

I have a script it.sh which is running fine when i execute it from shell command.
But when i schedule it in crontab it is throwing error.

Why and how can i resolve it ?i am clueless

IT.SH

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select distinct account_no from adj WHERE ADJ_TRANS_CODE=-2401 and request_status=1 and bill_ref_no=0
order by account_no;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
sh $SCRIPT_DIR/bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 180
done
fi


My error is in error.log

Code:


LOGGING STARTS

SQLPLUS CONNECTION
SQLPLUS Connection Successful
bip 114034 is running
cat: cannot open /.arborpw


my error is bip_log_1.txt

Code:

ERROR: $ARBORDBU environment variable is not set

This script requires that the $ARBORDBU environment variable be set.


My bip.sh is

Code:

#!/bin/sh
ARBOR_DB_PASSWD=`cat $ARBORDIR/.arborpw`; export ARBOR_DB_PASSWD
DB_PASS=$ARBOR_DB_PASSWD; export DB_PASS;
ORACLE_SID=$ARBOR_CATALOG_DATABASE; export ORACLE_SID;
ARBORCTRLRPT03=$ARBORDATA/reports/ctrl; export ARBORCTRLRPT03;

Usage(){
echo "nn Usage is: `basename $0` n"
echo " where is a number between 01 and 99"
echo " is a number. Use 0=production, 3=proforma, 6=backout"
echo " is an arbor accout numbernn"
exit 0
}

# Check number of arguments
if [ "$#" -ne 3 ] ; then
Usage
fi

# Check to see if ARBORDBU is set
if [ -z "${ARBORDBU}" ] ; then
echo "ERROR: $ARBORDBU environment variable is not setn"
echo "This script requires that the $ARBORDBU environment variable be set.nn"
...read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Files not being removed

By rafa_fed2

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f "$CUR_DIR/bip_log_1.txt" ]
then
rm "$CUR_DIR/bip_log_1.txt"
echo "file bip__log_1.txt removed"
fi

if [ -f "$CUR_DIR/sql_output.txt" ]
then
rm "$CUR_DIR/sql_output.txt"
echo "sql_output.txt removed"
fi


My error

error.log

Code:

SQLPLUS CONNECTION
SQLPLUS Connection Successful
bip 1016 is running
file bip__log_1.txt removed
./it.sh: syntax error at line 76: `end of file' unexpected


how do i remove sql_output.txt

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Another issue with crontab

By rafa_fed2

My shell script it.sh

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f $CUR_DIR/bip_log_1.txt ]
then
`rm $CUR_DIR/bip_log_1.txt`
echo "file bip__log_1.txt removed"
fi

if [ -f $CUR_DIR/sql_output.txt ]
then
`rm $CUR_DIR/sql_output.txt`
echo "sql_output.txt removed"
fi


when i execute the script manually ,it is working fine but when i schedule this job in crontab i get an error in error.log

Why?
Please help me.

crontab entry

Code:

59 04 * * * /arbor/integ_fx/rahul_raj/itsr_5652/it.sh /arbor/integ_fx/rahul_raj/itsr_5652


Code:


LOGGING STARTS 07-22-2013 05:22:00

SQLPLUS CONNECTION
SQLPLUS Connection Successful
bip 1016 is running
cat: cannot open /.arborpw
file bip__log_1.txt removed
sql_output.txt removed


…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Log file being not generated in crontab

By rafa_fed2

My shell script it.sh

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f $CUR_DIR/bip_log_1.txt ]
then
`rm $CUR_DIR/bip_log_1.txt`
echo "file bip__log_1.txt removed"
fi

if [ -f $CUR_DIR/sql_output.txt ]
then
`rm $CUR_DIR/sql_output.txt`
echo "sql_output.txt removed"
fi


when i execute the script manually ,it is working fine but when i schedule this job in crontab error.log file is not generated

Why?
Please help me.

crontab entry

Code:

59 04 * * * /arbor/integ_fx/rahul_raj/itsr_5652/it.sh /arbor/integ_fx/rahul_raj/itsr_5652


…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Removing log files

By rafa_fed2

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat .id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat .id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat .id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat .id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f $CUR_DIR/bip_log_1.txt ]
then
`rm $CUR_DIR/bip_log_1.txt`
echo "file bip__log_1.txt removed"
fi

if [ -f $CUR_DIR/sql_output.txt ]
then
`rm $CUR_DIR/sql_output.txt`
echo "sql_output.txt removed"
fi

rm $CUR_DIR/error.log


I want to remove the 3 files that are being genarated.
How can i do this
I am getting an error

Code:

file bip__log_1.txt removed
./it.sh: syntax error at line 76: `end of file' unexpected


My code should work for all paths that i give

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Script is not longer working in the crontab

By alexcol

This is the crontab it is supossed to be running everyday but it didnt

5 0 * * * /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1

Inside the above script connects to a database and extract data to a flat file, manually i run the script at about 2 a.m. and Works OK, besides manually connect to the database OK
sqlplus copge/passw
SQL*Plus: Release 10.2.0.4.0 – Production on Jue Jul 18 02:32:56 2013
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL>
This is the code:

[!/bin/ksh
#. .profile

#ORACLE_HOME=/softw/app/oracle/product/9.2.0;export ORACLE_HOME
#PATH=/usr/bin:/usr/sbin:.:/softw/app/oracle/product/9.2.0/bin; export PATH
#ORACLE_SID=COOPGE; export ORACLE_SID

fecha=`date +’%Y%m%d%H%M%S’`
sqlplus -s copge/passwd << fin
set feedback off
set linesize 1000
set pagesize 0
set head off
set trims on
set termout off
set serveroutput off
spool /export/app/CO/ppcs/datos/sdp/CO_Reportes/Imsi_$fecha.lis
alter session set nls_date_format = ‘yyyy/mm/dd hh24:mi:ss’;
select
num_telefono||’|’||
imsi||’|’||
asl||’|’||
cod_nir
from poge_paramred ;
spool off
exit;
fin][/CODE]

Thanks in advenced

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Process dies when launched in system startup script

By carpannav

Good morning!

I’m trying to add Maven to the system boot by the moment without success.
Testing the operation of the script I realize that the process isn’t persistent when the program is launched with the start option.

—- #Startup Script —-

Code:

#! /bin/sh
# chkconfig: 345 99 1
# description: xxx
# processname: Application
#
. /etc/rc.d/init.d/functions

BIN="/projects/user/app/appsysv.sh start $VERSION"
PIDFILE="/projects/user/app/pid.file"
#LOG
LOGFILE="/projects/user/log/app.log"

start()
{
su - user -c "/etc/init.d/app start_internal" &
echo -n "Starting App ... "
echo
}

start_internal()
{
# Remember PID
echo $$ > $PIDFILE
# Exec application
exec $BIN >> $LOGFILE 2>&1
if [ $(cat $PIDFILE) -gt 0 ]; then
ps -p $(cat $PIDFILE) > /dev/null
if [ $? -eq 0 ]; then
echo "App started successfully"
fi
fi
}

stop()
{
if [ -f ${PIDFILE} ]; then
kill $(cat $PIDFILE)
echo -n "App stopped"
echo
fi
}

case "$1" in
start)
start
;;
start_internal)
start_internal
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage $0 {start|stop|restart}"
exit 1
esac


And this is how the application is natively launched out of the system startup (the script which i’m pointing):

Code:

#!/bin/sh

#Set Maven
export M2_HOME=/opt/apache-maven-2.2.1
# Set Java environment
export JAVA_HOME=/opt/jdk1.6.0_22
PATH=$JAVA_HOME/bin:$PATH
# Oracle environment
export ORACLE_BASE=/home/oracle/app/oracle
export ORACLE_SID=db
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/client_1
export PATH=$ORACLE_HOME/bin:$PATH
source /projects/tcatnbia/app/nbis-execution/app.cfg
PIDFILE="/projects/user/app/pid.file"
start()
{dformat=`date '+%y%m%d_%H%M%S'`
export MAVEN_OPTS="-server -Xms512m -Xmx2048m -XX:MaxPermSize=256m -Xloggc:/projects/user/log/gc-${dformat}.log -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=app_jmxremote.password -Dcom.sun.management.jmxremote.access.file=app_jmxremote.access -Dcom.sun.management.jmxremote.ssl=true -Djavax.net.ssl.keyStore=nbis_jmx_key -Djavax.net.ssl.keyStorePassword=123456 -Duser.timezone=$TIMEZONE"
nohup mvn -e -o -Dapp.version=$1 -Dnbis.env=$ENV -Dlocal.server.file.locn=$LOCAL_SERVER exec:java > /projects/user/log/app-out.log 2>&1 &
}

stop()
{
if [ -f ${PIDFILE} ]; then
kill `cat $PIDFILE`
echo -n "App stopped"
echo
fi
}

case "$1" in
start)
start $2
;;
stop)
stop
;;
restart)
stop
start $2
;;
*)
echo Usage:
echo $0 'start [App_version]'
echo 'or restart [app_version]'
echo 'or stop'
exit 1
esac
exit 0


Can anybody help to find out what’s happening? When I check for the process, I find that …read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Waht is wrong with: echo $PATH | sed s/:/\n/g

By marek

Hello all!

I am on Mac (10.8.4) and my shell tcsh (man says version: Astron 6.17.00). Just to precise my tcsh:

Code:

echo $LC_CTYPE
UTF-8


I want to replace all ‘:’ with a new line, to get all paths on one line. I don’t find a way to make my shell accept the “n”

My start was:

Code:

echo $PATH | sed s/:/n/g


And I tried every possible variation of n: \n – “n” – “\n” or with r. The result is always the : colon disappears but the replace is sometimes nothing or a literal “n” …

Sorry for this dumb question; but the forum is for Dummies, isn’t it?

marek

ps: in bash I get the same results

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Help with error "por: 0403-012 A test command parameter is not valid."

By blacksteel1988

Hi, im asking for help with the next script:

Code:

echo ^[[32m Mails Pending ^[[37m
VAR1=`query1.sh`

if [ $VAR1 -ge 200 ];
then
if [ $VAR1 -ge 300 ]
then
printf "33[01;31m%s33[00mn" "$VAR1"
else
printf "33[01;33m%s33[00mn" "$VAR1"
fi
else
printf "33[01;32m%s33[00mn" "$VAR1"
fi

echo " "

sleep 30
clear
done;


query1.sh:

Code:

export TERM=vt100
export ORACLE_TERM=at386
export ORACLE_HOME=/home_oracle8i/app/oracle/product/8.1.7
export ORACLE_BASE=/home_oracle8i/app/oracle
export DBVISIT_HOME=/usr/local/dbvisit

PATH=/home_oracle8i/app/oracle/product/8.1.7/bin:/usr/ccs/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME
/bin:/usr/bin/X11:/sbin:$DBVISIT_HOME:.
export PATH
export ORACLE_SID=ORAB817
export DISPLAY=192.9.200.121:0.0
export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
export ORA_ENCRYPT_LOGIN=TRUE
set umask=022
sqlplus -s " / as sysdba " @query1.sql


query1.sql:

Code:

set serveroutput on
set feedback off
set head off

SELECT 'MAILS PENDING : ' || COUNT ( * ) "Correo Por Enviar" FRO
M SCHEMA.CSIC_MAILS_fOR_SEND@VIRT.DB.TGU.COM WHERE estado = 0;

exit;


When i execute the script it returns what i want, but before that it always gives me the error “j.sh[224]: por: 0403-012 A test command parameter is not valid.”

From: http://www.unix.com/shell-programming-scripting/221405-help-error-por-0403-012-test-command-parameter-not-valid.html

Install Numpy in AIX 6.1

By Brunolac

Hi

I have been trying install numpy in AIX 6.1 unsuccessfully, the versions are numpy (1.7 or 1.6), ( IBM XL C/C++ for AIX, V11.1 or gcc 4.7.2 )

I put in site.cfg from numpy the following
——-
library_dirs = /opt/freeware/lib:/usr/lib:/usr/lib64:/lib:/usr/local/lib64
include_dirs = /usr/include:/opt/freeware/include

[blas_opt]
libraries = libblas.a
[lapack_opt]
libraries = liblapack.a
——
The compilation was without error, after I changed the PATH and add PYTHONPATH.

When i import numpy with python_64 i saw the error:

File “”, line 1, in File “/home/bruno/bin/lib/python2.6/site-packages/numpy/__init__.py”, line 137, in import add_newdocs File “/home/bruno/bin/lib/python2.6/site-packages/numpy/add_newdocs.py”, line 9, in from numpy.lib import add_newdoc File “/home/bruno/bin/lib/python2.6/site-packages/numpy/lib/__init__.py”, line 4, in from type_check import * File “/home/bruno/bin/lib/python2.6/site-packages/numpy/lib/type_check.py”, line 8, in import numpy.core.numeric as _nx File “/home/bruno/bin/lib/python2.6/site-packages/numpy/core/__init__.py”, line 5, in import multiarray ImportError: 0509-022 Cannot load module /home/bruno/bin/lib/python2.6/site-packages/numpy/core/multiarray.so. 0509-103 The module has an invalid magic number.

And when i import with python i see

File “”, line 1, in File “/home/bruno/bin/lib/python2.6/site-packages/numpy/__init__.py”, line 137, in import add_newdocs File “/home/bruno/bin/lib/python2.6/site-packages/numpy/add_newdocs.py”, line 9, in from numpy.lib import add_newdoc File “/home/bruno/bin/lib/python2.6/site-packages/numpy/lib/__init__.py”, line 4, in from type_check import * File “/home/bruno/bin/lib/python2.6/site-packages/numpy/lib/type_check.py”, line 8, in import numpy.core.numeric as _nx File “/home/bruno/bin/lib/python2.6/site-packages/numpy/core/__init__.py”, line 8, in import numerictypes as nt File “/home/bruno/bin/lib/python2.6/site-packages/numpy/core/numerictypes.py”, line 872, in _typestr[key] = empty((1,),key).dtype.str[1:] ValueError: array is too big.

Can anyone help me?

Thanks

From: http://www.unix.com/aix/221395-install-numpy-aix-6-1-a.html

./configue

By Adriano Schmidt

hello,

I’m trying install apache http server version 2.2.22.

I downloaded the file httpd-2.2.22.tar.bz2.

I unzipped this file..

When I type “./configure”, the following error occurs:

[root@SERVER_JBOSS_235 httpd-2.2.22]# ./configure –prefix=/opt/work/apache2.2.22
checking for chosen layout… Apache
checking for working mkdir -p… yes
checking build system type… x86_64-unknown-linux-gnu
checking host system type… x86_64-unknown-linux-gnu
checking target system type… x86_64-unknown-linux-gnu

Configuring Apache Portable Runtime library …

checking for APR… reconfig
configuring package in srclib/apr now
checking build system type… x86_64-unknown-linux-gnu
checking host system type… x86_64-unknown-linux-gnu
checking target system type… x86_64-unknown-linux-gnu
Configuring APR library
Platform: x86_64-unknown-linux-gnu
checking for working mkdir -p… yes
APR Version: 1.4.5
checking for chosen layout… apr
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: in `/opt/work/httpd-2.2.22/srclib/apr’:
configure: error: no acceptable C compiler found in $PATH
See `config.log’ for more details.
configure failed for srclib/apr
[root@SERVER_JBOSS_235 httpd-2.2.22]#

trying install the gcc (gcc-4.8.0-1.fc19.x86_64.rpm) the following error occurs:

[root@SERVER_JBOSS_235 installers]# rpm -ivh gcc-4.8.0-1.fc19.x86_64.rpm
warning: gcc-4.8.0-1.fc19.x86_64.rpm: Header V3 RSA/SHA256 signature: NOKEY, key ID fb4b18e6
error: Failed dependencies:
binutils >= 2.20.51.0.2-12 is needed by gcc-4.8.0-1.fc19.x86_64
cpp = 4.8.0-1.fc19 is needed by gcc-4.8.0-1.fc19.x86_64
glibc-devel >= 2.2.90-12 is needed by gcc-4.8.0-1.fc19.x86_64
libc.so.6(GLIBC_2.11)(64bit) is needed by gcc-4.8.0-1.fc19.x86_64
libc.so.6(GLIBC_2.14)(64bit) is needed by gcc-4.8.0-1.fc19.x86_64
libc.so.6(GLIBC_2.7)(64bit) is needed by gcc-4.8.0-1.fc19.x86_64
libgcc >= 4.8.0-1.fc19 is needed by gcc-4.8.0-1.fc19.x86_64
libgmp.so.10()(64bit) is needed by gcc-4.8.0-1.fc19.x86_64
libgomp = 4.8.0-1.fc19 is needed by gcc-4.8.0-1.fc19.x86_64
libmpc.so.3()(64bit) is needed by gcc-4.8.0-1.fc19.x86_64
libmpfr.so.4()(64bit) is needed by gcc-4.8.0-1.fc19.x86_64
rpmlib(FileDigests) <= 4.6.0-1 is needed by gcc-4.8.0-1.fc19.x86_64
rpmlib(PayloadIsXz) <= 5.2-1 is needed by gcc-4.8.0-1.fc19.x86_64

What can I do?

I’m using Red Hat Enterprise Linux 5.8.

Thanks!!
Adriano Schmidt

From: http://www.unix.com/unix-dummies-questions-answers/221113-configue.html

Prize of being an Admin – Part 2

By ahamed101

I was reading this thread of admin_xor Prize of being an Admin and thought will share this experience of mine which is kind of opposite to what he did – I didn’t tell anybody what happened 😀

We were porting one of the telecom subsystem from Solaris to Linux. As part of that we developed many wrapper scripts. So, there is this rsh wrapper script which is deployed in the system which internally uses ssh if security is enabled or uses native rsh instead (this native rsh is placed in a different path, so that it will not show up in the $PATH and the wrapper rsh script is placed in /usr/bin). For some testing purpose, I modified the ssh command inside the rsh wrapper script to “rsh” command and forgot to change it back. So, you know what happened next. If I do a rsh, it goes into a continuous loop calling the rsh wrapper script over and over again, this clogged the cpu in no time. I did this change in the Testing teams setup. And the worst part was I did it in 2 of their setup.

Next day I came to office and there is a big fuss all over the place. I didn’t bother cause it was’t assigned to me and I totally forgot that what I did was causing this. After couple of days, the issue was assigned to me and then “oops” I realized it. Now what? Of course I didn’t tell them :D. Hearing about what happened to admin_xor for what he did, imagine what would’ve happened to me.

Later I told them that it was a “human” :p error and that there is no issue with the system. But then they asked how could it happen to 2 systems. I was like “it happened man, forget it” 😀 – no I didn’t say that, I told them we’ll monitor it. I assured them that it is human error and we will monitor the system and if it re-occurs we will investigate again and now its not worth spending time on this – obviously I know it – cause I am the culprit.

–ahamed

From: http://www.unix.com/war-stories/221075-prize-being-admin-part-2-a.html

Export Error in Shell script

By jothi basu

All,

While executing the bellow commnad after the sed, awk command to export the value to, i am getting the fallowing error.

Code:

line="_AABBB.EEEEEEE.LOG4JDISPLAY.PATH_=/apps/opt/abcde/pdstdsd/esapp/apadsfasdf/logadsfasdf.xml"
keystring=`echo $line | awk -F"=" '{ print $1 }'`
valuestring=`echo $line | awk -F"=" '{ print $2 }' | sed 's#([]*$|[])#\\1#g'`
eval export "${keystring}=${valuestring}"


Message i am getting after the execution of the above command:

Code:


-bash: export: `_AABBB.EEEEEEE.LOG4JDISPLAY.PATH=apps/opt/abcde/pdstdsd/esapp/apadsfasdf/logadsfasdf.xml': not a valid identifier


:confused:

Anyone could you help me on this.

Thanks,
Jothi

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

System function in awk

By EAGL€

Hello Friends,

I have written a script like below,

I aimed to move some CDR files (call data record) whose the last field is “1” (NF=1 ) from a spesific directory to a new directory
Field Seperator is pipe.
If the directory does not exitst i should create it.
I will give the script two arguments so i check if they are given or not

Here I have written this; Im suspicious if the below system function in awk will work or not, appreciate your opinions.

Code:

if [ "$#" -ne 2 ]
then
echo
echo "--- There are two arguments which is expected after script! ---"
echo "--- USAGE: "$0" | FULL PATH of NEPS DIRECTORY | NEW FULL PATH for INITIALLY CHARGED CDRs ---"
echo
elif [ "$#" -eq 2 ]
then
if [ ! -d $2 ];
then
mkdir $2
fi

for file in `find $1 -type f -name "*cdr*.txt" 2>/dev/null`
do
nawk -F| -v PATH=$2 'NR==1{ if $NF==1 system( "mv FILENAME PATH/FILENAME ") }'
done;
fi


Thanks in advance
BR

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Creating a .profile, displaying system variables, and creating an alias

By Jagst3r21

Use and complete the template provided. The entire template must be completed. If you don’t, your post may be deleted!

1. The problem statement, all variables and given/known data:

Here is what I am supposed to do, word for word from my assignment page:

1. Create/modify and print a .profile that does the following:
a) Displays the date and time
b) Lists all the current users
c) Adds the users home directory and the current directory to the PATH
d) Changes the prompt to display the current directory

2. Display the current system variables

3. Create an alias for a command that will look for your name in the password file

2. Relevant commands, code, scripts, algorithms:

.profile, alias

3. The attempts at a solution (include all code and scripts):

Here is what I have for each step above:

1. Create/modify and print a .profile that does the following:
a) date
b) users
c) export PS1=’${PWD} ‘
d) PATH=$PATH:$HOME:$PWD

2. set

3. alias findmyname=”grep /etc/passwd”

A couple questions:

1. My teacher wants me to print a listing of the profile. Would I just do “touch .profile” and then append (using “>>”) the commands to the file, then print it?

2. I am not sure if my alias is correct. Not sure how to find the exact location of the passwd file

Thanks in advance.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Brookdale Community College – Lincroft, New Jersey – United States – Dr. Rick Bournique- COMP 145

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Error in UNIX script

By sourabh.chhabra

When i run a script in linux. It shows the following error.

‘icsftpagent.sh: line 114: syntax error near unexpected token `’icsftpagent.sh: line 114: `Nicsftp() The script is as follows.

#!/bin/bash
#### Copyright Notice:
####
#### Copyright (c) 2007 Network Intelligence Corporation
####
#### Warning: This computer program is protected by copyright law and
#### international treaties. Unauthorized reproduction or distribution
#### of this program, or any portion of it, may result in severe civil
#### and criminal penalties, and will be prosecuted to the maximum
#### extent possible under the law.
####
#### RSA, The Security Division of EMC – Automated FTP/SCP/SFTP Script v2.7.11
####
###################
####
#### Begin User configuration
####
##########
########
######
####
#SILENT MODE
#produce no output to the console;
#set this to true when running from cron
#to reduce emails sent to root.
SILENT=true
# Have the Solaris POSIX compliant binaries first in the path.
# The /usr/bin directory in Solaris doesn’t have POSIX compliant
# binaries. This is particularly a problem for the awk command we are
# using. (ECE-138)
#PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/css/bin:$PATH
## Enter the hostname/IP address of the enVision machine to which you want to
## send the data files
ENVISION=192.168.1.20
## Enter the directories where the data files, which you need to send, exist. Separate
## multiple directories with a colon (:). This script must have read permissions
## to the directories.
## Example for multiple folders DATA_DIRECTORY=/var/log/:/var/log/audit
DATA_DIRECTORY=/var/log/
## The directory on the enVision box where the files should be written to. This directory
## is relative to the enVision/ftp_files directory. If the directory name contains a
## space it will need to be double escaped. For example, if the directory name is
## “name with spaces”, the variable needs to be set to “name with spaces”.
ENVISION_DIRECTORY=Squid_192.168.1.63
## The script keeps its persistent information in a directory. The
## script must have read and write permissions to this directory.
NIC_DIRECTORY=/usr/local/nic
## TRANSFER_METHOD=SFTP/SCP/FTP
## Select the method used to transfer the files to enVision. SFTP is recommended.
## valid options are FTP, SFTP and SCP
TRANSFER_METHOD=SFTP
## Enter a username (ftp default: anonymous; SFTP/SCP default: nic_sshd)
USERNAME=nic_sshd
## Enter a password (anonymous connections accept any password)
PASSWORD=RSAlab@12345
## Enter the identity/private key file for the user specified above user
## default is $HOME/.ssh/id_rsa
IDENTITY=~/.ssh/id_rsa
## Enter the file matching specification. “*” will send any files in the directory. Separate
## multiple fielnames with a colon (:).
## Example for multiple files::
## …read more
Source: FULL ARTICLE at The UNIX and Linux Forums

UNIX Error in Script

By sourabh.chhabra

When i run a script in linux. It shows the following error.
‘icsftpagent.sh: line 114: syntax error near unexpected token `
‘icsftpagent.sh: line 114: `Nicsftp()

My Script is as follows:
#!/bin/bash
#### Copyright Notice:
####
#### Copyright (c) 2007 Network Intelligence Corporation
####
#### Warning: This computer program is protected by copyright law and
#### international treaties. Unauthorized reproduction or distribution
#### of this program, or any portion of it, may result in severe civil
#### and criminal penalties, and will be prosecuted to the maximum
#### extent possible under the law.
####
#### RSA, The Security Division of EMC – Automated FTP/SCP/SFTP Script v2.7.11
####
###################
####
#### Begin User configuration
####
##########
########
######
####
#SILENT MODE
#produce no output to the console;
#set this to true when running from cron
#to reduce emails sent to root.
SILENT=true
# Have the Solaris POSIX compliant binaries first in the path.
# The /usr/bin directory in Solaris doesn’t have POSIX compliant
# binaries. This is particularly a problem for the awk command we are
# using. (ECE-138)
#PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/css/bin:$PATH
## Enter the hostname/IP address of the enVision machine to which you want to
## send the data files
ENVISION=192.168.1.20
## Enter the directories where the data files, which you need to send, exist. Separate
## multiple directories with a colon (:). This script must have read permissions
## to the directories.
## Example for multiple folders DATA_DIRECTORY=/var/log/:/var/log/audit
DATA_DIRECTORY=/var/log/
## The directory on the enVision box where the files should be written to. This directory
## is relative to the enVision/ftp_files directory. If the directory name contains a
## space it will need to be double escaped. For example, if the directory name is
## “name with spaces”, the variable needs to be set to “name with spaces”.
ENVISION_DIRECTORY=Squid_192.168.1.63
## The script keeps its persistent information in a directory. The
## script must have read and write permissions to this directory.
NIC_DIRECTORY=/usr/local/nic
## TRANSFER_METHOD=SFTP/SCP/FTP
## Select the method used to transfer the files to enVision. SFTP is recommended.
## valid options are FTP, SFTP and SCP
TRANSFER_METHOD=SFTP
## Enter a username (ftp default: anonymous; SFTP/SCP default: nic_sshd)
USERNAME=nic_sshd
## Enter a password (anonymous connections accept any password)
PASSWORD=RSAlab@12345
## Enter the identity/private key file for the user specified above user
## default is $HOME/.ssh/id_rsa
IDENTITY=~/.ssh/id_rsa
## Enter the file matching specification. “*” will send any files in the directory. Separate
## multiple fielnames with a colon (:).
## Example for multiple files::
## FILESPEC=*.log:xyz.log …read more
Source: FULL ARTICLE at The UNIX and Linux Forums