Download and Untar any URL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Download and Untar any URL
# 1  
Old 09-22-2012
Download and Untar any URL

Hi,

I am trying to make a flexible bash script which does the following:

Downloads a URL from a variable
Unzips it
Deletes the original archive

The problem is, the format could be .tar, .tar.gz etc, it wont be constant.

This is what I have currently:

Code:
#!/bin/bash

dl_dir="/opt"


function file_download()
{
    wget $2 -P "$dl_dir"
    tar xzf $1 -C $1
}

function user_create()
{
    useradd -s /usr/sbin/nologin -r $2
    chown -R $1 /opt/$1
}

# NGINX
name="nginx"
name_url="http://nginx.org/download/nginx-1.1.2.tar.gz"
file_download "$name" "${name}_url"
user_create "$name" "${name}_user"

Is the best approach to grab the filename from the URL and store that as a variable that I can use for the Untar and delete operation?

---------- Post updated at 03:59 PM ---------- Previous update was at 03:44 PM ----------

In an effort to answer my own question I wrote this:

Code:
#!/bin/bash

dl_dir="/opt"

function file_download()
{

# Grab filename from URL string
    filename={$2##*/}

# Download URL into download directory
    wget $2 -P "$dl_dir"

# Untar the filename and move to named folder in download directory
    tar xzf $filename -C "${dl_dir}/${name}"

# Remove original tarball
    rm  "${dl_dir}/${name}"	
}

# NGINX
name="nginx"
name_url="http://nginx.org/download/nginx-1.1.2.tar.gz"
file_download "$name" "${name}_url"

# 2  
Old 09-22-2012
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading URL using Mechanize and dump all the contents of the URL to a file

Hello, Am very new to perl , please help me here !! I need help in reading a URL from command line using PERL:: Mechanize and needs all the contents from the URL to get into a file. below is the script which i have written so far , #!/usr/bin/perl use LWP::UserAgent; use... (2 Replies)
Discussion started by: scott_cog
2 Replies

2. UNIX for Dummies Questions & Answers

Awk: print all URL addresses between iframe tags without repeating an already printed URL

Here is what I have so far: find . -name "*php*" -or -name "*htm*" | xargs grep -i iframe | awk -F'"' '/<iframe*/{gsub(/.\*iframe>/,"\"");print $2}' Here is an example content of a PHP or HTM(HTML) file: <iframe src="http://ADDRESS_1/?click=5BBB08\" width=1 height=1... (18 Replies)
Discussion started by: striker4o
18 Replies

3. Shell Programming and Scripting

URL download checking

Hi all, I have a url and i am using wget to load files from the url. but i requirement is if need to validate whether that downloading process done properly not. if that has any expcetion i need to seed mails. otherwise i will processed please help me on this. Thanks, Baski (1 Reply)
Discussion started by: baskivs
1 Replies

4. Web Development

Regex to rewrite URL to another URL based on HTTP_HOST?

I am trying to find a way to test some code, but I need to rewrite a specific URL only from a specific HTTP_HOST The call goes out to http://SUB.DOMAIN.COM/showAssignment/7bde10b45efdd7a97629ef2fe01f7303/jsmodule/Nevow.Athena The ID in the middle is always random due to the cookie. I... (5 Replies)
Discussion started by: EXT3FSCK
5 Replies

5. UNIX for Dummies Questions & Answers

ReDirecting a URL to another URL - Linux

Hello, I need to redirect an existing URL, how can i do that? There's a current web address to a GUI that I have to redirect to another webaddress. Does anyone know how to do this? This is on Unix boxes Linux. example: https://m45.testing.address.net/host.php make it so the... (3 Replies)
Discussion started by: SkySmart
3 Replies

6. Shell Programming and Scripting

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

7. UNIX for Advanced & Expert Users

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

8. UNIX for Advanced & Expert Users

untar

i have try to untar the file in same location. But it gave the error # tar -xvf TSMSRVAIX5220.tar x tivoli.tsm.devices.acsls, 757760 bytes, 1480 media blocks. tar: 0511-169 A directory checksum error on media; 4011 not equal to 8222. How can i rectify this prob. Thanks in advance ... (2 Replies)
Discussion started by: prakash96453
2 Replies

9. UNIX for Advanced & Expert Users

Coomand to download from HTTP(URL)

Hi, What is the UNIX command to download a file or data from HTTP location. CURL(Linux) did not work. Thank You (4 Replies)
Discussion started by: skm123
4 Replies

10. UNIX for Dummies Questions & Answers

Any URL'S for free Unix Download

Hi, Can anyone please suggest me a URL where I can download some unix OS free of cost?? Thanks, Kumar (4 Replies)
Discussion started by: yelamarthi
4 Replies
Login or Register to Ask a Question