PDA

View Full Version : Unexpected operator


chavez243ca
March 17th, 2009, 16:04
i have a script that checks the output of ps to see if squid is using too much cpu - the script is run by cron every 10 minutes. Occasionally (not always), I will get an email declaring:

[: -gt: unexpected operator

which is from the line

if [ ${test} -gt 30 ]; then

running the script with sh -xv can also sometime produce this error.

Curiously, this seems to occur either at hh:00 or hh:30

SirDice
March 17th, 2009, 16:19
If ${test} is empty the line will read:


if [ -gt 30 ]; then

DutchDaemon
March 17th, 2009, 16:23
You can use if [ -z ${data} ]; then ... else ... fi or if [ x${data} != "x" ]; then .. else .. fi ]

That way the following 'if' will only be executed when $data actually has a value (i.e.: is not an empty variable).

chavez243ca
March 17th, 2009, 16:31
a NULL value for ${test} would indicate something went wrong further up...

check=`ps -axo %cpu,command|grep "(squid) -D squid"|cut -f 2 -d " "`

test=`echo ${check}|bc -l`

I should likely test for NULL value and assign a 0 or 1

DutchDaemon
March 17th, 2009, 16:46
Maybe it's just my squid, but my process shows up as "(squid) -D (squid)". Are you sure you're not capturing the grep process instead of the squid process? Adding "| grep -v grep" usually helps. I don't think pgrep can print a CPU value.


ps -axo %cpu,command|grep "(squid) -D squid"
0.0 grep (squid) -D squid



ps -axo %cpu,command|grep "(squid) -D (squid)"
0.0 (squid) -D (squid)
0.0 grep (squid) -D (squid)


Having two lines will certainly break your variable assignment ..


ps -axo %cpu,command|grep "(squid) -D (squid)" | grep -v grep
0.0 (squid) -D (squid)

SirDice
March 17th, 2009, 16:48
Use the pgrep command instead of piping ps output to grep.

DutchDaemon
March 17th, 2009, 16:54
He wants a CPU value..

SirDice
March 17th, 2009, 16:56
ps -axo %cpu,command -p `pgrep squid`

:e

Oh wait.. That doesn't quite work..

pgrep -d, squid produces a comma at the end which screws things up :-/

DutchDaemon
March 17th, 2009, 16:58
Very funny :e

SirDice
March 17th, 2009, 17:15
assuming the bourne shell:


for p in `pgrep squid`
do
ps -axo %cpu -p $p
done


But unfortunately that prints a header on each ps query...

chavez243ca
March 17th, 2009, 20:43
Maybe it's just my squid, but my process shows up as "(squid) -D (squid)". Are you sure you're not capturing the grep process instead of the squid process? Adding "| grep -v grep" usually helps. I don't think pgrep can print a CPU value.


yeah - it's grabbing the grep value - I'll try the grep -v grep

jotawski
March 23rd, 2010, 10:41
apologized me for bringing this out once again but i every time face this message from ffserver when booting


[~] % cat /root/ffservers.scr
Starting mysql.
Starting default moused.
Starting dbus.
Starting hald.
Configuring syscons: keymap blanktime screensaver.
[: /usr/local/bin/ffserver: unexpected operator
Starting ffserver.
Starting elogd.
Starting ddclient.
Starting cupsd.


i do not know to get rid of this (error) message but annoy a few times.

any helps or hints would be highly appreciated.

best regards,
jotawski

SirDice
March 23rd, 2010, 11:23
Just a guess.. A typo or an addition space in /etc/rc.conf.

phoenix
March 23rd, 2010, 23:13
Or in the rc script for ffserver?

jotawski
March 24th, 2010, 01:41
Or in the rc script for ffserver?

ffserver rc script is automatically generated from ports when installing

to SirDice

i did re-edit /etc/rc.conf and restart ffserver but that message did not disappear.

many thanks to both of us though.

regards,
jotawski

DutchDaemon
March 24th, 2010, 02:37
I've seen errors in automatically generated rc scripts before.

Compare it with this (working) one:


#!/bin/sh
#
# $FreeBSD: ports/multimedia/ffmpeg/files/ffserver.in,v 1.2 2008/09/07 03:31:58 ahze Exp $
#

# PROVIDE: ffserver
# REQUIRE: NETWORKING
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable ffserver:
#
#ffserver_enable="YES"
#
ffserver_enable="${ffserver_enable-NO}"

. /etc/rc.subr

name=ffserver
rcvar=`set_rcvar`

command="/usr/local/bin/${name} &"
required_files=/usr/local/etc/ffserver.conf

load_rc_config ${name}
run_rc_command "$1"

jotawski
March 24th, 2010, 04:30
the same as mine.

may be i set strange options during build but i can not remember now. here is some parts of output from the script


[: /usr/local/bin/ffserver: unexpected operator
Starting ffserver.
Starting elogd.
Starting ddclient.
Starting cupsd.
FFserver version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --prefix=/usr/local --mandir=/usr/local/man --enable-shared --e
nable-gpl --enable-swscale --enable-postproc --enable-avfilter --enable-avfilter
-lavf --enable-pthreads --enable-memalign-hack --cc=cc --extra-cflags=-I/usr/loc
al/include/vorbis -I/usr/local/include --extra-ldflags=-L/usr/local/lib --extra
-libs=-pthread --disable-debug --disable-sse --disable-mmx --enable-libamr-nb --
enable-nonfree --enable-libamr-wb --enable-nonfree --enable-libdirac --enable-li
bfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --disable-vhook --ena
ble-ipv6 --enable-libmp3lame --enable-libopenjpeg --enable-libschroedinger --ena
ble-libspeex --enable-libtheora --enable-libvorbis --enable-x11grab --enable-lib
x264 --enable-libxvid
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Jan 22 2010 16:55:59, gcc: 4.2.1 20070719 [FreeBSD]
Wed Mar 24 08:41:13 2010 FFserver started.


best regards,
jotawski

DutchDaemon
March 24th, 2010, 12:39
Once it's running, what is the output of /usr/local/etc/rc.d/ffserver status? Does the error occur then as well?

jotawski
March 24th, 2010, 15:20
Once it's running, what is the output of /usr/local/etc/rc.d/ffserver status? Does the error occur then as well?

there is no error code displayed but the output which i have shown above.
this is really very strange.

many thanks for your time indeed.

DutchDaemon
March 24th, 2010, 15:29
Seeing that the error occurs specifically when /usr/local/bin/ffserver gets called: did you make any changes to /usr/local/etc/ffserver.conf? I see this rather awkward syntax in there:


# Format of the stream : you can choose among:
# mpeg : MPEG-1 multiplexed video and audio
# mpegvideo : only MPEG-1 video
[..]
Format mpeg


Uncommenting an option there would probably introduce a spurious ":" that may cause this specific error.

Quick check: grep -v -E "(^$|^#)" /usr/local/etc/ffserver.conf | grep \:. This should only produce a URL.

jotawski
March 24th, 2010, 21:55
Seeing that the error occurs specifically when /usr/local/bin/ffserver gets called: did you make any changes to /usr/local/etc/ffserver.conf? I see this rather awkward syntax in there:


# Format of the stream : you can choose among:
# mpeg : MPEG-1 multiplexed video and audio
# mpegvideo : only MPEG-1 video
[..]
Format mpeg


Uncommenting an option there would probably introduce a spurious ":" that may cause this specific error.

Quick check: grep -v -E "(^$|^#)" /usr/local/etc/ffserver.conf | grep \:. This should only produce a URL.

i apply your hint to both /usr/local/etc/ffserver.conf and /usr/local/etc/ffserver.conf-dist it produce only the last line of the configuration file which is the only url

here they are


# grep -v ^$ /usr/local/etc/ffserver.conf | grep -v ^# | grep :
URL http://www.ffmpeg.org/
# grep -v ^$ /usr/local/etc/ffserver.conf-dist | grep -v ^# | grep :
URL http://www.ffmpeg.org/


many thanks indeed for your times

jotawski
March 24th, 2010, 22:12
hi sirs,

i also try to remove blank lines and comment lines from /usr/local/etc/ffserver.conf but it still produces the same things. here they are


[maifa] /home/pirat# /usr/local/etc/rc.d/ffserver restart
Stopping ffserver.
[: /usr/local/bin/ffserver: unexpected operator
Starting ffserver.
[maifa] /home/pirat# FFserver version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --prefix=/usr/local --mandir=/usr/local/man --enable-shared --enable-gpl --enable-swscale --enable-postproc --enable-avfilter --enable-avfilter-lavf --enable-pthreads --enable-memalign-hack --cc=cc --extra-cflags=-I/usr/local/include/vorbis -I/usr/local/include --extra-ldflags=-L/usr/local/lib --extra-libs=-pthread --disable-debug --disable-sse --disable-mmx --enable-libamr-nb --enable-nonfree --enable-libamr-wb --enable-nonfree --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --disable-vhook --enable-ipv6 --enable-libmp3lame --enable-libopenjpeg --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-x11grab --enable-libx264 --enable-libxvid
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Jan 22 2010 16:55:59, gcc: 4.2.1 20070719 [FreeBSD]
Thu Mar 25 03:04:55 2010 FFserver started.

[maifa] /home/pirat# echo $?
0
[maifa] /home/pirat#


should we file a pr ?