Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

when I run the particular command in a console it works fine but when I run using start script..it throws error.

#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
    # code to start app comes here
    # example: daemon program_name &
        daemon /root/amr/bin/LoggerServer &
        daemon /root/amr/bin/mediaController -i 192.168.117.119 &
        daemon /root/amr/bin/mstdaemon --daemon
        daemon /root/amr/bin/pcdaemon --daemon -i ens192 -f "udp && portrange 3000-8000 && not(src host localhost)" &
        daemon /root/amr/bin/stund &
        daemon /root/amr/bin/tdaemon &
        #/root/amr/bin/start.sh &
}

stop() {
    # code to stop app comes here
    # example: killproc program_name
        killproc LoggerServer
        killproc mediaController
        killproc mstdaemon
        killproc pcdaemon
        killproc stund
        killproc tdaemon
}

case "$1" in
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here
       # example: status program_name
        status LoggerServer
        status mediaController
        status mstdaemon
        status pcdaemon
        status stund
        status tdaemon
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac

exit 0

error :

/bin/bash: -c: line 0: syntax error near unexpected token `src'
/bin/bash: -c: line 0: `ulimit -S -c 0 >/dev/null 2>&1 ; /root/amr/bin/pcdaemon --daemon -i ens192 -f udp && portrange 3000-8000 && not(src host localhost)'

command line run : ./pcdaemon --daemon -i ens192 -f "udp && portrange 3000-8000 && not(src host localhost)"

share|improve this question
    
I am pulling blanks about that /root/amr directory contents ? It is not something that I encountered before. Care to let me know what lies in that directory ? – MelBurslan Jul 7 at 18:28
    
all my executables located there – Suresh Kumar Jul 7 at 18:29
    
Might be some sort of quoting mishap, it seems to see that && as a shell boolean. Maybe try single quotes instead of double, just in case? – Ulrich Schwarz Jul 7 at 18:38
    
same error for single quote – Suresh Kumar Jul 7 at 18:41
1  
Which distribution and version is it? Just guessing: there's a function daemon in /etc/init.d/functions and it messes up the quoting while running the command. – ilkkachu Jul 7 at 18:41
up vote 1 down vote accepted

Looking inside /etc/init.d/functions on an old CentOS system, the daemon function effectively runs

/bin/bash -c "[...] ; $*"

$* expands to to the function's arguments, separated by spaces, effectively losing the extra quotes around "udp...localhost)". The result is given to a new shell, that sees the following:

/root/amr/bin/pcdaemon --daemon -i ens192 -f udp && portrange 3000-8000 && not(src host localhost)

and runs it as a command line. The && is not quoted at this point, so it's interpreted by the shell where foo && bar means "run foo, then if it succeeds, run bar". As it happens the not(src... triggers a syntax error so nothing runs. Changing the not to a ! will not help, because even though it removes the syntax error, the shell now runs pcdaemon with the arguments truncated and then tries to run a program called portrange.

Apart from having Red Hat fix the script, you could work around this by putting the pcdaemon command line in a script of its own (as suggested by Mark Plotnick), or by adding another set of quotes. With the current daemon function, I think this should work:

daemon /root/amr/bin/pcdaemon --daemon -i ens192 -f "'udp && portrange 3000-8000 && not(src host localhost)'" 

(Though if someone were to actually fix the daemon function, then this would give the extra quotes to pcdaemon.)

share|improve this answer
    
Thanks a lot genius! It works well. – Suresh Kumar Jul 8 at 16:42

Change not(src host localhost) to !(src host localhost)

share|improve this answer
    
Please refrain posting your additional questions as answers. They should be comments. – MelBurslan Jul 7 at 18:45
    
Sorry about that. I'm not allowed to comment yet because I am new. So thought I'd ask it where I am allowed to post. – stingray Jul 7 at 18:46
    
Is && not(src host localhost) == && !(src host localhost)?yes it is – Suresh Kumar Jul 7 at 18:51
    
Then try using ! instead or not. I got the same error running the command and replacing not with ! passed. test:~$ /root/amr/bin/pcdaemon --daemon -i ens192 -f udp && portrange 3000-8000 && not(src host localhost) -bash: syntax error near unexpected token `src' test:~$ /root/amr/bin/pcdaemon --daemon -i ens192 -f udp && portrange 3000-8000 && !(src host localhost) -bash: /root/amr/bin/pcdaemon: Permission denied – stingray Jul 7 at 18:54
    
@stingray see also the FAQ (but if that's a pcap filter, then the answer to your question is here ) – ilkkachu Jul 7 at 18:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.