The shell script doesn't get arguments, but parse them


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting The shell script doesn't get arguments, but parse them
# 1  
Old 07-25-2017
The shell script doesn't get arguments, but parse them

Hello,
I have a simple shell script, which starts from crontab like this:
Code:
 00 03 * * 2-6 /export/applications/dte/sh/fwmarg.sh > /export/applications/dte/data/cron_log/fwmarg.cronlog.`date +\%m.\%d` 2>&1

The script doesn't get any argument. But inside it I see the line
Code:
 parse_args $@

I don't understand, why it need to parse arguments, if it doesn't get any arguments when it starts from crontab?

Thanks for contribution
# 2  
Old 07-25-2017
We would have to see the actual parse_args function to give you a good answer. All of the scripts we run against our huge datasets have a common include shell script, i.e., another small script is sourced. Keeps our common modules easy to maintain - just look in only one place.

The argument parsing it does loops over available arguments. If none are present there are a few default values used. So it does not "care" if there are arguments or not.

So. This is what someone else does. What your script does, I do not know for sure.
# 3  
Old 07-25-2017
The script start Perl script with several arguments. The Perl script or cerate report or update database
below is parse_args function
Code:
 parse_args () {
        echo "VARVAR $#"
        if [ $# -gt 0 ]
        then
                export THREAD_ARG="$@"
                while [ ! -z "$1" ]
                do
                        case $1 in
                                -P* | -p* )
                                        export PROCESS_DATE=$2
                                        export MM=`echo $2 | cut -c5-6`
                                        export DD=`echo $2 | cut -c7-8`
                                        export YY=`echo $2 | cut -c3-4`
                                        export PROCESS_DATE_US_MMDDYY="$MM/$DD/$YY"
                                        shift
                                        ;;
                                -OUT* | -OUt* | -Out* | -out* | -oUT* | -ouT* |-oUt* )
                                        if [ -d $2 ]
                                        then
                                                export OUTPUT_DIR=$2
                                        fi
                                        shift
                                        ;;
                                -IN* | -In* | -in* | -iN* )
                                        if [ -d $2 ]
                                        then
                                                export INPUT_DIR=$2
                                        fi
                                        shift
                                        ;;
                                -LOG* | -LOg* | -Log* | -log* | -lOG* | -loG* |-lOg* )
                                       if [ -d $2 ]
                                        then
                                                export LOG_HOME=$2
                                        fi
                                        shift
                                        ;;
                                -COO* | -COo* | -Coo* | -coo* | -cOO* | -coO* |-cOo* )
                                        if [ -d $2 ]
                                        then
                                                export COOL_DIR=$2
                                        fi
                                        shift
                                        ;;
                                -CBD* | -CBd* | -Cbd* | -cbd* | -cBD* | -cbD* |-cBd* )
                                        COOLBDAY=$2
                                        shift
                                        ;;
                                -TES* | -TEs* | -Tes* | -tes* | -tES* | -teS* |-tEs* )
                                        TEST="Y"
                                       ;;
                                -RELOAD* | -RESEND* | -reload* | -resend* | -Reload* | -Resend* )
                                        RELOAD="Y"
                                        ;;
                                SERVERMODE* | servermode* | ServerMode* )
                                        tmpmode=`echo ${1} | awk -F'=' '{print ($2)}' | tr a-z A-Z`
                                        export SERVERMODE="${tmpmode}"
                                        ;;
                                DBENV* | dbenv* | DBenv* | DBEnv* )
                                        tmpmode=`echo ${1} | awk -F'=' '{print ($2)}' | tr a-z A-Z`
                                        export DBENV="${tmpmode}"
                                        if [ -f ${DTE_WORKING_DIR}/sh/oracle.env ]; then
                                                . ${DTE_WORKING_DIR}/sh/oracle.env
                                        fi
                                        ;;
                                -DB* | -db* | -Db* | -dB*)
                                        ORACLE_USER=$2
                                        shift
                                        ;;
                                -NOPAGE* | -Nopag* | -NOPag* | -nopage* )
                                        export PAGEMODE="OFF"
                                        ;;
                                -Userdata* | -USERDATA* | -Userdata* | -userdata* | -UserData* )
                                        export _USER_DATA=$2
                                        shift
                                        ;;
                                * )
                                        ;;
                        esac
                        shift
                done
        fi
}

Thanks for contribution
# 4  
Old 07-25-2017
It skips over the arguments -- if no arguments it just goes on. Now whether that is correct for job to run well, I cannot know. Your problem.

Code:
        echo "VARVAR $#"
        if [ $# -gt 0 ]
        then
          .. remove lots of code here 

       fi

$# is a count of command line arguments passed to the script.
This User Gave Thanks to jim mcnamara For This Post:
# 5  
Old 07-25-2017
ok, thanks
# 6  
Old 07-25-2017
Yikes!

Whoever wrote this has never heard of the getopts command or shell shell-built-in. Even if this (miraculously) works, you should replace it by a function using getopts.

UNIX (and systems alike like Linux) provides a parser for commandline parsing already and there is no need to replace that - and definitely not with one that works less reliable.

I hope this helps.

bakunin
# 7  
Old 07-25-2017
this is a very old shell program, which I convert to Perl. And as I said, there is no arguments shell script receives
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

2. Shell Programming and Scripting

sub arguments to shell script

Hi, I have a shell script, when run it i get a prompt to enter arguments say 1 for doing my next task otherwise q for quit. What I am trying to do is run the shell script with the argument passed in however it does not seem to work. This is what I did ./test.sh 1 Instead it printed the line... (6 Replies)
Discussion started by: aqua9
6 Replies

3. Shell Programming and Scripting

Using arguments in Shell script

Hello, I have to make a shell script doing that : the program tests if there is an argument, if there is it checks whether this is a directory or not, If it is it opens it. for any .c file in the directory it prints 2 lines in the screen : the dependence line of the .o and compiler commend... (1 Reply)
Discussion started by: dekl
1 Replies

4. Shell Programming and Scripting

shell script, echo doesn't work

#!/bin/sh something(){ echo "Inside something" echo $1 $2 } val=$(something "Hello " "world") Output expected: Inside somethingHello world But it's not echoing. (4 Replies)
Discussion started by: cola
4 Replies

5. Shell Programming and Scripting

no of arguments to function in shell script

Hi, I have a function in shell script fun1{ echo "No.of arguments are..."} this function will be called in same script by passing arguments fun 1 2 3 I want to check the no. of arguments passed to fun1 function in the same functionbefore validation. can any one suggest me. (2 Replies)
Discussion started by: KiranKumarKarre
2 Replies

6. Shell Programming and Scripting

Need help to pass arguments to shell script

Hi, I have a shell script called ftp.sh which is running continously in background. I tried passing arguments to this script but it did not worked out. Below is ftp.sh script. Please help me case $param in start) sleep_func "300" echo "!ksh $scr_ddir/ftp.sh... (1 Reply)
Discussion started by: bhargav20
1 Replies

7. Shell Programming and Scripting

passing runtime arguments to a shell script...

hi I am new to shell programming.....my question is while running one of my shell program it stops in between to accept input from the user and proceeds furthur after giving input....I want to know whether I can set this input through some files so that the shell acript reads the input from the... (10 Replies)
Discussion started by: santy
10 Replies

8. Shell Programming and Scripting

Is there a limit to the no. of arguments to a shell script ?

What is the maximum no. of arguments that could be passed to a shell script ? Is there any restriction ? I've a requirement where I need to pass a list of names to a unix script and I guess the number of such names is not a fixed one. It can run into hundreds. Is this feasible ? (4 Replies)
Discussion started by: hidnana
4 Replies

9. Shell Programming and Scripting

Shell script doesn't get executed using crontab

I have the following crontab entry to run a shell script for every 30 minutes of every day: 30 * * * * $HOME/main.sh > $HOME/main.log 2>$HOME/error.log after I created the crontab file I have also done: $crontab my_crontab I also check to make sure it exists, by using the following... (11 Replies)
Discussion started by: radhika
11 Replies

10. Shell Programming and Scripting

Shell script with arguments

Hi All, I need some help/ideas in coming up with a shell script. Basically, the script should install 1 or 2 or 3 packages based on the input arguments. For example, if I type in pkgscript.sh a1 a2 a3, it should install all the 3 scripts and pkgscript.sh a1 should install only a1. If a... (3 Replies)
Discussion started by: sankar6254
3 Replies
Login or Register to Ask a Question