Running sh script error

Quite a Linux and Openwrt rookie, attempting to run this script got here https://davidsimpson.me/2016/02/05/push-speed-test-results-from-openwrt-to-google-sheets/.

I get this error:

': No such file or directory env: can't execute 'bash

Here's the full script:

#!/usr/bin/env bash
###########################################################################
# Originally written by: Henrik Bengtsson, 2014
# https://github.com/HenrikBengtsson/speedtest-cli-extras
# Modified to use IFTTT by: Alasdair Allan, 2015
# License: GPL (>= 2.1) [http://www.gnu.org/licenses/gpl.html]
###########################################################################

# Character for separating values
# (commas are not safe, because some servers return speeds with commas)
sep=";"

# Temporary file holding speedtest-cli output
user=$USER
if test -z $user; then
  user=$USERNAME
fi
log=/$user/tmp/speedtest-csv.log

# Local functions
function str_extract() {
 pattern=$1
 # Extract
 res=`grep "$pattern" $log | sed "s/$pattern//g"`
 # Drop trailing ...
 res=`echo $res | sed 's/[.][.][.]//g'`
 # Trim
 res=`echo $res | sed 's/^ *//g' | sed 's/ *$//g'`
 echo $res
}

# Display header?
if test "$1" = "--header"; then
  start="start"
  stop="stop"
  from="from"
  from_ip="from_ip"
  server="server"
  server_dist="server_dist"
  server_ping="server_ping"
  download="download"
  upload="upload"
  share_url="share_url"
else
  mkdir -p `dirname $log`

  start=`date +"%Y-%m-%d %H:%M:%S"`

  if test -n "$SPEEDTEST_CSV_SKIP" && test -f "$log"; then
    # Reuse existing results (useful for debugging)
    1>&2 echo "** Reusing existing results: $log"
  else
    # Query Speedtest
    /usr/local/bin/speedtest-cli --share > $log
  fi
  
  stop=`date +"%Y-%m-%d %H:%M:%S"`
  
  # Parse
  from=`str_extract "Testing from "`
  from_ip=`echo $from | sed 's/.*(//g' | sed 's/).*//g'`
  from=`echo $from | sed 's/ (.*//g'`
  
  server=`str_extract "Hosted by "`
  server_ping=`echo $server | sed 's/.*: //g'`
  server=`echo $server | sed 's/: .*//g'`
  server_dist=`echo $server | sed 's/.*\\[//g' | sed 's/\\].*//g'`
  server=`echo $server | sed 's/ \\[.*//g'`
  
  download=`str_extract "Download: "`
  upload=`str_extract "Upload: "`
  share_url=`str_extract "Share results: "`
fi

# Standardize units?
if test "$1" = "--standardize"; then
  download=`echo $download | sed 's/Mbits/Mbit/'`
  upload=`echo $upload | sed 's/Mbits/Mbit/'`
fi

# Send to IFTTT
secret_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
value1=`echo $server_ping | cut -d" " -f1`
value2=`echo $download | cut -d" " -f1`
value3=`echo $upload | cut -d" " -f1` 
json="{\"value1\":\"${value1}\",\"value2\":\"${value2}\",\"value3\":\"${value3}\"}"
echo $json
curl -X POST -L -H "Content-Type: application/json" -d "${json}" https://maker.ifttt.com/trigger/speedtest/with/key/${secret_key} -i -v --insecure

bash is not installed by default on OpenWrt. You can use shellcheck (install or on their webside) to determine if it is compliant with sh. If so, you can just change the "shebang" to #!/bin/sh at the start and run it. (Warnings are probably OK from shellcheck, anything that indicates that it is a bash-specific form, or not POSIX-compliant probably need to be fixed.)

bash can also be installed on routers with sufficient flash. It is pretty heavy and, in my opinion, doesn't offer significant advantages for maintaining a router.

1 Like

jeff''s advice is on point,
but if you use /overlay filesystem, all your concerns about space go out the window as irrelevant. For $7 and little trouble during upgrades, I have a 32GB root partition for openWRT. I dont know how you use samba+ nginx + other large softwares on openWRT without it.

I prefer bash+mksh in all cases
over ash, dash, zsh, tcsh, csh and the miniscule stand-ins, because that way all my scripts + .bash_profiles + functions work everywhere across all platforms I mess with. YMMV.

speedtest-cli is Python based, so bash is rather light by comparison.

OOOF! As a heads up, getting more than a minimal Python install onto a 16 MB router can be a challenge, in my experience. I was only able to do it by building my own images. Using extroot or the like to mount a USB stick as the active root filesystem is another approach.

I downloaded both bash and python!

  1. Any better idea than python based speedtest?
  2. How can I check the memory left?
  3. I see my router specs. Where did all that rubbish go? Can I uninstall all that & reclaim space? (installed also SFTP server BTW)