X
    Categories: Linux

Doing a for loop in batch script

Let’s see you want to download a series of file from somewhere.
Which is having sequential filename.

This can be easily done with a shell script.
such as below:

for i in {1..113}
do
echo $i
done

while am at it, why not make a PDF file out of the images file.
this may require ImageMagick to be installed first.

yum install ImageMagick -y

So, the final script would be something like..


#!/bin/bash

  mkdir z
  cd z  
  for i in {1..113}
    do          
      # go get the image.
      /usr/bin/wget https://dev.namran.com/ss/IMAGE-$i.jpg -O $i.jpg
    done        
  # make pdf from jpg list
  convert `ls -1v` ../1st-session.pdf
  mv ../1st-session.pdf ~/public_html/download/


Done.

Namran Hussin: a soft spoken guy... with exceptional interest in computers and technology. I love to learn new thing and also love to break thing for the sake of learning.. but I do abide to the self-imposed limitation or certain thing such as social thing in life, thing can be done and thing that must be avoided at whatever cost such as drug,illegal tracking, smoke,illicit activity..etc.muahahaha let's share what we had in this short term of the life.! make it worth of the living.~
Related Post
Leave a Comment