Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacNewbie03

macrumors regular
Original poster
I am trying to write a bash script that does the following:
Code:
#!/bin/bash
ping -c 4 192.168.2.27
ping -c 4 192.168.2.1
ping -c 4 72.11.28.215
ping -c 4 72.11.28.129
ping -c 4 72.11.31.21
ping -c 4 72.11.0.21
sleep 5s
exit
I want to be able to double click it from my home folder and then it runs and then quits Terminal. How do I go about this? The above code is what I used on my Ubuntu box and I was able to get it to work as I wanted.
 
Put the code in a text file and named it something like script.sh. Then, from Terminal change the permissions to add the execute attribute for yourself. I believe it'll work to double click on it after that. It's been a while since I've done it, but know it's possible.
 
Code:
chmod 775 PingTest.sh

To run the script, in Terminal type:
Code:
./PingTest.sh

Make sure you are in the directory where the file is located! You could even make an alias in your .profile file so that you can run it no matter what, or put it in sbin.
 
I think if you give the file a .command extension it will execute when you double-click it. e.g., pingTest.command. (Hopefully I am remembering the extension correctly.)
 
You can do the whole thing in Automator I believe, and save it as a doubleclickable application. It has a "execute shell script" action, and a quit application action.
 
Because I have other stuff to do. :D The only time I use this script is to test for Internet connectivity

How do I go about using Automator? I tried to use it and nothing happened. It acted like something was going on but I didn't see anything.

Within Automator there's a work flow option for command line stuff. I'm not at my Mac to get the specific name, but once you add that you can add your bash script and save the work flow as a .app.
 
Sorry for asking so many questions but how do I get Automator to show me that the script is running? When I run the script from Terminal myself I get something like this
Code:
PING 192.168.2.27 (192.168.2.27): 56 data bytes
64 bytes from 192.168.2.27: icmp_seq=0 ttl=64 time=0.047 ms
64 bytes from 192.168.2.27: icmp_seq=1 ttl=64 time=0.058 ms
64 bytes from 192.168.2.27: icmp_seq=2 ttl=64 time=0.057 ms
64 bytes from 192.168.2.27: icmp_seq=3 ttl=64 time=0.056 ms

--- 192.168.2.27 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.047/0.054/0.058/0.004 ms
PING 192.168.2.1 (192.168.2.1): 56 data bytes
64 bytes from 192.168.2.1: icmp_seq=0 ttl=64 time=3.103 ms
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=2.885 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=3.063 ms
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=3.232 ms

--- 192.168.2.1 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 2.885/3.071/3.232/0.124 ms
PING 72.11.28.215 (72.11.28.215): 56 data bytes
64 bytes from 72.11.28.215: icmp_seq=0 ttl=64 time=2.954 ms
64 bytes from 72.11.28.215: icmp_seq=1 ttl=64 time=3.046 ms
64 bytes from 72.11.28.215: icmp_seq=2 ttl=64 time=3.137 ms
64 bytes from 72.11.28.215: icmp_seq=3 ttl=64 time=3.077 ms

--- 72.11.28.215 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 2.954/3.054/3.137/0.066 ms
PING 72.11.28.129 (72.11.28.129): 56 data bytes
64 bytes from 72.11.28.129: icmp_seq=0 ttl=254 time=82.527 ms
64 bytes from 72.11.28.129: icmp_seq=1 ttl=254 time=57.910 ms
64 bytes from 72.11.28.129: icmp_seq=2 ttl=254 time=79.953 ms
64 bytes from 72.11.28.129: icmp_seq=3 ttl=254 time=98.633 ms

--- 72.11.28.129 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 57.910/79.756/98.633/14.503 ms
PING 72.11.31.21 (72.11.31.21): 56 data bytes
64 bytes from 72.11.31.21: icmp_seq=0 ttl=61 time=108.897 ms
64 bytes from 72.11.31.21: icmp_seq=1 ttl=61 time=11.599 ms
64 bytes from 72.11.31.21: icmp_seq=2 ttl=61 time=20.390 ms
64 bytes from 72.11.31.21: icmp_seq=3 ttl=61 time=88.204 ms

--- 72.11.31.21 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 11.599/57.273/108.897/42.036 ms
PING 72.11.0.21 (72.11.0.21): 56 data bytes
64 bytes from 72.11.0.21: icmp_seq=0 ttl=60 time=74.475 ms
64 bytes from 72.11.0.21: icmp_seq=1 ttl=60 time=80.896 ms
64 bytes from 72.11.0.21: icmp_seq=2 ttl=60 time=81.626 ms
64 bytes from 72.11.0.21: icmp_seq=3 ttl=60 time=52.231 ms

--- 72.11.0.21 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 52.231/72.307/81.626/11.920 ms
The above is what I want to do with Automator.
 
Automator doesn't seem to have anything great for displaying the results. I wrote up a quick AppleScript instead that display the results in a pop-up.
Code:
display dialog (do shell script "
ping -c 1 -q 192.168.2.27
ping -c 1 -q 192.168.2.1
ping -c 1 -q 72.11.28.215
ping -c 1 -q 72.11.28.129
ping -c 1 -q 72.11.31.21;
ping -c 1 -q 72.11.0.21;
")
You can open Script Editor and place it in there. It can be saved as a .app as well. I modified the commands slightly to better ensure the output would fit inside the pop-up.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.