Sponsored Content
Full Discussion: Download and Untar any URL
Top Forums Shell Programming and Scripting Download and Untar any URL Post 302704657 by Spadez on Saturday 22nd of September 2012 04:59:35 PM
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"

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
BF_TAR(1)						    Bogofilter Reference Manual 						 BF_TAR(1)

NAME
bf_tar - shell script to write a tar file of a bogofilter directory to stdout SYNOPSIS
bf_tar [-r] [-R] bogofilter_directory DESCRIPTION
bf_tar bundles a bogofilter working directory in tar format and copies it to standard output (your console, or where you redirect it, see EXAMPLES below). OPTIONS
The -r option causes bf_tar to remove inactive log files after the archive has been written successfully. The default is to leave log files. The -R option causes bf_tar to remove inactive log files before the archive is written. This may reduce chances that the resulting archive is recoverable should it become damaged. The archive may be smaller though. The default is to leave log files. EXIT STATUS
The script exits with status code 0 if everything went well, and nonzero if it encountered trouble. EXAMPLES
o bf_tar ~/.bogofilter > outfile.tar Writes a standard .tar file containing the essential files from ~/.bogofilter to outfile.tar. o bf_tar ~/.bogofilter | gzip -9 -c > outfile.tar.gz Writes a gzipped .tar.gz file containing the essential files from ~/.bogofilter to outfile.tar.gz. o bf_tar `pwd`/mydirectory > outfile.tar Prepend $(pwd)/ or `pwd`/ if you want to specify an absolute path instead of a relative path. NOTES
This script is meant for use with Berkeley DB based bogofilter versions. This script requires a SUSv2 compliant pax utility. This script expects a SUSv2 compliant shell. Solaris systems should have the SUNWxcu4 package installed (when bogofilter is configured) so that /usr/xpg4/bin/sh can be used. AUTHORS
Matthias Andree Bogofilter 10/22/2012 BF_TAR(1)
All times are GMT -4. The time now is 11:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy