How does the pinging script work on Qnap?

Introduce yourself to us and other members here, or share your own product reviews, suggestions, and tips and tricks of using QNAP products.
aleksey_z
Getting the hang of things
Posts: 66
Joined: Tue Jun 10, 2014 6:41 pm

How does the pinging script work on Qnap?

Post by aleksey_z »

Help me please.
TS239ProII+ & QTS 4.2.4
I try to run the pinging script for ping network devices (smartphone), but it does not work and I get in the log:

Code: Select all

grep: invalid option -- w
BusyBox v1.01 (2017.03.12-18:58+0000) multi-call binary

Usage: grep [-ihHnqvs] PATTERN [FILEs...]

Search for PATTERN in each FILE or standard input.

Options:
	-H	prefix output lines with filename where match was found
	-h	suppress the prefixing filename on output
	-i	ignore case distinctions
	-l	list names of files that match
	-n	print line number with output lines
	-q	be quiet. Returns 0 if result was found, 1 otherwise
	-v	select non-matching lines
	-s	suppress file open/read error messages
The script looks like this:

Code: Select all

#!/bin/sh
#set up new vars;
new_var=0
var1=android
var2=192.168.1.35
ddd=$(date +"%Y-%m-%d %H:%M:%S,%3N")
echo "datetime = $ddd"

echo "ipaddress to check is $var2"
status=`ping -qc 1 $var2 | grep -wi '[0-9][[:space:]]received'|awk -F, '{print $2}'|awk '{print $1}'`
echo "$var1 status is :$status";

# if status is ge 1 that means one of the ips responded to a ping.
# therefore value in pingsensor table should be set to 0;

   if [[ $status -gt 0 ]]; then
   echo "ping response received resetting $var1 status to 1"
   echo "1" > /share/MD0_DATA/.qpkg/OpenRemote/OpenRemote/facts/sensor_$var1
   else
    #write out a 0 in the android_sensor file
    echo "0" > /share/MD0_DATA/.qpkg/OpenRemote/OpenRemote/facts/sensor_$var1
   fi

ddd=$(date +"%Y-%m-%d %H:%M:%S,%3N")
echo "datetime = $ddd"
echo "**********************************************************"
On my second NAS Synology, this script works well for pinging my smartphone.

Thanks.
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: How does the pinging script work on Qnap?

Post by OneCD »

Looks like your old BusyBox 1.01 grep doesn't like that 'w' option.

So, you'll need to install GNU grep.

As I think you're now back on Optware (instead of Entware), try this:

Code: Select all

ipkg install grep

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
aleksey_z
Getting the hang of things
Posts: 66
Joined: Tue Jun 10, 2014 6:41 pm

Re: How does the pinging script work on Qnap?

Post by aleksey_z »

Thanks for you quickly reply. Yes, I have install Optware.

Tomorrow a morning i try this.
aleksey_z
Getting the hang of things
Posts: 66
Joined: Tue Jun 10, 2014 6:41 pm

Re: How does the pinging script work on Qnap?

Post by aleksey_z »

Hi.

I am install GNU grep.

Code: Select all

[~] # ipkg update
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/Packa                                                                                        ges.gz
Inflating http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/Package                                                                                        s.gz
Updated list of available packages in /opt/lib/ipkg/lists/ts509
Successfully terminated.
[~] # ipkg install grep
Installing grep (2.12-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/grep_                                                                                        2.12-1_i686.ipk
Installing pcre (8.31-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/pcre_                                                                                        8.31-1_i686.ipk
Installing libstdc++ (6.0.9-6) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/libst                                                                                        dc++_6.0.9-6_i686.ipk
Configuring grep
update-alternatives: Linking //opt/bin/grep to /opt/bin/grep-grep
update-alternatives: Linking //opt/bin/egrep to /opt/bin/grep-egrep
update-alternatives: Linking //opt/bin/fgrep to /opt/bin/grep-fgrep
Configuring libstdc++
Configuring pcre
Successfully terminated.
[~] # ipkg list_installed
autoconf - 2.69-1 - Creating scripts to configure source code packages using templates
automake - 1.12-1 - Creates GNU standards-compliant Makefiles from template files
binutils - 2.17-2 - The GNU assembler and linker and related tools
freetype - 2.3.6-1 - Free truetype library
gcc - 4.2.1-5 - The GNU Compiler Collection.
grep - 2.12-1 - Global regular expression parser
libc-dev - 2.6.1-5 - libc development files.
libnsl - 2.6.1-4 - Network Services Library
libstdc++ - 6.0.9-6 - Standard C++ library, needed for dynamically linked C++ programs
m4 - 1.4.16-1 - gnu macro processor and compiler front end
make - 3.82-1 - examines files and runs commands necessary for compilation
pcre - 8.31-1 - Perl-compatible regular expression library
zlib - 1.2.5-1 - zlib is a library implementing the 'deflate' compression system.
Successfully terminated.
[~] # reboot
The same log:

Code: Select all

grep: invalid option -- w
BusyBox v1.01 (2017.03.12-18:58+0000) multi-call binary
Usage: grep [-ihHnqvs] PATTERN [FILEs...]
Search for PATTERN in each FILE or standard input.
Options:
	-H	prefix output lines with filename where match was found
	-h	suppress the prefixing filename on output
	-i	ignore case distinctions
	-l	list names of files that match
	-n	print line number with output lines
	-q	be quiet. Returns 0 if result was found, 1 otherwise
	-v	select non-matching lines
	-s	suppress file open/read error messages
	
If -- v, then:

Code: Select all

ping: sendto: Invalid argument
ping: sendto: Invalid argument
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: How does the pinging script work on Qnap?

Post by OneCD »

Which grep are you using?

Code: Select all

which grep
If your $PATH isn't set correctly, you won't run the new one by default.

To check the version:

Code: Select all

grep --version
Then try this one:

Code: Select all

/opt/bin/grep --version

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
aleksey_z
Getting the hang of things
Posts: 66
Joined: Tue Jun 10, 2014 6:41 pm

Re: How does the pinging script work on Qnap?

Post by aleksey_z »

Code: Select all

[~] # which grep
/bin/grep
[~] # grep --version
grep: unrecognized option `--version'
BusyBox v1.01 (2017.03.12-18:58+0000) multi-call binary

Usage: grep [-ihHnqvs] PATTERN [FILEs...]

Search for PATTERN in each FILE or standard input.

Options:
        -H      prefix output lines with filename where match was found
        -h      suppress the prefixing filename on output
        -i      ignore case distinctions
        -l      list names of files that match
        -n      print line number with output lines
        -q      be quiet. Returns 0 if result was found, 1 otherwise
        -v      select non-matching lines
        -s      suppress file open/read error messages

[~] # /opt/bin/grep --version
/opt/bin/grep (GNU grep) 2.12
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: How does the pinging script work on Qnap?

Post by OneCD »

So, you can now either manually specify /opt/bin/grep each time you need it, or you can prepend /opt/bin to your $PATH. ;)

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
aleksey_z
Getting the hang of things
Posts: 66
Joined: Tue Jun 10, 2014 6:41 pm

Re: How does the pinging script work on Qnap?

Post by aleksey_z »

I have little knowledge in Linux.
In the $PATH now like this: (after installing Optware-IPKG from package, I did not touch anything)

Code: Select all

# ~/.bashrc: executed by bash(1) for non-login interactive shells.

export PATH=\
/bin:\
/sbin:\
/usr/bin:\
/usr/sbin:\
/usr/bin/X11:\
/usr/local/sbin

# If running interactively, then:
if [ "$PS1" ]; then

    if [ "$BASH" ]; then
	export PS1="[\u@\h \W]\\$ "
	alias ll='/bin/ls -laFh'
	alias ls='/bin/ls -F'
	export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.png=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:';
    else
      if [ "`id -u`" -eq 0 ]; then 
	export PS1='# '
      else
	export PS1='$ '
      fi
    fi

    export USER=`id -un`
    export LOGNAME=$USER
    export HOSTNAME=`/bin/hostname`
    export HISTSIZE=1000
    export HISTFILESIZE=1000
    export PAGER='/bin/more '
    export EDITOR='/bin/vi'
    export INPUTRC=/etc/inputrc
    export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile
    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    export LC_CTYPE=en_US.UTF-8

    ### Some aliases
    alias ps2='ps facux '
    alias ps1='ps faxo "%U %t %p %a" '
    alias af='ps af'
    alias cls='clear'
    alias df='df -h'
    alias indent='indent -bad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs -npsl -nsc -nsob -nss -ts4 '
    #alias bc='bc -l'
    alias minicom='minicom -c on'
    alias calc='calc -Cd '
    alias bc='calc -Cd '
fi;
export PATH=${PATH}:/usr/local/bin
alias smb2enable='/etc/init.d/smb2_protocol.sh enable'
alias smb2disable='/etc/init.d/smb2_protocol.sh disable'
alias smb2status='/etc/init.d/smb2_protocol.sh status'
alias smb21enable='/etc/init.d/smb2_protocol.sh enable 21'
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin:/opt/bin:/opt/sbin
export JAVA_HOME=/usr/local/jre
export PATH=$PATH:$JAVA_HOME/bin
Where do I need to add /opt/bin/grep ?
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: How does the pinging script work on Qnap?

Post by OneCD »

The third line from the bottom should be re-arranged so the /opt directories are at the front.

Like this:

Code: Select all

export PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
aleksey_z
Getting the hang of things
Posts: 66
Joined: Tue Jun 10, 2014 6:41 pm

Re: How does the pinging script work on Qnap?

Post by aleksey_z »

Not work. I add:

Code: Select all

export PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin:/var/lib/phpfiwa:/var/lib/phpfina:/var/lib/phptimeseries:/var/log

Code: Select all

grep: invalid option -- w
BusyBox v1.01 (2017.03.12-18:58+0000) multi-call binary

Usage: grep [-ihHnqvs] PATTERN [FILEs...]

Search for PATTERN in each FILE or standard input.

Options:
	-H	prefix output lines with filename where match was found
	-h	suppress the prefixing filename on output
	-i	ignore case distinctions
	-l	list names of files that match
	-n	print line number with output lines
	-q	be quiet. Returns 0 if result was found, 1 otherwise
	-v	select non-matching lines
	-s	suppress file open/read error messages
Please tell me where in the Qnap is being tuned a php open_basedir path.
I need to add:

Code: Select all

:/var/lib/phpfiwa:/var/lib/phpfina:/var/lib/phptimeseries:/var/log
In Synology it looks like this: screen
You do not have the required permissions to view the files attached to this post.
aleksey_z
Getting the hang of things
Posts: 66
Joined: Tue Jun 10, 2014 6:41 pm

Re: How does the pinging script work on Qnap?

Post by aleksey_z »

Now, i change in Optware.sh

Code: Select all

# adding Ipkg apps into system path ...
	/bin/cat /etc/profile | /bin/grep "PATH" | /bin/grep "/opt/bin" 1>>/dev/null 2>>/dev/null
	[ $? -ne 0 ] && /bin/echo "export PATH=\$PATH":/opt/bin:/opt/sbin >> /etc/profile
after reboot i get this:

Code: Select all

[~] # echo $PATH
/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin:/opt/bin:/opt/sbin:/usr/local/jre/bin
but in the /etc/profile only

Code: Select all

export PATH=$PATH:/opt/bin:/opt/sbin
in ping script log new argument

Code: Select all

ping: sendto: Invalid argument
grep: invalid option -- w
BusyBox v1.01 (2017.03.12-18:58+0000) multi-call binary

Usage: grep [-ihHnqvs] PATTERN [FILEs...]

Search for PATTERN in each FILE or standard input.

Options:
	-H	prefix output lines with filename where match was found
	-h	suppress the prefixing filename on output
	-i	ignore case distinctions
	-l	list names of files that match
	-n	print line number with output lines
	-q	be quiet. Returns 0 if result was found, 1 otherwise
	-v	select non-matching lines
	-s	suppress file open/read error messages
aleksey_z
Getting the hang of things
Posts: 66
Joined: Tue Jun 10, 2014 6:41 pm

Re: How does the pinging script work on Qnap?

Post by aleksey_z »

Next step:

I change pinging script. Now the script looks like this:

Code: Select all

#!/bin/sh
#set up new vars;
new_var=0
var1=android
var2=192.168.1.35
ddd=$(date +"%Y-%m-%d %H:%M:%S,%3N")
echo "datetime = $ddd"

echo "ipaddress to check is $var2"
status=`ping -q c 1 $var2 | grep -vi '[0-9][[:space:]]received'|awk -F, '{print $2}'|awk '{print $1}'`
echo "$var1 status is :$status";

# if status is ge 1 that means one of the ips responded to a ping.
# therefore value in pingsensor table should be set to 0;

   if [[ $status -gt 0 ]]; then
   echo "ping response received resetting $var1 status to 1"
   echo "1" > /share/MD0_DATA/.qpkg/OpenRemote/OpenRemote/facts/sensor_$var1
   else
    #write out a 0 in the android_sensor file
    echo "0" > /share/MD0_DATA/.qpkg/OpenRemote/OpenRemote/facts/sensor_$var1
   fi

ddd=$(date +"%Y-%m-%d %H:%M:%S,%3N")
echo "datetime = $ddd"
echo "**********************************************************"
but in log only:

Code: Select all

ping: c: Unknown host
ping: c: Unknown host
ping: c: Unknown host
ping: c: Unknown host
ping: c: Unknown host
How fix its script?
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: How does the pinging script work on Qnap?

Post by OneCD »

No sure where to start.

You're missing steps, you're rebooting without ensuring your files will be modified after reboot, you're showing extracts from files with no context. :S

When (re)setting variables like $PATH multiple times, the order becomes important. e.g.
PATH="/usr:/usr/bin"
PATH="/opt/bin:/opt/sbin:$PATH"
OneCD wrote:The third line from the bottom should be re-arranged so the /opt directories are at the front.

Like this:

Code: Select all

export PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin
Please note: /etc/profile is not persistent - changes made to it will be lost when you reboot - so you'll need to ensure that your /etc/profile is restored after reboot.

When you changed /etc/profile as I indicated above, did you logout and reconnect your SSH session?

Maybe the best thing to do (for now) is to set your $PATH manually. Run your script. Check that it works. If so, THEN modify /etc/profile. :geek:

So, at the shell prompt:

Code: Select all

export PATH="/opt/bin:/opt/sbin:$PATH"
Then try running your script.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
aleksey_z
Getting the hang of things
Posts: 66
Joined: Tue Jun 10, 2014 6:41 pm

Re: How does the pinging script work on Qnap?

Post by aleksey_z »

I performed at the shell prompt:

Code: Select all

[~] # export PATH="/opt/bin:/opt/sbin:$PATH"
Now I get:

Code: Select all

[~] # echo $PATH
/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin:/opt/bin:/opt/sbin:/usr/local/jre/bin
running script, but in log as before:

Code: Select all

ping: c: Unknown host
Maybe the script itself is not correct? But on the Synology worked well.
Last edited by aleksey_z on Wed Mar 22, 2017 3:39 am, edited 1 time in total.
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: How does the pinging script work on Qnap?

Post by OneCD »

aleksey_z wrote:running script, but in log as before:

Code: Select all

ping: c: Unknown host
Your ping command should specify '-c'. At the moment, it specifies 'c' ;)

So, change it to this:

Code: Select all

status=`ping -q -c 1 $var2 | grep -vi '[0-9][[:space:]]received'|awk -F, '{print $2}'|awk '{print $1}'`

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
Locked

Return to “Users' Corner”