I am looking for a shell script where counter needs to be set for input paramter and do action once the count reaches to 5. The problem is there could be n number of input parameter and action should also be dependent on time ... Lets suppose if within 60 mins if count reaches upto 5 then which ever action i want to do .......

I found somthing like below but there is no explanation in this programm.....Please help...

echo "Enter a series of lines of numbers separated by spaces."
read LIST
IFS=" "
for VALUE in $LIST ; do
    eval export ARRAY_$COUNTER
    COUNTER=$(expr $COUNTER '+' 1) # More on this in Paint by Numbers

# print the exported variables.
echo "Printing values."
while [ $COUNTERB -lt $COUNTER ] ; do
    echo "ARRAY[$COUNTERB] = $(eval echo '$'ARRAY_$COUNTERB)"
    COUNTERB=$(expr $COUNTERB '+' 1) # More on this in Paint by Numbers



If your script is going to be called multiple times then you need to keep the counter in some external persistent form, a environment variable or file. In this case ARRAY_n is exported for this purpose.

  • Thanks for the response... Can I use the same srcipt as I am not sure i searched it from some link...... – user28011 Nov 30 '12 at 4:38
  • I have tried below way but its not working as its again and again showing as count as 1....x="$device" count=0 for device_count in $x do count=expr $count + 1 echo "pe_[$device_count] count $count" >> ${LOGFILE} if [ count -eq 5 ]; then echo "email " >> ${LOGFILE} fi done – user28011 Nov 30 '12 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.