LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   problems with arguments when calling a script (https://www.linuxquestions.org/questions/linux-newbie-8/problems-with-arguments-when-calling-a-script-880467/)

brownie_cookie 05-13-2011 02:01 AM

problems with arguments when calling a script
 
Hi all

Suddenly, i have problems when i call a script when i use some arguments/variables
Here is my code
Code:

#!/bin/sh
PATH=""

find="/usr/bin/find"
xargs="/usr/bin/xargs"
tail="/usr/bin/tail"
awk="/usr/bin/awk"
cut="/usr/bin/cut"
wc="/usr/bin/wc"
grep="/bin/grep"
sqlplus="/usr/bin/sqlplus"

# Make sure the correct number of command line
# arguments have been supplied
if [ $# -lt 5 ]; then
    print_usage
    exit $STATE_UNKNOWN
fi

# Grab the command line arguments
exitstatus=$STATE_WARNING #default
while test -n "$1"; do
    case "$1" in
        --user)
            $user=$2
            shift
            ;;
            -u)
            $user=$2
            shift
            ;;
            --pass)
            $pass=$2
            shift
            ;;
            -pa)
            $pass=$2
            shift
            ;;
            --host)
            $host=$2
            shift
            ;;
            -h)
            $host=$2
            shift
            ;;
            --port)
            $port=$2
            shift
            ;;
            -po)
            $port=$2
            shift
            ;;
            --sid)
            $sid=$2
            shift
            ;;
            -s)
            $sid=$2
            shift
            ;;
    esac
    shift
done

# DB Query:
queryresult=`$sqlplus $user/$pass@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$host)(PORT=$port)))(CONNECT_DATA=(SID=$sid)))' << EOF
select *;
EOF`

This is my output:
Code:

# ./check_ORAdatabase_1.sh -u user -pa pass -h host -po port -s sid
./check_ORAdatabase_1.sh: line 73: =user: No such file or directory
./check_ORAdatabase_1.sh: line 81: =pa: No such file or directory
./check_ORAdatabase_1.sh: line 89: =host: No such file or directory
./check_ORAdatabase_1.sh: line 97: =port: No such file or directory
./check_ORAdatabase_1.sh: line 105: =sid: No such file or directory
OK - Nothing to report

why is this happening???

Thanks in advance

brownie_cookie 05-13-2011 02:08 AM

i've found the problem ;)
when i search for my arguments or variables
i do
$user=$2

in stead of
user=$2

Code:

# Grab the command line arguments
exitstatus=$STATE_WARNING #default
while test -n "$1"; do
    case "$1" in
        --user)
            $user=$2
            shift
            ;;
            -u)
            $user=$2
            shift
            ;;
            --pass)
            $pass=$2
            shift
            ;;
            -pa)
            $pass=$2
            shift
            ;;
            --host)
            $host=$2
            shift
            ;;
            -h)
            $host=$2
            shift
            ;;
            --port)
            $port=$2
            shift
            ;;
            -po)
            $port=$2
            shift
            ;;
            --sid)
            $sid=$2
            shift
            ;;
            -s)
            $sid=$2
            shift
            ;;
    esac
    shift
done


prayag_pjs 05-13-2011 02:20 AM

Hi,

When you run this command as it is

Code:

# ./check_ORAdatabase_1.sh -u user -pa pass -h host -po port -s sid
you will get error as you need to replace user with some user on system and pass with actual password.
values in the argument are misssing.

are you running this script for the first time and also this script is written by you or you downloaded it?

brownie_cookie 05-13-2011 02:28 AM

euh... yeah i'm aware of that, but i don't say what user and pass i'm using ;)
i don't use that command as i say it here :p


All times are GMT -5. The time now is 01:18 AM.