Sponsored Content
Top Forums Shell Programming and Scripting Command line not getting assigned in script. Post 302341090 by kshji on Wednesday 5th of August 2009 04:28:43 AM
Old 08-05-2009
Code:
#!/bin/ksh

usage()
{
    # print error to the stderr
    print "Usage: ${0} { inc_non_primary }"  >&2
    print "Usage: ${table_name} ${ c}"        >&2
}

####
# maybe your functions include also options_count handling ? - change order
# or next line include error => script will exit, usually never set output redirect when use 
# . 
#. /opt/projects/gsd/scripts/functions gsd > /dev/null 2>&1
# maybe you try to load file gsd ?
# better method to load something to this process 
f=/opt/projects/gsd/scripts/functions/gsd
[ -f "$f" ] && . $f  || print "no $f" >&2

option_count=$#

[ "$option_count" -gt 2 ] && usage && exit 1
[ "$option_count" -lt 1 ] && usage && exit 1

#CURR_USER: where set ? Usually LOGNAME
if [ "$CURR_USER" != "srvcdesk" ]; then
        log_msg "You must be srvcdesk to execute this script, ABORTING!"
        exit 5
fi

# make default, you can use { }, but not needed in your cases
ACTION_TYPE="$1"

if [ "$option_count" = 2 ]  # both are possible: string = and numeric -eq, 
then
 	TABLE_NAME="$1"
 	ACTION_TYPE="$2"			  
 	print "$ACTION_TYPE" 
	print "$TABLE_NAME"
fi	

APPLNAME="DBCheckSum"
LOGFILE="$NIGHTLY_LOG_DIR/$APPLNAME.$DATETIME_STAMP.log"
ERROR_LOGFILE="$NIGHTLY_LOG_DIR/$APPLNAME.$DATETIME_STAMP.err"

case "$option_count" in
  1)	java -Xms256m -Xmx1536m "$APPLNAME" "$ACTION_TYPE" > "$LOGFILE" 2> "$ERROR_LOGFILE"
  	;;
  2)    java -Xms256m -Xmx1536m "$APPLNAME" "$TABLE_NAME" "$ACTION_TYPE" > "$LOGFILE" 2> "$ERROR_LOGFILE"
  	;;
esac

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return code of command assigned to variable

How do I evaluate the result of a command assigned to a variable?? Example: var1=`cmd` rc=$? rc will be the result of the assignment rather than cmd since it executes after. How do I evaluate the result of the command itself? Cheers..:confused: (2 Replies)
Discussion started by: browndr
2 Replies

2. Solaris

Command to list all the VIP addresses assigned to Solaris server

Hello All, I want to list all the VIP addresses assigned to Solaris server. whats the command we have use on solaris for this? Please help Thanks!! Weblogic Consultant (1 Reply)
Discussion started by: weblogicsupport
1 Replies

3. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

4. Shell Programming and Scripting

perl script command line option driven script

could someone show me a sample command line option driven script? i want to see an easy way to write one and how i can execute it using command line options such as typing in read.pl -i <id> -c <cmds> -s <start> -e <end> would read out all the commands run by ID . from start time to... (7 Replies)
Discussion started by: kpddong
7 Replies

5. Solaris

Command files when the output is assigned to a variable

Hi, i'm posting this in the Solaris forum although maybe it should be better in the General unix forum, I'm formatting an output witht he following command: crontab -l | grep GBOUAT8 | grep UTP | grep -i stop | sed 's/\\//' 08 2 * * 2-6 /apps/sum_glob/gbo_uat/sparse/bin/dmg_cronlaunch -ENVI... (2 Replies)
Discussion started by: Cvg
2 Replies

6. Shell Programming and Scripting

Command executes on the command line but not from script

Hello guys, I have the following commands : Command 1: sudo find "../bundlepool" -name "merchandising2.html" -print0 |xargs -0 -I {} cp "rebranding/merchandising2.html" {} Command 2: find "../bundlepool" -name "merchandising2.html" -exec cp rebranding/merchandising2.html {} \; Command 3: ... (2 Replies)
Discussion started by: ihabo01
2 Replies

7. Shell Programming and Scripting

Syntax error piping to bc on command line - works when assigned to var

I have a script which outputs some timing data a line at a time. There are approx. 10 lines echoed, each line looks something like this: 0.741 http://checkip.dyndns.org 94.170.119.226Since I needed to add all the values in the first column, I piped the output to grep, matching and printing the... (7 Replies)
Discussion started by: gencon
7 Replies

8. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

9. Shell Programming and Scripting

Works on command line but not in script

OSX 10.9 I am building a script that evaluates the difference between 2 files. Here is a command that does not work transparently. Running this command in Terminal yields great results; however when I put that line in a .sh script, I get the errors shown below. Am I doing something silly? ... (1 Reply)
Discussion started by: sudo
1 Replies

10. Shell Programming and Scripting

Command assigned to a variable is failed or not having any data - error

Hi, My command is getting stuck while running it. observed that the grep command doesn't returned any data ($? was 1) and it failed. This command is assigned into the variable and used in other command as script progresses. To continue the script output, i have to press ^C twice and script... (2 Replies)
Discussion started by: abhii
2 Replies
Usage(3)						User Contributed Perl Documentation						  Usage(3)

NAME
pod2usage - print a usage message using a script's embedded pod documentation SYNOPSIS
use PDL::Pod::Usage; pod2usage(); pod2usage(2); pod2usage({EXIT => 2}); pod2usage({EXIT => 2, VERBOSE => 0}); pod2usage(EXIT => 1, VERBOSE => 2, OUTPUT=*STDERR); pod2usage(VERBOSE => 2); DESCRIPTION
pod2usage will print a usage message for the invoking script (using its embedded pod documentation) and then exit the script with the specified exit value. It takes a single argument which is either a numeric value corresponding to the desired exit status (which defaults to 2), or a reference to a hash. If more than one argument is given then the entire argument list is assumed to be a hash. If a hash is supplied it should contain elements with one or more of the following keys: "EXIT" The desired exit status to pass to the exit() function. "VERBOSE" The desired level of "verboseness" to use when printing the usage message. If the corresponding value is 0, then only the "SYNOPSIS" section of the pod documentation is printed. If the corresponding value is 1, then the "SYNOPSIS" section, along with any section entitled "OPTIONS", "ARGUMENTS", or "OPTIONS AND ARGUMENTS" is printed. If the corresponding value is 2 or more then the entire manpage is printed. "OUTPUT" A reference to a filehandle, or the pathname of a file to which the usage message should be written. The default is "*STDERR" unless the exit value is less than 2 (in which case the default is "*STDOUT"). "INPUT" A reference to a filehandle, or the pathname of a file from which the invoking script's pod documentation should be read. It defaults to the file indicated by $0 ($PROGRAM_NAME for "use English;" users). If neither the exit value nor the verbose level is specified, then the default is to use an exit value of 2 with a verbose level of 0. If an exit value is specified but the verbose level is not, then the verbose level will default to 1 if the exit value is less than 2 and will default to 0 otherwise. If a verbose level is specified but an exit value is not, then the exit value will default to 2 if the verbose level is 0 and will default to 1 otherwise. EXAMPLE
Most scripts should print some type of usage message to STDERR when a command line syntax error is detected. They should also provide an option (usually "-h" or "-help") to print a (possibly more verbose) usage message to STDOUT. Some scripts may even wish to go so far as to provide a means of printing their complete documentation to STDOUT (perhaps by allowing a "-man" option). The following example uses pod2usage in combination with Getopt::Long to do all of these things: use PDL::Pod::Usage; use Getopt::Long; GetOptions("help", "man") || pod2usage(2); pod2usage(1) if ($opt_help); pod2usage(VERBOSE => 2) if ($opt_man); CAVEATS
By default, pod2usage() will use $0 as the path to the pod input file. Unfortunately, not all systems on which Perl runs will set $0 properly (although if $0 isn't found, pod2usage() will search $ENV{PATH}). If this is the case for your system, you may need to explicitly specify the path to the pod docs for the invoking script using something similar to the following: o "pod2usage(EXIT => 2, INPUT => "/path/to/your/pod/docs");" AUTHOR
Brad Appleton <Brad_Appleton-GBDA001@email.mot.com> Based on code for Pod::Text::pod2text() written by Tom Christiansen <tchrist@mox.perl.com> perl v5.12.1 2009-10-17 Usage(3)
All times are GMT -4. The time now is 03:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy