Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-25-2013, 01:45 AM
|
#1
|
LQ Newbie
Registered: Apr 2013
Posts: 4
Rep: 
|
Bash ping script
Hello,
execuse my english.
I need help with script
I have 5 networks and I need ping script with menu option.
example:
1) network 1 (10.0.0.1) network 1 is only alias
2) network 2
etc.
choose option:
Then choose option
Enter number of ping:
then enter of ping show
ping network% n%
Thanks
|
|
|
04-25-2013, 02:47 AM
|
#2
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
this looks a little bit like a homework question. Please note that although we are happy to help, we won't do your homework for you. Show us what you have tried and tell us where you are having trouble, then we can help point you in the right direction.
If this is not a homework question, why do you want and interactive menu driven program for this? Is there something wrong with using ping directly on the commandline?
Evo2.
|
|
|
04-25-2013, 01:40 PM
|
#3
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
Do you know how to do each of the steps individually?
Do you know how to ping a single host?
Can you check the result of that and perform some action based on the result?
Can you ask for and receive user input, and check that for various values?
(Hint, check out the select loop and case statement.)
Once you have these figured out, you can put them together into a full script.
Good luck!
|
|
|
05-07-2013, 04:00 AM
|
#4
|
LQ Newbie
Registered: Apr 2013
Posts: 4
Original Poster
Rep: 
|
It isn't homework.
I need this script to our Technical Service.
In windows I use this bat.file
Code:
@ECHO OFF
echo ________________________________
echo.
:DOTAZ
echo Volba 1) Rozhrani 10.242.37.xxx
echo Volba 2) Rozhrani 133.120.1.xxx
echo Volba 3) Ukoncit
echo ________________________________
echo.
set choice=
set /p choice=Vyberte volbu:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto IP1
if '%choice%'=='2' goto IP2
if '%choice%'=='3' goto UKONCIT
ECHO Moznost "%choice%" neexistuje! Opakujte volbu.
goto DOTAZ
:IP1
echo.
echo Zadejte koncove cislo IP adresy:
echo ________________________________
echo.
set cislo=
set /p cislo=Zadejte cislo:
if not '%cislo%'=='' set choice=%cislo:~0,1%
if not '%cislo%'=='' goto KONTROLA1
ECHO Moznost "%cislo%" neexistuje! Opakujte volbu.
goto IP1
:KONTROLA1
echo.
PING 10.242.37.%cislo% -n 10
goto end
:IP2
echo.
echo Zadejte koncove cislo IP adresy
echo.
set cislo=
set /p cislo=Vyber volbu:
if not '%cislo%'=='' set choice=%cislo:~0,1%
if not '%cislo%'=='' goto KONTROLA2
ECHO Moznost "%cislo%" neexistuje! Opakujte volbu.
goto IP2
:KONTROLA2
echo.
PING 133.120.1.%cislo% -n 10
goto end
:UKONCIT
echo.
echo Konec davky
goto end
:end
And I don't know shell commands
Can you help me?
|
|
|
05-07-2013, 09:36 AM
|
#5
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,584
|
Quote:
Originally Posted by SirTonic
It isn't homework.
I need this script to our Technical Service. In windows I use this bat.file
And I don't know shell commands Can you help me?
|
Yes, we can help you, but you do need to show some effort of your own. There are MANY easily found bash scripting tutorials you can find, and the shell command to ping is (obviously enough), called "ping". Also, there are many already written scripts to do exactly what you're after, and Google can show them to you, like this one:
http://www.thelinuxtips.com/2012/06/...ultiple-hosts/
|
|
|
05-09-2013, 12:30 AM
|
#6
|
LQ Newbie
Registered: Apr 2013
Posts: 4
Original Poster
Rep: 
|
I understand
Quote:
Originally Posted by TB0ne
Yes, we can help you, but you do need to show some effort of your own. There are MANY easily found bash scripting tutorials you can find, and the shell command to ping is (obviously enough), called "ping". Also, there are many already written scripts to do exactly what you're after, and Google can show them to you, like this one:
http://www.thelinuxtips.com/2012/06/...ultiple-hosts/
|
I understand you,
ad1) but I don't want multiple host in txt file. I need choose some subnet and choose last oktet IP host and number of pings
ad2) It doesn't solve the menu, where I choose subnet and last oktet from host IP
So and only convert my .bat file to bash script
In my bat file is easy to view what I want
so where is the problem?
You think I'm on the net looking for a solution? I do not need to learn the lengthy script. The only thing I need to convert my bat file to a shell script, or on the basis of my bat file to create a shell script.
Try to understand me
|
|
|
05-09-2013, 01:18 AM
|
#7
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
LQ is about spreading knowledge. If you are not interested in learning and just want someone to simply provide a ready made solution, you're not likely to find much help here. That sort of help usually comes in the form of paid contractors/consultants.
Evo2.
|
|
1 members found this post helpful.
|
05-09-2013, 02:49 AM
|
#8
|
Moderator
Registered: May 2001
Posts: 29,415
|
Or phrased differently: only people who want to learn can be taught.
@OP: using a menu option means using "select" ('man bash'):
Code:
LIST="item0 item1 item2"
select ITEM in $LIST; do
case $ITEM in
item*) echo $ITEM;;
*) echo hell no;;
esac
done
|
|
1 members found this post helpful.
|
05-10-2013, 10:05 AM
|
#9
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,584
|
Quote:
Originally Posted by SirTonic
I understand you,
ad1) but I don't want multiple host in txt file. I need choose some subnet and choose last oktet IP host and number of pings
ad2) It doesn't solve the menu, where I choose subnet and last oktet from host IP
So and only convert my .bat file to bash script
In my bat file is easy to view what I want so where is the problem?
You think I'm on the net looking for a solution? I do not need to learn the lengthy script. The only thing I need to convert my bat file to a shell script, or on the basis of my bat file to create a shell script.
Try to understand me
|
We do understand you: you want someone to write a script for you, and you don't want to be bothered learning anything. Thanks, but no. If you don't want to put any effort into doing work that you're getting PAID to do, why should we do your work for you, FOR FREE???.
You've been pointed to resources to help you solve your problem, and have folks willing to HELP you...this means putting some effort in of your OWN, rather than being lazy and somewhat rude, and expecting others to do your work for you. Again, show some effort, post what you've written/tried, and we will be happy to help.
|
|
|
05-20-2013, 08:14 AM
|
#10
|
LQ Newbie
Registered: Apr 2013
Posts: 4
Original Poster
Rep: 
|
For your information:
ad 1) This work is not paid, it is a personal initiative
ad 2) The fact that I can not write script in Linux is only one.
I can not learn scripting, in this time.
I just need advice or or rewrite my bat file into a shell script
Thats all.
|
|
|
05-20-2013, 09:05 AM
|
#11
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,584
|
Quote:
Originally Posted by SirTonic
For your information:
ad 1) This work is not paid, it is a personal initiative
ad 2) The fact that I can not write script in Linux is only one. I can not learn scripting, in this time.
I just need advice or or rewrite my bat file into a shell script
Thats all.
|
It's been about a month since you first posted...MORE than enough time for you to have looked at the sample script you were provided, and look at one of the THOUSANDS of bash-scripting tutorials, and made it work. Since it's your 'personal initiative', you should be WANTING to learn, rather than asking someone to do it for you.
You WERE given advice, a sample script, and there are even links on LQ (and in my posting signature), to bash scripting tutorials. You've not done any of it, and AGAIN, we are not going to write your script FOR YOU. You will NEVER be able to write a script if you don't actually TRY TO DO IT.
Either look at the sample and scripting tutorials and put some effort into it (which WILL get you lots of help), or get someone else to write your script for you.
Last edited by TB0ne; 05-20-2013 at 02:58 PM.
|
|
|
05-20-2013, 02:47 PM
|
#12
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
Quote:
Originally Posted by SirTonic
For your information:
ad 1) This work is not paid, it is a personal initiative
ad 2) The fact that I can not write script in Linux is only one.
I can not learn scripting, in this time.
I just need advice or or rewrite my bat file into a shell script
Thats all.
|
Fries with that?
Go!
|
|
1 members found this post helpful.
|
05-20-2013, 02:54 PM
|
#13
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
You can always hire someone to do something like this for you. You are unlikely to find someone that is going to take the time to do it for you for free.
https://www.elance.com/
Or google: Programmers for hire
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 11:02 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|