Run shell 'ping' with tasker

6,276 views
Skip to first unread message

Nikhil Wanpal

unread,
Feb 7, 2013, 9:16:49 PM2/7/13
to tas...@googlegroups.com

Hi all,
I am trying to ping my computer over wifi to check if it is available. I know it's a much discussed use case n the answer is to use secure settings to ping. I am able to do that.

But Tasker is able to execute other commands like 'ls'.
Is ping handled differently? Is it must to keep secure settings installed (I do not need it otherwise) n use it or am I doing something wrong?
Command: ping -c 1 192.168.0.202

Dan

unread,
Feb 8, 2013, 4:58:48 AM2/8/13
to tas...@googlegroups.com
ping works fine in tasker shell. 
the main difference to Secure Settings IMHO is that shell only gives you less possibilities for error handling. and since you want to check on availability it is a good idea to have the non-reachable-by-ping case covered well.
a possibility would be to write a shell script containing ping and error handling and run that from the tasker shell.

GermainZ

unread,
Feb 8, 2013, 1:16:49 PM2/8/13
to tas...@googlegroups.com
Here's a snippet from a script I use:

if [ `ping 192.168.x.x -c 1 | grep received | awk '{print($4)}'` = 1 ]
then
echo pc detected
else
echo pc not found
fi

NikhilW

unread,
Feb 11, 2013, 4:41:33 AM2/11/13
to tas...@googlegroups.com
Thanks both for your reply.

@GermainZ
Thanks for the script, it helped a lot in figuring out the issue. I could execute it on my Ubuntu machine, but in tasker, it kept on showing 'pc not found'.
on echoing the if condition's output, I found I don't have 'awk'. So I changed it to:
V=( `ping 192.168.0.202 -c 1 | grep received` ); if [ ${V[3]} = 1 ]; then echo Y; else echo N; fi
Then, turns out I don't have 'grep' as well!

I am not rooted and using a stock S2 ROM. (No BusyBox)
I think I'll see if I can find a ping compiled for android that I can execute from the sdcard, may be by passing the complete path.

Also, every time, I try to ping and it fails to find the machine, there is some log shown when I start Tasker next time. I need the log enabled, I cant avoid this error getting into that log, can I?

Thank you your help. :) 

Matt R

unread,
Feb 11, 2013, 3:23:53 PM2/11/13
to tas...@googlegroups.com
Presumably, the error is because the command fails, so the script aborts with an error code.  If you can get it working, you won't see an error the next time you start Tasker anymore.
 
Matt

NikhilW

unread,
Feb 23, 2013, 1:06:07 AM2/23/13
to tas...@googlegroups.com
Ohh.. Ok.. Thanks.. :)

BTW, I am unable to find a solution to include these commands in the android shell without installing busybox. So for now, I have to stick with Secure Settings.
Thank you all for your help.. :)

Wietse van Buitenen

unread,
Feb 23, 2013, 4:38:33 AM2/23/13
to tas...@googlegroups.com
I am using ping to check if devices are on..

Run Shell: ping -c 3 192.168.1.1
Store Output In: %stdout
Continue Task After Error: checked

If %stdout ~ *100% packet loss*
   device is off
Else
  device is on
End If

ping with Run Shell seems to give an error when there's 100% packet loss, that's why Continue Task After Error needs to be checked

some commands with Run Shell need some fiddling to find a way to make it work :)

NikhilW

unread,
Feb 24, 2013, 4:15:00 AM2/24/13
to tas...@googlegroups.com
Wow..! This fixes it! Superb! :)
Does not require any additional commands (like awk/grep) and also does not show any log on next Tasker launch if the machine is not found.

Thank you.. :)

Jorge E. Vargas

unread,
Aug 15, 2013, 11:05:38 PM8/15/13
to tas...@googlegroups.com
From the depths of my cold, exhausted heart..THANK YOU for this, Wietse!

Eddy Chong

unread,
Oct 11, 2013, 12:44:48 PM10/11/13
to tas...@googlegroups.com
Thanks Wietse, your answer is so helpful!

Eddy
Message has been deleted

Simon Bové-Christensen

unread,
Nov 4, 2016, 7:26:31 PM11/4/16
to Tasker
Thank you.. Just what I needed 😊👍

M@xF@ctor

unread,
Jan 26, 2018, 11:40:34 AM1/26/18
to Tasker
I use

Run Shell: ping -c 1 -q -w 8.8.8.8
  Continue Task After Error: checked

If %result ~ 0
   Internet Access is OK
Else
  Internet Access not available
End If

Reply all
Reply to author
Forward
0 new messages