Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-11-2017, 03:40 PM   #1
LQ Newbie
Registered: Aug 2017
Posts: 2

Rep: Reputation: Disabled
New to Linux, need to write a loop script, but do not know where to start...

Hello all, As stated I have little experience with Linux. I am trying to write a loop script with the information below to run on one of our Teradici servers to clear out the management state for our zero clients. Teradici provided us with a command that could be run that will clear out a devices from the server one at a time.

curl -c cookies -k -d "password_value=<password>" -d "idle_timeout=0"

curl -b cookies -k -d "clear_topology="

I am looking for a way to automate this that will continuously change the value (IP Address) until it gets through the ranges needed. I can modify it per VLAN, I just need to know how to write the script to change the IP value in the 4th octet. I hope I am explain this correctly also, because I do not know anything about Linux and just going by what Teradici said I needed to do.

Any help I can get will be greatly appreciated. Because if I cannot get this working, I will have to manually remote into 2000 zero clients and reset their management states.
Old 08-12-2017, 09:24 AM   #2
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,000
Blog Entries: 3

Rep: Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632

It's not unique to GNU/Linux, any non-Windows system will be about the same: you can store the IP numbers in a file, one per line, then read that file with your shell script using a while loop so that the IP numbers end up in a variable which then gets used when you call curl.

The details will be buried in the manual page for bash, or whichever shell you will be using.

man bash
The manual page will be overwhelming at first, there's no way around that, but it's the authoritative reference for shell scripting with bash. So it is very useful to get used to using it to look up things, such as the while loop.

Last edited by Turbocapitalist; 08-12-2017 at 09:25 AM.
Old 08-12-2017, 09:39 AM   #3
LQ 5k Club
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,213

Rep: Reputation: 2679Reputation: 2679Reputation: 2679Reputation: 2679Reputation: 2679Reputation: 2679Reputation: 2679Reputation: 2679Reputation: 2679Reputation: 2679Reputation: 2679
Welcome to LQ!

Create a file ip.txt containing the IP addresses. e.g.
Create a file containing a shell script

while read ip; do
  curl -c cookies -k -d "password_value=<password>" -d "idle_timeout=0" https://$ip/cgi-bin/login
  curl -b cookies -k -d "clear_topology=" https://$ip/cgi-bin/ajax/configuration/management
done < ip.txt
Run the script from a terminal using the command 'sh ./' or do 'chmod +x' then './'

Last edited by allend; 08-12-2017 at 09:45 AM.
Old 08-13-2017, 07:38 AM   #4
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
You can also increment the variable:
Old 08-14-2017, 08:53 AM   #5
LQ Newbie
Registered: Aug 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Awesome! Thank you all. I will try read over and try these out to see if it yields what I am hoping for.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to write script to start daemon BW-userx Slackware 5 10-13-2016 07:01 AM
[SOLVED] Is this the write way to write a 2 command loop script? Bobbyyyy Linux - Newbie 1 04-14-2014 02:03 PM
Make a bash script loop from start evansd321 Linux - Newbie 5 08-29-2008 11:37 AM
write a script to start a yenonn Linux - Newbie 6 05-26-2003 05:14 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:23 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration