LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   red hat script with curl (https://www.linuxquestions.org/questions/linux-newbie-8/red-hat-script-with-curl-4175624323/)

biggizod 02-23-2018 12:50 PM

red hat script with curl
 
hi guys , i am trying to create script with curl command:
curl -v "http://x.x.x.x......"
sleep 5

about 300 of this commands, it will help me to remotely log off and login cisco phones. How can I run that text file/script?
Is it just : file [file location] ?
should i make it exe ? please share steps
thank you

RandomTroll 02-23-2018 12:55 PM

Code:

#! /bin/bash
curl -v "..."
sleep 5

You don't have to give it any special name.

You need to make it executable with:
Code:

chmod +x myscript
and specify the path, for instance $HOME/bin/myscript, if that's where it is, or put it in the path.

You can discover the path with:
Code:

echo $PATH

rtmistler 02-23-2018 01:00 PM

Yes you should put your commands into a file and make that file executable. You can run that file, providing you are in the directory where it is located, or if it resides in a directory which is in your $PATH variable.

There is also some syntax relevant to bash scripts which you need to be aware of.

Recommend you use The Bash Beginners Guide as a general guide to learning bash scripting.

A first script example is shown in Section 1.5.5: An example Bash script: mysystem.sh and this should show you a great example in line with what you're doing here and help you with the syntax I'm referring to.

biggizod 02-23-2018 01:56 PM

Thank you guys. Is there a way to get logs, output results ?

rtmistler 02-23-2018 02:09 PM

Quote:

Originally Posted by biggizod (Post 5823325)
Thank you guys. Is there a way to get logs, output results ?

Hi,

Back to the reference Appendix A: Shell Features where you'll find the input/output redirectors. There are examples throughout that document if you search for redirect. It is a matter of choosing between ">" for redirect to file (new), or ">>" redirect to file (append)

RandomTroll 02-24-2018 12:20 AM

Quote:

Originally Posted by rtmistler (Post 5823297)
Y You can run that file, providing you are in the directory where it is located,

Unlike MS-DOS the current directory is not in the path in Linux. You can put . in the path, but it isn't by default. A Unix instructor told me it was a bad idea. I can't recall the reason; I'll try to.


All times are GMT -5. The time now is 12:43 PM.