Sponsored Content
Top Forums Shell Programming and Scripting Custom exit message according to flag Post 303045141 by sea on Thursday 12th of March 2020 02:07:18 PM
Old 03-12-2020
I didnt request the whole code, just the first commented line.
Anyway, thanks.

First and foremost, both "${2:-}" are useless, as that would fill an empty variable with... emptyness.
Second, you dont want something in a variable that defines an extra option - if it hasnt been set by the user.

I'll keep the short approach you've had in the first post:
Code:
curl_args="--fail --max-time 3"


case ${#@} in
1)	url="$1"
	exit_msg="connecting to $url"
	;;
2)	url="$1"
	curl_args="$curl_args -x \"$2\""	# The 'inner' quotes needs escape so they are there when the variable is reused
	exit_msg="connecting to $url via $2"
	;;
esac

curl $curl_args "$url"
ret=$?

[[ 0 = $ret ]] && \
	exit_msg="SUCCESS - $exit_msg" || \
	exit_msg="FAILURE - $exit_msg"

echo "$exit_msg"
exit $ret

hth & hf

Last edited by sea; 03-12-2020 at 03:10 PM.. Reason: typo
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies

2. Shell Programming and Scripting

cant get the right exit message

#!/bin/ksh application task run command //returns 0 if successful if ; then echo "Ran Fine" else echo "Didnt run" fi When I run the script, here is the output Status code = 0 ksh: [0: not found. Job didnt run any suggestions? (4 Replies)
Discussion started by: bryan
4 Replies

3. Programming

How to limit max no of message in a posix message queue

Hii can anyone pls tell how to limit the max no of message in a posix message queue. I have made changes in proc/sys/fs/mqueue/msg_max But still whenever i try to read the value of max. message in the queue using attr.mq_curmsgs (where struct mq_attr attr) its giving the default value as 10.... (0 Replies)
Discussion started by: mohit3884
0 Replies

4. AIX

du flag -x

Hi, I would like to know if there's any option to use with the du command so that I can list only the files/directories on the current filesystem... I usually use du -gs *But I'd like to see only the directories in the filesystem I am on, and not the mount point directory of other fss... ... (6 Replies)
Discussion started by: Casey
6 Replies

5. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 Replies

6. UNIX for Dummies Questions & Answers

'h' flag in du

Hey, all! Why is the "human readable" flag changing the behavior of du? And while I'm at it, can you make du only look at files, not directories. I often find myself wanting to find the largest file(s) in a dir or vol. Using 'find' itself, it seems you have to at least be able to guess the size of... (2 Replies)
Discussion started by: sudon't
2 Replies

7. Shell Programming and Scripting

Need the difference between exit 1 & exit 7

Hi In one of the script I am seeing some thing like exit 7,exit 1,exit 2,exit 3,exit 9,exit6.What is the difference between all of this exit.Can anyone help here please (3 Replies)
Discussion started by: ginrkf
3 Replies

8. UNIX for Dummies Questions & Answers

Get the id with specify flag

.... means multi line ddd,bug fgdrg dfdfsdfdfsd fsdfdfdfd fdfdsfdsfsd ....... flag2 ...... aaa,bug sfsfsfsfs dfdfsdfdfsd fsdfdfdfd fdfdsfdsfsd ...... flag1 ...... ddd,bug fgdrg dfdfsdfdfsd (9 Replies)
Discussion started by: yanglei_fage
9 Replies

9. Shell Programming and Scripting

awk to supress error message with custom text

After a bash function is run the below file is produced: out_name.txt tab-delimeted Input Errors and warnings AccNo Genesymbol Variant Reference Sequence Start Descr. Coding DNA Descr. Protein Descr. GeneSymbol Coding DNA Descr. GeneSymbol Protein Descr. Genomic... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. IP Networking

Insmod custom module fails with message : disagrees about version of symbol ...

Hello : I want to make a netfilter conntrack module for myself. So I copy all the source code about netfilter conntrack from kernel source tree to my external directory. It can be insmod after compiled. Then I add some members to the struct nf_conn, and it 's compiled successfully. However, it... (1 Reply)
Discussion started by: 915086731
1 Replies
libapache2-mod-perl2-2.0.7::docs::api::Apache2::URI(3pm)User Contributed Perl Documentatiolibapache2-mod-perl2-2.0.7::docs::api::Apache2::URI(3pm)

NAME
Apache2::URI - Perl API for manipulating URIs Synopsis use Apache2::URI (); $hostport = $r->construct_server(); $hostport = $r->construct_server($hostname); $hostport = $r->construct_server($hostname, $port); $hostport = $r->construct_server($hostname, $port, $pool); $url = $r->construct_url(); $url = $r->construct_url($rel_uri); $url = $r->construct_url($rel_uri, $pool); $parsed_uri = $r->parse_uri($uri); $parsed_uri = $r->parsed_uri(); $url = join '%20', qw(one two three); Apache2::URI::unescape_url($url); Description While "APR::URI" provides a generic API to dissect, adjust and put together any given URI string, "Apache2::URI" provides an API specific to Apache, by taking the information directly from the $r object. Therefore when manipulating the URI of the current HTTP request usually methods from both classes are used. API
"Apache2::URI" provides the following functions and methods: "construct_server" Construct a string made of hostname and port $hostport = $r->construct_server(); $hostport = $r->construct_server($hostname); $hostport = $r->construct_server($hostname, $port); $hostport = $r->construct_server($hostname, $port, $pool); obj: $r ( "Apache2::RequestRec object" ) The current request object opt arg1: $hostname ( string ) The hostname of the server. If that argument is not passed, "$r->get_server_name" is used. opt arg2: $port ( string ) The port the server is running on. If that argument is not passed, "$r->get_server_port" is used. opt arg3: $pool ( "APR::Pool object" ) The pool to allocate the string from. If that argument is not passed, "$r->pool" is used. ret: $hostport ( string ) The server's hostport string since: 2.0.00 Examples: o Assuming that: $r->get_server_name == "localhost"; $r->get_server_port == 8001; The code: $hostport = $r->construct_server(); returns a string: localhost:8001 o The following code sets the values explicitly: $hostport = $r->construct_server("my.example.com", 8888); and it returns a string: my.example.com:8888 "construct_url" Build a fully qualified URL from the uri and information in the request rec: $url = $r->construct_url(); $url = $r->construct_url($rel_uri); $url = $r->construct_url($rel_uri, $pool); obj: $r ( "Apache2::RequestRec object" ) The current request object opt arg1: $rel_uri ( string ) The path to the requested file (it may include a concatenation of path, query and fragment components). If that argument is not passed, "$r->uri" is used. opt arg2: $pool ( "APR::Pool object" ) The pool to allocate the URL from If that argument is not passed, "$r->pool" is used. ret: $url ( string ) A fully qualified URL since: 2.0.00 Examples: o Assuming that the request was http://localhost.localdomain:8529/test?args The code: my $url = $r->construct_url; returns the string: http://localhost.localdomain:8529/test notice that the query (args) component is not in the string. You need to append it manually if it's needed. o Assuming that the request was http://localhost.localdomain:8529/test?args The code: my $rel_uri = "/foo/bar?tar"; my $url = $r->construct_url($rel_uri); returns the string: http://localhost.localdomain:8529/foo/bar?tar "parse_uri" Break apart URI (affecting the current request's uri components) $r->parse_uri($uri); obj: $r ( "Apache2::RequestRec object" ) The current request object arg1: $uri ( string ) The uri to break apart ret: no return value warning: This method has several side-effects explained below since: 2.0.00 This method call has the following side-effects: 1. sets "$r->args" to the rest after '?' if such exists in the passed $uri, otherwise sets it to "undef". 2. sets "$r->uri" to the passed $uri without the "$r->args" part. 3. sets "$r->hostname" (if not set already) using the ("scheme://host:port") parts of the passed $uri. "parsed_uri" Get the current request's parsed uri object my $uri = $r->parsed_uri(); obj: $r ( "Apache2::RequestRec object" ) The current request object ret: $uri ( "APR::URI object" ) The parsed uri since: 2.0.00 This object is suitable for using with "APR::URI::rpath" "unescape_url" Unescape URLs Apache2::URI::unescape_url($url); obj: $url ( string ) The URL to unescape ret: no return value The argument $url is now unescaped since: 2.0.00 Example: my $url = join '%20', qw(one two three); Apache2::URI::unescape_url($url); $url now contains the string: "one two three"; See Also "APR::URI", mod_perl 2.0 documentation. Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. Authors The mod_perl development team and numerous contributors. perl v5.14.2 2011-02-08 libapache2-mod-perl2-2.0.7::docs::api::Apache2::URI(3pm)
All times are GMT -4. The time now is 09:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy