FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14455 questions

17168 answers

28195 comments

0 members

We are migrating to our new platform at https://community.teltonika.lt. Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
706 views 4 comments
by anonymous

Hi,

my question is loop in the shell script:

#!/bin/ash

my_array=$(echo "abc" | grep -o .)

echo $my_array

for i in "${my_array[@]}"

do

  echo "$i"

 done

result is

syntax error: bad substitution

Why?

Thanks 

ps. RUT9XX_R_00.06.08.6

6 Answers

0 votes
by anonymous

A simple awk script looks good enough for a checksum calculation:

echo abcdefg | awk '
BEGIN {
for (i = 0; i <= 255; i++) {
  t = sprintf("%c", i);
  a[t] = i;
}
cks=0;
};
/./ {
print $0;
for(i=0; i<length($0);++i) {
  cks = xor(cks, a[substr($0,i+1,1)]);
};
};
END {
printf("%02x\n",cks);
};
'

Regards,

  

Best answer
by anonymous

it is fabulous, i don't  knew AWK.

i did the bash script:

checksum=0

for s in ${my_array[@]}; do

  checksum=$(($checksum^$(ord $s)))

done

echo $checksum

printf "%02x\n" $checksum

0 votes
by anonymous
Since when does ash support arrays ?
0 votes
by anonymous

Hello

The possible cause of the of the issue might be related to the usage of the features not understood by ash shell. Also, as mentioned by augustus_meyer, ash does not natively support arrays.

You can also try checking your script with this online tool: https://www.shellcheck.net/

Best regards,

Žygimantas 

0 votes
by anonymous
thanks for your reply

I need a script for checksum8 XOR of a String:

https://www.scadacore.com/tools/programming-calculators/online-checksum-calculator/

What script language can i use for Rut955?
by anonymous

Hello,

You could try using python. More details regarding python package installation are provided in this OpenWRT site: https://openwrt.org/docs/guide-user/services/python.

Bets regards,

Žygimantas

by anonymous
Usually, on official openwrt, which is also availabel for the RUT955, you can replace ash by bash. Or to use LUA, which is standard in official openwrt, too.

Dunno, whether the Teltonika stuff allows that, too.
by anonymous

You can download bash as an additional package via CLI using opkg command. You can also write your own applications for RUT955 in C using software development kit, which can be downloaded from this page: https://wiki.teltonika-networks.com/view/Software_Development_Kit. You can find instructions on how to develop software for router in this pagehttps://openwrt.org/docs/guide-developer/helloworld/start

0 votes
by anonymous
amazing, your advice are phenomenal.

thank you very much everyone!!!!!!!!!
0 votes
by anonymous

i don't have sufficient size in the file system.

Filesystem                Size      Used Available Use% Mounted on

rootfs                    2.9M      2.8M     72.0K  98% /

/dev/root                11.3M     11.3M         0 100% /rom

tmpfs                    61.5M    192.0K     61.3M   0% /tmp

/dev/mtdblock5            2.9M      2.8M     72.0K  98% /overlay

overlayfs:/overlay        2.9M      2.8M     72.0K  98% /

tmpfs                   512.0K         0    512.0K   0% /dev

/dev/mtdblock7          576.0K    408.0K    168.0K  71% /mnt/mtdblock7

After installation:

* pkg_write_filelist: Failed to open //usr/lib/opkg/info/python-light.list: No space left on device.

 * opkg_install_pkg: Failed to extract data files for python-light. Package debris may remain!

 * opkg_install_cmd: Cannot install package python-light.

how install python on tmpfs? And How remove python?

maybe removing /usr/lib/libpython2.7.so.1.0?

while i installed BASH, but i have this error:

bash: can't load library 'libncurses.so.5'

I try with ln -s /usr/lib/libncursesw.so.6 /usr/lib/libncurses.so.5 and works fine.

Thanks