Sponsored Content
Top Forums Shell Programming and Scripting Help! Yet another check element in array Question Post 302440885 by alan on Wednesday 28th of July 2010 07:20:39 PM
Old 07-28-2010
Help! Yet another check element in array Question

Greetings,

DISCLAIMER: My shell scripting is rusty so my question may be borderline stupid. You've been warned.

I need to create a script that a) lists the content of zip files in a directory and b) sends out an `exception` report. My ZIP files contain a control file (for load check). I want to abort the whole process if the control file is missing from the ZIP file.

Typically a zip file will have its contents looking like this:

Code:
file_1231232345.ctl
filea.txt
fileb.txt
filec.txt

Here what I wrote so far:
Code:
#!/bin/bash

#get today's date in YYYYMMDD formart 
DAY=`date +%Y%m%d`

#populate array of HDD zipped log(s) for today 
HDD_ZIP_Array=(`ls *${DAY}*.zip`)
HDD_ZIPlen=${#HDD_ZIP_Array[*]}

#echoes message if no files to process and exits. 
if [ $HDD_ZIPlen -eq 0 ]
then
        echo " HDD CheckZip -- $HDD_ZIPlen files! Process will exit!" ;         exit 1;
else
        for name in ${HDD_ZIP_Array[@]};
                 do
                echo " Zip File Name: $name"
                #list ZIP contents with unzip, remove header and trailer, 
                 #reverse sort to put control file name at index 0 and put file names in array().
                HDD_LIST_Array=(`unzip -l $name | head -n -2|tail -n +4 | sort -r | awk '{print $4}'`)
                HDD_LISTlen=${#HDD_LIST_Array[*]}
                #iterate array to 1) build exception report and 2) look for control file
                echo -e "Files in ZIP file: $name\n"     >> report.out
                        for (( i = 0 ; i < ${#HDD_LIST_Array[@]} ; i++ ))
                                do
                                        echo -e "${HDD_LIST_Array[$i]}"  >> report.out
                                done
                echo -e "\n  Number of files in ZIP file: $HDD_LISTlen."  >> report.out
              #since the name of the control contains a random number, glob CTL extension
               if [ $i != {*ctl} ]
              then
                   echo "Control file not found!" ; exit 2;
                fi
                done
fi

It is basic but it works. Except the bottom part where I test for the CTL file extension. It is not working whether the file is here or not.

What am missing?

Thanks for your input.

Last edited by alan; 07-28-2010 at 08:28 PM.. Reason: Please don't use font SIZE=1!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

accessing my first element of array

Hello everyonel, I have an array set like so num=4 read name arr=name I go through while loop to assign different values to different array element from 1 to 4. when I try to access the FIRST element of the array I get the last one first. Like if I say ${arr} it will show the last element... (4 Replies)
Discussion started by: afadaghi
4 Replies

2. Shell Programming and Scripting

A final question! Compare character with each array element

qwrtyuiop666yhh (1 Reply)
Discussion started by: rorey_breaker
1 Replies

3. Shell Programming and Scripting

Shift array element

I want to delete and 0th element of array in shell scrpit and also shift all others to one level up. (2 Replies)
Discussion started by: darshakraut
2 Replies

4. Shell Programming and Scripting

How to check index of a array element in shell script?

Example - Script to find the index of a month from array MONTHS="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" set -A MON $MONTHS A="Sun May 23 09:34:30 GMT 2010" getMonth=`echo $A|cut -c5-7` ##getMonth=May Arrayindex_in_MONTHS_array= ???? # { 0,1,2,3,4 } - at fifth place ... (7 Replies)
Discussion started by: KuldeepSinghTCS
7 Replies

5. Shell Programming and Scripting

remove an element from array

I need to remove an element from the below array variable TABLENAME. #!/bin/ksh set -A TABLENAME "mirf roxar keke mirs" echo "the array is ${TABLENAME}" If i need to remove say keke and have the final TABLENAME as below, how this could be achieved. Pls throw some light. echo "Modified... (3 Replies)
Discussion started by: michaelrozar17
3 Replies

6. Shell Programming and Scripting

Multiplying array element

I am trying to take all the elements of an array and multiply them by 2, and then copy them to a new array. Here is what I have i=0 for true in DMGLIST do let DMGSIZES2="${DMGSIZES}"*2 let i++ done unset i echo ${DMGSIZES2} It does the calculation correctly for the first element,... (7 Replies)
Discussion started by: nextyoyoma
7 Replies

7. Shell Programming and Scripting

Perl: How to check whether my array contains element x

Hi All, I am new to perl I am stuck in simple problem I need your help I want to define a subroutine. sub check_if_entity_exists(@array_to_be_checked,$entityName) I have array as http-listener-1 http-listener-2 http-listener-3 http-listener-4 If i send http-listener-3 my... (1 Reply)
Discussion started by: javaholics
1 Replies

8. Shell Programming and Scripting

How to insert an array element within regex?

Hello to all, I'm trying to separate the string "str" using a regex within match function. The substrings that I want to separate, begin with 22, 23, 24 or 25 and followed by 12 or 14 characters. And I want to replace 22 with MJS, 23 with UYT, 24 with WER and 25 with PIL. For this string... (4 Replies)
Discussion started by: Ophiuchus
4 Replies

9. UNIX for Advanced & Expert Users

Array Element

This question is for someone that's more familiar with Array Element. I need to know if the maximum array element that can be assigned is 1024 and if its so, Is there a workaround solution when the counter exceeded 1024? param_array="$param_nam" counter=$counter+1 #to avoid space... (3 Replies)
Discussion started by: cumeh1624
3 Replies

10. Shell Programming and Scripting

Awk: check element in array and it's value

Hello, I want to see if element exists in array, if so then, check it's corresponding value. Column 4 is position and column 1 is the chromosome for it. There are duplicates for one position on one chromosome. I want to check if same position exists on different chromosome: Data... (8 Replies)
Discussion started by: genome
8 Replies
jrunscript(1)						      General Commands Manual						     jrunscript(1)

NAME
jrunscript - command line script shell SYNOPSIS
jrunscript [ options ] [ arguments... ] PARAMETERS
options Options, if used, should follow immediately after the command name. arguments Arguments, if used, should follow immediately after options or command name. DESCRIPTION
jrunscript is a command line script shell. jrunscript supports both an interactive (read-eval-print) mode and a batch (-f option) mode of script execution. This is a scripting language independent shell. By default, JavaScript is the language used, but the -l option can be used to specify a different language. Through Java to scripting language communication, jrunscript supports "exploratory programming" style. NOTE: This tool is experimental and may not be available in future versions of the JDK. OPTIONS
-classpath path Specify where to find the user's .class files that are accessed by the script. -cp path This is a synonym for -classpath path -Dname=value Set a Java system property. -Jflag Pass flag directly to the Java virtual machine on which jrunscript is run. -l language Use the specified scripting language. By default, JavaScript is used. Note that to use other scripting languages, you also need to spec- ify the corresponding script engine's jar file using -cp or -classpath option. -e script Evaluate the given script. This option can be used to run "one liner" scripts specified completely on the command line. -encoding encoding Specify the character encoding used while reading script files. -f script-file Evaluate the given script file (batch mode). -f - Read and evaluate a script from standard input (interactive mode). -help Output help message and exit. -? Output help message and exit. -q List all script engines available and exit. ARGUMENTS
If [arguments...] are present and if no -e or -f option is used, then the first argument is the script file and the rest of the arguments, if any, are passed as script arguments. If [arguments..] and -e or -f option are used, then all [arguments..] are passed as script argu- ments. If [arguments..], -e and -f are missing, interactive mode is used. Script arguments are available to a script in an engine variable named "arguments" of type String array. EXAMPLES
Executing inline scripts jrunscript -e "print('hello world')" jrunscript -e "cat('http://java.sun.com')" Use specified language and evaluate given script file jrunscript -l js -f test.js Interactive mode jrunscript js>print('hello world'); hello world js>34 + 55 89 js> thread(function() { print('hello world'); } hello world js> Run script file with script arguments jrunscript test.js arg1 arg2 arg3 test.js is script file to execute and arg1, arg2 and arg3 are passed to script as script arguments. Script can access these using "argu- ments" array. SEE ALSO
If JavaScript is used, then before evaluating any user defined script, jrunscript initializes certain built-in functions and objects. These JavaScript built-ins are documented in jsdocs. 06 Aug 2006 jrunscript(1)
All times are GMT -4. The time now is 03:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy