Sponsored Content
Top Forums Shell Programming and Scripting To reduce the bash script length!!! Post 302506286 by ctsgnb on Saturday 19th of March 2011 06:55:18 PM
Old 03-19-2011
Inspired from Danero's code with some modif (ksh + building a parameter file + adding function _get_param ) i didn't try it so it may requires some little adaptation or fix.

Code:
#!/usr/bin/ksh

PARAMFILE=status.cfg

cat <<-EOF >$PARAMFILE
200:okay:M
201:created
202:Accepted
203:Non-Authoritative Information
204:No Content
205:Reset Content
206:Partial Content
207:Multi-Status
226:IM Used
300:Multiple choices
301:Moved Permanently
302:found
303:See Other
304:Not Modified
305:Use Proxy
306:UnUsed
307:Temporary Redirect
400:Bad Request:M
401:Unauthorized:M
402:Payment Required:M
403:Forbidden:M
404:Page Not Found:M
405:Method Not Allowed :M
406:Not Acceptable:M
407:Proxy Authentication Required:M
408:Request Timeout:M
409:Conflict:M
410:Gone:M
411:Length Required:M
412:Precondition Failed:M
413:Request Entity Too Large:M
414:Request-URI Too Long:M
415:Unsupported Media Type :M
416:Requested Range Not Satisfiable:M
417:Expectation Failed:M
422:Unprocessable Entity:M
423:Locked:M
424:Failed Dependency:M
425:Unordered Collection:M
426:Upgrade Required:M
444:No Response:M
449:Retry With:M
450:Blocked by Windows Parental Controls:M
499:Client Closed Request:M
500:Internal Server Error:M
501:Not Implemented:M
502:Bad Gateway:M
503:Service Unavailable:M
504:Gateway Timeout:M
505:HTTP Version Not Supported:M
506:Variant Also Negotiates:M
507:Insufficient Storage:M
509:Bandwidth Limit Exceeded:M
510:Not Extended:M
EOF

echo "BP "
STA=
ML=
MSG=
_get_param(){
        awk -F: -v c="$1" '$0~c{print $1,($3=="M")?Y:N,$2}' $PARAMFILE | read STA ML MSG
}

timevar=$(date +%d-%m-%Y_%H.%M.%S) #—– > Storing Date and Time in a Variable
get_contents=`cat ./urls.txt`  #—- > Getting content of website from  file. Note the file should not contain any http:// as its already been  taken care of
######### Next Section Does all the processing #########
_echo(){
        echo $1 $2 $3 $4  >> /log.txt
}
_mail(){
        echo "Status $1 found" | mail -s "Check of $2 failed" 07anis@gmail.com
}

for i in $get_contents
do
statuscode=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s  -I -L http://$i | awk '{for(i = 1; i<=NF; i++)  if($i=="“totaltime:0.000n”“totaltime:0.000n”HTTP/1.1") print $(i+1);}'`

_get_param $statuscode
_echo $timevar $i $statuscode $MSG
[[ $ML == Y ]] && _mail $statuscode $i

done
rm $PARAMFILE

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to reduce a length in a file?

i want to reduce a length in the file called text in the file im having 10 byte length. want to reduce it to 9 byte length for all lines. (5 Replies)
Discussion started by: laknar
5 Replies

2. Shell Programming and Scripting

need inputs on how i can change my script to reduce amount of time the script takes

HI , I have a list1 which consists of data that i have to search and a list2 which has the files that need to be searched .So basically i am using list1 on list2 to see if list1 data is present if found replace it .I have written the code using foreach loop for each list .This is taking the... (1 Reply)
Discussion started by: madhul2002
1 Replies

3. Shell Programming and Scripting

How to reduce the length of records in a file?

I have a file with 400 characters How can I create another file with only a portion of them (like 300 within 400) and get rid of the rest? Thanks (5 Replies)
Discussion started by: fafchi
5 Replies

4. Shell Programming and Scripting

How to make bash wrapper for java/groovy program with variable length arguments lists?

The following bash script does not work because the java/groovy code always thinks there are four arguments even if there are only 1 or 2. As you can see from my hideous backslashes, I am using cygwin bash on windows. export... (1 Reply)
Discussion started by: siegfried
1 Replies

5. Shell Programming and Scripting

Automation script to reduce the installation time

DELETED. (0 Replies)
Discussion started by: vasuvv
0 Replies

6. Shell Programming and Scripting

Reduce the number of lines in script

Hello All, I have created a script which will show the errors from a log file in between a particular section. v1=$(sed -n "/Main Report/,/Main Report End/p" input | grep -i 'Unable to find' v2=$(sed -n "/Main Report/,/Main Report End/p" input | grep -i 'Unable to add' if then echo... (5 Replies)
Discussion started by: Vikram_Tanwar12
5 Replies

7. Shell Programming and Scripting

Bash - delete from csv all the row if the first column is length >

Hi guys, i have a csv file like: USERID;COG;DESCR;FIL;OFF user001;user;test1;001;A01 user002;user;test2;002;A02 user0003;user;test3;003;A03 user004;user;test4;004;A04 user0005;user;test5;005;A05 etc.. I need to read line for line and, if value of first column is > 7 char (in this example... (4 Replies)
Discussion started by: kamose
4 Replies

8. Shell Programming and Scripting

Optimizing script to reduce execution time

AFILENAME=glow.sh FILENAME="/${AFILENAME}" WIDTHA=$(echo ${FILENAME} | wc -c) NTIME=0 RESULTS=$(for eachletter in $(echo ${FILENAME} | fold -w 1) do WIDTHTIMES=$(awk "BEGIN{printf... (5 Replies)
Discussion started by: SkySmart
5 Replies

9. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies
exit(1)                                                            User Commands                                                           exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 04:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy