Sponsored Content
Full Discussion: Infinite looping in script
Top Forums Shell Programming and Scripting Infinite looping in script Post 302858891 by anshu ranjan on Tuesday 1st of October 2013 03:06:41 PM
Old 10-01-2013
Infinite looping in script

we have one script which we use to send mail in our environment. If we are giving correct attachment script runs fine but if we give a attachment name which is not present on server then this script go to infinite loop and causing all memory to be used. could any one please suggest me what is wrong

below is the portion of script where attachment condition is defined.

Code:
#==========================================
#  Validate the passed arguments
#

attach_total_size=0
n=0
while [[ $n -lt ${#PASSED_ATTACHMENTS[*]} ]];
do
   if [[ ! -r ${PASSED_ATTACHMENTS[$n]} ]];
   then
      invalid_attachments="$invalid_attachments ${PASSED_ATTACHMENTS[$n]}"
      continue
   else
      size=$(ls -al ${PASSED_ATTACHMENTS[$n]} | awk '{print $5}')
      (( attach_total_size = attach_total_size + size ))
   fi
   (( n = n + 1 ))
done

# Check if the size of overall attachments doesn't exceed Limit (2MB=2097152Byte)
if [[ $attach_total_size -gt $ATTACH_SIZE_LIMIT ]] ;
then
   msg "Attachment(s) not included due to the size larger than 2MB."
   ret_val2=$ERR_ATTACHMENT
elif [[ -n ${invalid_attachments} ]];
then
   msg "Attachment(s), ${invalid_attachments}, not found. Aborting."
   return $ERR_INVALID_VALUE
fi

when we use wrong attachment (attachment is not present) then scripts goes to infinite loop. below is the O/P of debugging mode. in below example "/home/auto/anshu/attccc" is the file name which is not present on server.

Code:
+ attach_total_size=0
+ n=0
+ [[ 0 -lt 1 ]]
+ [[ ! -r /home/auto/anshu/attccc ]]
+ invalid_attachments=' /home/auto/anshu/attccc'
+ continue
+ [[ 0 -lt 1 ]]
+ [[ ! -r /home/auto/anshu/attccc ]]
+ invalid_attachments=' /home/auto/anshu/attccc /home/auto/anshu/attccc'
+ continue
+ [[ 0 -lt 1 ]]
+ [[ ! -r /home/auto/anshu/attccc ]]
+ invalid_attachments=' /home/auto/anshu/attccc /home/auto/anshu/attccc /home/auto/anshu/attccc'
+ continue
+ [[ 0 -lt 1 ]]
+ [[ ! -r /home/auto/anshu/attccc ]]
+ invalid_attachments=' /home/auto/anshu/attccc /home/auto/anshu/attccc /home/auto/anshu/attccc /home/auto/anshu/attccc'
+ continue


Last edited by Neo; 10-01-2013 at 04:24 PM.. Reason: Changed icode tags to code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running a script in INFINITE LOOP

Hi All, I have a requirement as below. I supposed to get a file from Source system once in a month. But we dont know when the source system will send the file. My script has to wait for that file in LOOP once it gets the file then it has to FTP the file. I thought of scheduling the job... (5 Replies)
Discussion started by: Raamc
5 Replies

2. Shell Programming and Scripting

Infinite loop not looping

Hi guys, I'm having a problem getting my infinite loop to loop. It simply reads in the users choice form the menu, executes the corresponding case statement and quits instead of looping back to the main menu again. I have a feeling it might be something with my if then statements within the case... (2 Replies)
Discussion started by: hootdocta5
2 Replies

3. Shell Programming and Scripting

Script to run infinite loop

Hi all, I have a script which triggers batch admin manager and gets the top 10 jobs and their status info. the output of this script is the list of all these jobs. I want to run this in infinite loop which will show top 100 jobs' status. the script is as follows #!/bin/sh exec &> capture1.txt... (1 Reply)
Discussion started by: digitalrg
1 Replies

4. Shell Programming and Scripting

Script with infinite loop stops after sometime

Hi I am working on a server that is set up and maintained by a third party. It seems whenever I run bash scripts in the background (with a &) with while loops in them they seem to me killed in around 2.5 hours. ( I am running them as a normal user with no special privileges ) . Is there a... (3 Replies)
Discussion started by: pkabali
3 Replies

5. Shell Programming and Scripting

Looping in the shell script with help of script timer.

Hello Experts- We are facing some issues in the while loop script when we use the script time to decide whether to exist from the loop or continue. Below is the script SrcExitLoop="FALSE" Src_InitialStartTime=`date +%s` Src_StartTime=`date +%s` Src_NUM_ALERTS=0 TOTAL_ALERTS=`expr <SOME... (4 Replies)
Discussion started by: Amey Joshi
4 Replies

6. Shell Programming and Scripting

Infinite while loop script shows more than one process

Hi, I have a script which triggers an infinite loop. #!bin/bash trig=`ls /home/trig.tch |wc -l` function callj { some commands... } while do callj & done The number of process after doing a ps -ef |grep Mon.sh returns processes even after the script is killed by deleting the... (4 Replies)
Discussion started by: chetan.c
4 Replies

7. Shell Programming and Scripting

Select command going to infinite loop after running the script

cd /opt/et/WAS/apps/8.0 find . -name "HostIntegration.properties" -o -name "HostSocket.properties" -o -name "environment.properties" 2> /dev/null | awk -F '' '{print $4}'|awk '!x++' | cat>/home/cbadmin/file1.txt cd /home/cbadmin/ PS3='Please enter a number from list of applications==>:' select... (3 Replies)
Discussion started by: bhas85
3 Replies

8. Shell Programming and Scripting

Calling a script from a shell that needs to cancel out of infinite loop

I am writing a shell script that calls this oracle utility to get some information about the DB that I need for the script https://docs.oracle.com/cd/B16240_01/doc/em.102/e15294/options.htm This is the command that I am running: $ORACLE_HOME/OPatch/opatch lsinventory -details | grep -i... (1 Reply)
Discussion started by: guessingo
1 Replies

9. Programming

Nmap shell script goes in infinite loop

My script’s output goes in infinite loop Below is my script: Nmap() { while read -r line do name="$line" echo "$name" count=$line nmap -oG output.txt -T4 -f -iL iplist.txt $line1 done < iplist.txt } Nmap ................................................................. ... (2 Replies)
Discussion started by: sk151993
2 Replies

10. Shell Programming and Scripting

Read function is going in infinite in another script having while loop

Hello Experts, I have created one user confirmation process that will ask for user input. I have created one func for it. The issue is if i call it as normal then it works fine but if i am calling it in another script(in while loop) . It is going in infinite loop and not asking for user input. ... (8 Replies)
Discussion started by: looney
8 Replies
NETRC(5)						      BSD File Formats Manual							  NETRC(5)

NAME
netrc, .netrc -- user configuration for ftp DESCRIPTION
This file contains configuration and autologin information for the File Transfer Protocol client ftp(1). The .netrc file contains login and initialization information used by the auto-login process. It resides in the user's home directory. The following tokens are recognized; they may be separated by spaces, tabs, or new-lines: machine name Identify a remote machine name. The auto-login process searches the .netrc file for a machine token that matches the remote machine specified on the ftp command line or as an open command argument. Once a match is made, the subsequent .netrc tokens are processed, stopping when the end of file is reached or another machine or a default token is encountered. default This is the same as machine name except that default matches any name. There can be only one default token, and it must be after all machine tokens. This is normally used as: default login anonymous password user@site thereby giving the user automatic anonymous ftp login to machines not specified in .netrc. This can be overridden by using the -n flag to disable auto-login. login name Identify a user on the remote machine. If this token is present, the auto-login process will initiate a login using the specified name. password string Supply a password. If this token is present, the auto-login process will supply the specified string if the remote server requires a password as part of the login process. Note that if this token is present in the .netrc file for any user other than anonymous, ftp will abort the auto-login process if the .netrc is readable by anyone besides the user. account string Supply an additional account password. If this token is present, the auto-login process will supply the specified string if the remote server requires an additional account password, or the auto-login process will initiate an ACCT command if it does not. macdef name Define a macro. This token functions like the ftp macdef command functions. A macro is defined with the specified name; its con- tents begin with the next .netrc line and continue until a null line (consecutive new-line characters) is encountered. If a macro named init is defined, it is automatically executed as the last step in the auto-login process. SEE ALSO
ftp(1), ftpd(8) Linux NetKit (0.17) September 23, 1997 Linux NetKit (0.17)
All times are GMT -4. The time now is 06:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy