LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   New to Linux, need to write a loop script, but do not know where to start... (https://www.linuxquestions.org/questions/linux-newbie-8/new-to-linux-need-to-write-a-loop-script-but-do-not-know-where-to-start-4175611785/)

Atmaworm 08-11-2017 03:40 PM

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" https://10.0.0.2/cgi-bin/login

curl -b cookies -k -d "clear_topology=" https://10.0.0.2/cgi-bin/ajax/configuration/management


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.

Turbocapitalist 08-12-2017 09:24 AM

Welcome.

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.

Code:

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.

allend 08-12-2017 09:39 AM

Welcome to LQ!

Create a file ip.txt containing the IP addresses. e.g.
Quote:

10.0.0.2
10.0.0.3
10.0.0.4
Create a file ip.sc containing a shell script
Code:

#!/bin/bash

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 ./ip.sc' or do 'chmod +x ip.sc' then './ip.sc'

AwesomeMachine 08-13-2017 07:38 AM

You can also increment the variable: https://askubuntu.com/questions/3855...riable-in-bash

Atmaworm 08-14-2017 08:53 AM

Awesome! Thank you all. I will try read over and try these out to see if it yields what I am hoping for.


All times are GMT -5. The time now is 11:04 AM.