Unexpected operator

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:

Code:
[: -gt: unexpected operator

which is from the line

Code:
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
 
If ${test} is empty the line will read:

Code:
if [  -gt 30 ]; then
 
You can use
Code:
if [ -z ${data} ]; then ... else ... fi
or
Code:
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).
 
a NULL value for ${test} would indicate something went wrong further up...

Code:
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
 
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.

Code:
ps -axo %cpu,command|grep "(squid) -D squid"
 0.0 [B]grep[/B] (squid) -D squid

Code:
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 ..

Code:
ps -axo %cpu,command|grep "(squid) -D (squid)" | grep -v grep
 0.0 (squid) -D (squid)
 
Use the pgrep command instead of piping ps output to grep.
 
Code:
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 :-/
 
assuming the bourne shell:

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

But unfortunately that prints a header on each ps query...
 
DutchDaemon said:
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
 
apologized me for bringing this out once again but i every time face this message from ffserver when booting

Code:
[~] % 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
 
Just a guess.. A typo or an addition space in /etc/rc.conf.
 
phoenix said:
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
 
I've seen errors in automatically generated rc scripts before.

Compare it with this (working) one:

Code:
#!/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"
 
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

Code:
[: /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
 
Once it's running, what is the output of /usr/local/etc/rc.d/ffserver status? Does the error occur then as well?
 
DutchDaemon said:
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.
 
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:

Code:
# 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: [cmd=]grep -v -E "(^$|^#)" /usr/local/etc/ffserver.conf | grep \:[/cmd]. This should only produce a URL.
 
DutchDaemon said:
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:

Code:
# 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: [cmd=]grep -v -E "(^$|^#)" /usr/local/etc/ffserver.conf | grep \:[/cmd]. 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

Code:
# 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
 
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

Code:
[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 ?
 
Back
Top