Sponsored Content
Full Discussion: Identify script please!
Top Forums Shell Programming and Scripting Identify script please! Post 302488576 by bound4h on Monday 17th of January 2011 06:56:53 PM
Old 01-17-2011
For some reason when I use your two lines, it tries to unzip two files because there is a space in the file name. Here is the whole script. I adapted it from an unpacking script, so that I could unzip a folder full of zip files:

Code:
#!/bin/sh

DLDIR=/mnt/HD_a2/files
LOG=/mnt/usb/logs/unzip.log
UNZIP=/opt/bin/unzip-unzip

  # check incoming DLDIR
  for FILE in `find $DLDIR -name "*.zip"`; do
    if [ "$FILE" != "*.zip" ]; then
      # shell-fu to extract to path containing the rar
      #FILENAME=`expr //$FILE : '.*/\(.*\)'`
      #UNPACKDIR=`echo $FILE | sed -e s/$FILENAME//g`
      FILENAME=$(basename $FILE)
      UNPACKDIR=$(dirname $FILE) 
      echo [`date`] Extracting "$FILE" ... >> $LOG

      # unzip file to the directory its sitting in
      $UNZIP "$FILE" -d "$UNPACKDIR" >> /dev/null 2>&1
      echo [`date`] ... done extracting. >> $LOG

      # cleanup - remove the rar file(s)
      # note: match .rar, .r01, .r02 ... etc
      echo [`date`] Removing "$FILENAME and zip files." >> $LOG
      for j in `find "$DLDIR" -name "*.zip"`; do
        rm $j
      done
    fi
  done
  echo [`date`] Done unpacking/extracting \(if any necessary\)... >> $LOG

# fi

exit 0

So if I have /mnt/HD_a2/files/The App.app.zip, then it tries to unzip (and remove) The and App.app.zip which fails. I know there's an easy command but I just don't know how. I have the same issue when I use the original script to unrar files, they cannot have spaces in the filename. Is there also a way to chmod the unzip/unrar FOLDER and its contents to 777 after it unzips/unrars it? Because I have the script running by root, and when I access the files using AFP (under user called nobody) I can't move/delete them.

Thanks for your help!

Last edited by Franklin52; 01-19-2011 at 03:22 AM.. Reason: Please use code tags instead of quote tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to identify the calling script?

Hi, I have two scripts ( /tmp/k1.sh and /tmp/k2.sh ). k1.sh calls the k2.sh . For security reasons, I must be sure that the k2.sh is being called by the k1.sh . Is it possible for the k2.sh identify that it's been called by the k1.sh? I mean, identify the complete path of the k1.sh (... (6 Replies)
Discussion started by: crematoriumm
6 Replies

2. Shell Programming and Scripting

test script to identify SHELL

I am new to BASH and writing a small script to identify the SHELL . #!/bin/bash BASH='/bin/bash' KSH='/bin/ksh' if then echo "it's Bash" else echo "it's not Bash" fi $ bash -x a.sh + BASH=/bin/bash + KSH=/bin/ksh + '' a.sh: line 4: where am I missing . PLease advice . (10 Replies)
Discussion started by: talashil
10 Replies

3. Shell Programming and Scripting

Shell script to identify the number of files and to append data

Hi I am having a question where I have to 1) Identify the number of files in a directory with a specific format and if the count is >1 we need to concatenate those two files into one file and remember that in the second file the header should not be copied. it should be form first file.... (4 Replies)
Discussion started by: pradkumar
4 Replies

4. AIX

Script to identify high CPU usage processes

Hi Guys, I need to write a script capable of identifying when a high cpu utilitzation process. It sounds simple but we are on a AIX 5.3 environment with Virtual CPU's (VP's) and logical CPU's. Please any ideas or tips would be highly appreciated. Thanks. Harby. (6 Replies)
Discussion started by: arizah
6 Replies

5. Shell Programming and Scripting

Using an awk script to identify dupes in two files

Hello, I have two files. File1 or the master file contains two columns separated by a delimiter: a=b b=d e=f g=h File 2 which is the file to be processed has only a single column a h c b What I need is an awk script to identify unique names from file 2 which are not found in the... (6 Replies)
Discussion started by: gimley
6 Replies

6. Shell Programming and Scripting

Script to Identify if folder has a file in it

Hi everyone I am new to the forums. I haven't done much linux myself but I have been asked if I can do the following. Write a linux script that needs to scan a certain folder every x amount of minutes and if there is a file in the folder then it needs to call a different script. Is this... (2 Replies)
Discussion started by: Bosbaba
2 Replies

7. Shell Programming and Scripting

Perl Script to identify files without extension and assign a value

Hi, I have a perl script which is a part of a shell script which read lines from a flat file(which is generated as part of a script after a series of bteq/fexp) and assigns a value for each object in the file based on the type of file name. (i.e extensions like .bteq/.ctl/.ksh etc) For example,... (1 Reply)
Discussion started by: yohasini
1 Replies

8. Shell Programming and Scripting

How to identify whether the script is in Unix format or not ?

Hi All, I have the below scenario in my environment Developers used to copy file from windows to Linux box. Some time on the copied file developers miss to run the dos2unix utility. Because of this script gets failed during the execution. Most of the failures are due to the dos2unix format... (7 Replies)
Discussion started by: kalpeer
7 Replies

9. Shell Programming and Scripting

Identify variables used in the shell script

Hi, Is there any simple way to get/identify the variables that are used in a file and print those variable names. If I have something like this in a file, /$var/temp_dir/${var2}${var3}.log I want to display the variables 'var', 'var2' and 'var3' from that file. I tried something like... (6 Replies)
Discussion started by: pvamsikr
6 Replies

10. Shell Programming and Scripting

Unable to identify error in the script

cat test3.sh #!/bin/sh set -x while getopts ":n:" opt; do case "$opt" in n) host=$OPTARG shift 2 ;; -h ) host=$2 shift 2 ;; *) break ;; esac done; echo "host =... (7 Replies)
Discussion started by: Vishal_dba
7 Replies
ZIPGREP(1L)															       ZIPGREP(1L)

NAME
zipgrep - search files in a ZIP archive for lines matching a pattern SYNOPSIS
zipgrep [egrep_options] pattern file[.zip] [file(s) ...] [-x xfile(s) ...] DESCRIPTION
zipgrep will search files within a ZIP archive for lines matching the given string or pattern. zipgrep is a shell script and requires egrep(1) and unzip(1L) to function. Its output is identical to that of egrep(1). ARGUMENTS
pattern The pattern to be located within a ZIP archive. Any string or regular expression accepted by egrep(1) may be used. file[.zip] Path of the ZIP archive. (Wildcard expressions for the ZIP archive name are not supported.) If the literal filename is not found, the suffix .zip is appended. Note that self-extracting ZIP files are supported, as with any other ZIP archive; just specify the .exe suffix (if any) explicitly. [file(s)] An optional list of archive members to be processed, separated by spaces. If no member files are specified, all members of the ZIP archive are searched. Regular expressions (wildcards) may be used to match multiple members: * matches a sequence of 0 or more characters ? matches exactly 1 character [...] matches any single character found inside the brackets; ranges are specified by a beginning character, a hyphen, and an end- ing character. If an exclamation point or a caret (`!' or `^') follows the left bracket, then the range of characters within the brackets is complemented (that is, anything except the characters inside the brackets is considered a match). (Be sure to quote any character that might otherwise be interpreted or modified by the operating system.) [-x xfile(s)] An optional list of archive members to be excluded from processing. Since wildcard characters match directory separators (`/'), this option may be used to exclude any files that are in subdirectories. For example, ``zipgrep grumpy foo *.[ch] -x */*'' would search for the string ``grumpy'' in all C source files in the main directory of the ``foo'' archive, but none in any subdirectories. Without the -x option, all C source files in all directories within the zipfile would be searched. OPTIONS
All options prior to the ZIP archive filename are passed to egrep(1). SEE ALSO
egrep(1), unzip(1L), zip(1L), funzip(1L), zipcloak(1L), zipinfo(1L), zipnote(1L), zipsplit(1L) URL
The Info-ZIP home page is currently at http://www.info-zip.org/pub/infozip/ or ftp://ftp.info-zip.org/pub/infozip/ . AUTHORS
zipgrep was written by Jean-loup Gailly. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWunzip | +--------------------+-----------------+ |Interface Stability | External | +--------------------+-----------------+ NOTES
Source for unzip is available on http://opensolaris.org. Info-ZIP 28 November 2007 ZIPGREP(1L)
All times are GMT -4. The time now is 02:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy