Author Topic: [SOLVED] Creating a script  (Read 1214 times)

0 Members and 1 Guest are viewing this topic.

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 1616
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards
Re: [SOLVED] Creating a script
« Reply #15 on: November 19, 2013, 03:54:35 pm »
Bit more info on how I want to do it;
download the file
unpack it
rename it
move it
delete the archive

There is only ONE file in the archive.

Kubuntu 12.04LTS 64bit|KDE 4.13.2|QT 4.8.6|Linux 3.2.0-61-generic|M3A76-CM|BIOS 2101|AMD PhenomII X4 965 3400+|Realtek RTL8168C(P)|8111C(P) PCI-E Gigabit Ethernet NIC|NVIDIA 128MB GeForce6200 Turbocache|8.0GB Single-Channel DDR2|

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 1616
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards
Re: [SOLVED] Creating a script
« Reply #16 on: November 19, 2013, 04:11:36 pm »
I don't understand the use of -f

Code: [Select]
tar -xf $i -C $HOME/.config/transmission/blocklists

Kubuntu 12.04LTS 64bit|KDE 4.13.2|QT 4.8.6|Linux 3.2.0-61-generic|M3A76-CM|BIOS 2101|AMD PhenomII X4 965 3400+|Realtek RTL8168C(P)|8111C(P) PCI-E Gigabit Ethernet NIC|NVIDIA 128MB GeForce6200 Turbocache|8.0GB Single-Channel DDR2|

Offline SeZo

  • Hero Member
  • *****
  • Posts: 1428
  • Karma: 118
  • Gender: Male
    • View Profile
    • Awards
Re: [SOLVED] Creating a script
« Reply #17 on: November 20, 2013, 12:44:48 am »
Do not attempt to do it all in one go as debugging could be a nightmare.
Break it down to smaller (more manageable) chunks.

My approach would be to download all the files first..

Code: [Select]
#!/bin/bash

#-P = Directory where all files will be saved to
#-w = Wait the specified number of seconds between the retrievals.
#-i = Read URLs from input file

#set variables
Wget_dir="$HOME/tmp/tar/blocklist"
Untar_dir="$HOME/.config/transmission/blocklists"
export FILE_NUMBER=0
 
mkdir $Wget_dir
#mkdir $Untar_dir

wget --trust-server-names -P $Wget_dir -w 3 -i ~/Peer_Blocklist.txt

#Then loop trough the downloaded files

for file in $Wget_dir/*
do
   ((FILE_NUMBER++))
   echo "$file"
   echo $FILE_NUMBER
   #tar -xzvf "$file" -C $Untar_dir
    STEM=$(basename "${file}" .gz)
    gunzip -c "${file}" > $Untar_dir/"${STEM}"-$FILE_NUMBER.txt
done
Once you are happy that it works you could delete the unneeded folders.

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 1616
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards
Re: [SOLVED] Creating a script
« Reply #18 on: November 20, 2013, 05:31:23 pm »
Just going to hide away for a couple of days while I try to understand the commands  ;)

Kubuntu 12.04LTS 64bit|KDE 4.13.2|QT 4.8.6|Linux 3.2.0-61-generic|M3A76-CM|BIOS 2101|AMD PhenomII X4 965 3400+|Realtek RTL8168C(P)|8111C(P) PCI-E Gigabit Ethernet NIC|NVIDIA 128MB GeForce6200 Turbocache|8.0GB Single-Channel DDR2|

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 1616
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards
Re: [SOLVED] Creating a script
« Reply #19 on: November 20, 2013, 10:05:22 pm »
SeZo, I don't get putting '~/Peer_Blocklist.txt'. I might not understand it properly but it looks to me like it's getting the archive and saving it under the name 'Peer_Blocklist.txt'

Code: [Select]
wget --trust-server-names -P $Wget_dir -w 3 -i ~/Peer_Blocklist.txt

I've looked at the commands with 'man' but still can't figure it!

Kubuntu 12.04LTS 64bit|KDE 4.13.2|QT 4.8.6|Linux 3.2.0-61-generic|M3A76-CM|BIOS 2101|AMD PhenomII X4 965 3400+|Realtek RTL8168C(P)|8111C(P) PCI-E Gigabit Ethernet NIC|NVIDIA 128MB GeForce6200 Turbocache|8.0GB Single-Channel DDR2|

Offline SeZo

  • Hero Member
  • *****
  • Posts: 1428
  • Karma: 118
  • Gender: Male
    • View Profile
    • Awards
Re: [SOLVED] Creating a script
« Reply #20 on: November 20, 2013, 10:38:31 pm »
Quote
I've looked at the commands with 'man' but still can't figure it!

Wget is capable of downloading multiple files at once.

Supplied arguments are:

You can tell wget to use the name from the redirected URL instead of http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz by passing the --trust-server-names option.

-P = Directory where all files will be saved to
Code: [Select]
-P $HOME/tmp/tar/blocklist
This would download all files into ~/tmp/tar/blocklist directory

-w = Wait the specified number of seconds between the retrievals
Code: [Select]
-w 3
Self explanatory

-i = Read URLs from input file
If you got a file with a list of URLs to fetch, then you can simply supply wget with an input file that contains a list of URLs.
Code: [Select]
wget -i ~/Peer_Blocklist.txt 
Where Peer_Blocklist.txt is the file that contains a list of URLs.

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 1616
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards
Re: [SOLVED] Creating a script
« Reply #21 on: November 20, 2013, 11:16:18 pm »
-i = Read URLs from input file
If you got a file with a list of URLs to fetch, then you can simply supply wget with an input file that contains a list of URLs.
Code: [Select]
wget -i ~/Peer_Blocklist.txt 
Where Peer_Blocklist.txt is the file that contains a list of URLs.

Sorry, I completely forgot that the file with the URL's was named Peer_Blocklist.txt

Kubuntu 12.04LTS 64bit|KDE 4.13.2|QT 4.8.6|Linux 3.2.0-61-generic|M3A76-CM|BIOS 2101|AMD PhenomII X4 965 3400+|Realtek RTL8168C(P)|8111C(P) PCI-E Gigabit Ethernet NIC|NVIDIA 128MB GeForce6200 Turbocache|8.0GB Single-Channel DDR2|

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal