how to write bash script that will automatically extract zip file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to write bash script that will automatically extract zip file
# 1  
Old 08-12-2012
how to write bash script that will automatically extract zip file

i'm trying to write a bash script that that will automatically extract zip files after the download.
i writed this script
PHP Code:
#!/bin/bash
wget -c https://github.com/RonGokhle/kernel-downloader/zipball/master
CURRENDIR=/home/kernel-downloader

cd $CURRENDIR
rm $CURRENDIR
/zipfiles 2>/dev/null

ls 
-*.zip
if [ $? -eq 0 ]
then
echo ".zip file found"
ls -1 $CURRENDIR/*.zip > $CURRENDIR/zipfiles
for i in `cat $CURRENDIR/zipfiles`
do
unzip $i
done
fi
if [ $? -eq 1 ]
then
echo "NOT found"
fi 
but it not unpack zip file after download, i'm only getting this error

PHP Code:
./script/testline 5cd: /kernel-downloaderNo such file or directory
ls
cannot access *.zipNo such file or directory 
can some give me idea's why i'm getting this error Smilie
# 2  
Old 08-12-2012
Are you sure the error msgs come from your script?
Code:
CURRENDIR=/home/kernel-downloader
cd $CURRENDIR

should give sth like cd: /home/kernel-downloader: No such file or directory if really missing.
Btw, rm $CURRENDIR/zipfiles should fail as well then.

wget downloads to the current directory, so in your case to wherever you were before you cd'd to somewhere else. So it's likely no .zip files are found making ls fail with your second err msg.

Aside, $? will NOT retain its contents but will be overwritten with the result of every single command you issue. If you need it later (... not found ...), save it to a variable immediately after the command that you are evaluating.
# 3  
Old 08-12-2012
Quote:
Btw, rm $CURRENDIR/zipfiles should fail as well then.
Further to @RudiC excellent post, the redirection of the error channel hides this error.


It is clear that the directory /home/kernel-downloader does not exist or that your Operating System (whatever that is?) needs the string containing the hyphen character in quotes.
Code:
cd "${CURRENDIR}"


Off-topic: Use hyphen characters in directory or file names at your own risk.
There is nothing to stop you using any character (except null) in a directory or file name, but hyphens, tabs and space characters will give you the most trouble.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to break up file (write new files) in bash

Hello experts, I need help writing individual files from a data matrix, with each new file being written every time there is a blank line: From this cat file.txt col1 col2 col3 6661 7771 8881 6661 7771 8881 6661 7771 8881 col1 col2 col3 3451 2221 1221... (6 Replies)
Discussion started by: torchij
6 Replies

2. UNIX for Dummies Questions & Answers

Write pid and command name to a txt file while executing a bash script

Hi All, Just have a requirement, I am executing a bash shell script, my requirement is to catch the pid and job name to a txt file in the same directory, is there anyway to do it? please help me out. Regards Rahul ---------- Post updated at 08:42 AM ---------- Previous update was at... (2 Replies)
Discussion started by: rahulkalra9
2 Replies

3. Shell Programming and Scripting

How to write a shell script to automatically accept return key with out user intervention?

Hi Friends, i am creating a shell script which is accepting file name as input parameter from Java and invoking finacle service. The service will accpet text file,B2k_session id,etc and upload the text file data in finacle database. My shell script looks like this:- #! /bin/ksh... (2 Replies)
Discussion started by: vadlamudy
2 Replies

4. Shell Programming and Scripting

How to write a script to extract strings from a file.

Hello fourm members, I want to write a script to extarct paticular strings from the all type of files(.sh files,logfiles,txtfiles) and redirect into a log file. example: I have to find the line below in the script and extract the uname and Pwds. sqsh -scia2007 -DD0011uw01 -uciadev... (5 Replies)
Discussion started by: rajkumar_g
5 Replies

5. Shell Programming and Scripting

script that will automatically extract

how do i write a script that will automatically extract rar files after the download in a particular folder? can you give me an idea please? :D or is there an existing script for this? (3 Replies)
Discussion started by: garfish
3 Replies

6. Shell Programming and Scripting

To write a shell script which groups files with certain pattern, create a tar and zip

Hi Guru's, I have to write a shell script which groups file names based upon the certain matching string pattern, then creates the Tar file for that particular group of files and then zips the Tar file created for the respective group of files. For example, In the given directory these files... (3 Replies)
Discussion started by: rahu_sg
3 Replies

7. Shell Programming and Scripting

How to write bash script to explode multiple zip files

I have a directory full of zip files. How would I write a bash script to enumerate all the zip files, remove the ".zip" from the file name, create a directory by that name and unzip each zip file into its corresponding directory? Thanks! Siegfried (3 Replies)
Discussion started by: siegfried
3 Replies

8. Shell Programming and Scripting

how to extract paragraphs from file in BASH script followed by prefix ! , !! and !!!

I]hi all i am in confusion since last 2 days :( i posted thraed yesterday and some friends did help but still i couldnt get solution to my problem let it be very clear i have a long log file of alkatel switch and i have to seperate the minor major and critical alarms shown by ! , !! and !!!... (6 Replies)
Discussion started by: nabmufti
6 Replies

9. Shell Programming and Scripting

Extract lines from a file automatically. Please a Help

hello, hope you can help me: ive got a file called archivos The content or structure of this file is ./chu0/filechu ./chu1/filechu I extract each line from this file manually and redirect to a file, and it Works fine, so the command line is: awk ‘/chu0/ {print $0}' < archivos >... (8 Replies)
Discussion started by: alexcol
8 Replies

10. Shell Programming and Scripting

need help to write script to check the process health and automatically restart it

I am working on a project, which need to constantly watch the process, and check its status, if it was dead, it should be restart automatically. Please kindly refer me to URL which teach how to write this kind of script, or service. Thanks. (1 Reply)
Discussion started by: dragondad
1 Replies
Login or Register to Ask a Question