Entries tagged bash

Simple wget crawler for list of files

Posted on 6. August 2015 Comments

This script could be helpful to download a set of files from a webserver, that you don’t have (S)FTP access to. The input file consists of a list of filenames, one name each line.


#!/bin/bash
file=$1
WEBSERVER="http://webserver.tld/folder/"
while IFS= read -r line; do
FULLURL="$WEBSERVER$line"
wget -nc -R --spider $FULLURL
done < "$file"

At first, the first command line argument is saved into the variable file. Then the Webserver address is saved to the WEBSERVER variable. IFS stands for Internal Field Separator. It’s used to read line by line through the file in the while loop that ends in the last line. Inside of the loop, the read line is concatenated with the webserver address into FULLURL. Then, wget is used with the parameters -nc for checking if the file is not already present in the current folder, -R for downloading and –spider for checking the existence on the webserver.

You can find the script on GitHub.

MAC-Adresse per Skript aus ifconfig

Posted on 9. Februar 2012 Comments

Soweit ich weiß, gibt es unter Linux keinen Befehl oder eine Datei in der die MAC-Adresse steht, nur ifconfig. Für die weitere Verwendung ist das natürlich unpraktisch und so habe ich hier eben ein bisschen was mit grep und regular expressions zusammengeskriptet/kopiert:

#!/bin/bash
ifconfig |grep $1 | grep -m 1 -Eo '[[:alnum:]][[:alnum:]](:[[:alnum:]][[:alnum:]]){5}'

Das am besten unter der Datei grepMacAdr speichern, noch schnell mit

chhmod +x  grepMacAdr

ausführtbar machen, dann erfolgt der Aufruf mit

./grepMacAdr eth0

eth0 ist hier das Netzwerkgerät. Wenn das bekannt ist kann auch direkt im Skript $1(=erster Parameter) durch die entsprechende Bezeichnung geändert werden.

Zur Erklärung: ifconfig ruft den Befehl auf, der alle Netzwerkgeräte samt Konfiguration ausgibt, von denen schneidet das Tool grep nur den Abschnitt heraus, der das übergebene Netzwerkgerät behandelt(bzw. die erste Zeile, da steht die MAC-Adresse im allgemeinen) und davon wiederrum wird mit einer Regular Expression(-E) dann nach dem Muster XX:XX:XX:XX:XX gesucht. Falls, was mit dem ersten grep falsch gelaufen ist, wird nur das erste ausgeben(-m 1). Ausgegeben wird dabei nur der Teil, der das Muster einhält, nicht die ganze Zeile(-o)

Ihr findet das Skript auch als fertige Datei hier.