Tuesday, December 7, 2010

How To Get A Unicorn Horn In Poptropica

3 Shell Scripts for Linux DIY

Sometimes it takes a microprogram to do something simple but repetitive, or you can not find a program that meets a very specific role. For these cases, a shell script in GNU / Linux can be a good choice. I have 3 tiny scripts that use both terms, and I'll explain in case anyone may be helpful.

-consecutive massive file download
For example photos of a website. A very simple script that simply download the images in the directory from which it runs. The main use is that it automatically "up" counter.

# / bin / sh # #
initialize a counter variable to 1
i = 1
# # loop for items
001 to 009 while [$ i-le 9]
do
# # use wget to download itself
/ usr / bin / wget http://www.ejemplo.com / directorio/fichero00 "$ i"
i = `expr $ i + 1` done


# # loop for items
010 to 099 while [$ i-le 99] do

/ usr / bin / wget http : / / www.ejemplo.com/directorio/fichero0 "$ i"
i = `expr $ i + 1` done


# # repeat if needed for elements 100 to 999

Beware massive downloads file, there are websites that you cut the connection if you do.

- Download images from a webcam
This follows the script and used to obtain images station Cebreros deep space. The script first connects to the webcam every 30 seconds, and download a static image (not all webcams allow this), saving it with a name straight. For the name is unique, use the unix time added to the suffix that you indicate. This caused a curious problem solved with the third script ...

# / bin / sh # #
initialize a counter variable to 1
i = 1
# # main loop, adjust as needed
while [$ i-le 3000] do

# # wget to download the image
http://www.ejemplo.com/imagen-webcam.jpg wget-O file `date +% s`. Jpg
# # timer, adjust to taste, 30 seconds
# # is fine for a stop-motion
sleep 24 hours 30
i = `expr $ i + 1` done

echo "ENDED"


- Renowned massive consecutive files
Once downloaded images Webcam I noticed a curious problem: unix date has this format: 1291756602. So I found with 3000 files, well sorted, but with strange names rare. The solution was the following script, using the ls command and head first file gets the total of which may be renamed in a row. The destination name must be alphabetical behind the files to rename, or not work.

# / bin / sh # #
initialize a counter variable to 1
i = 1
# # The counter should match the total
file while [$ i-le 3000] do

# # with mv do the rename, and nested ls and head
# # to get the file name to rename clean
mv `ls


0 comments:

Post a Comment