Register
It is currently Wed Oct 22, 2014 9:03 pm

What is unary operator?


All times are UTC - 6 hours


Post new topic Reply to topic  [ 11 posts ] 
Author Message
 PostPosted: Wed Jul 17, 2013 12:53 am   

Joined: Wed Jul 17, 2013 12:13 am
Posts: 5
I wrote a script that when run as daemon checks whether pppd is running, otherwise boots it, iteratively
Copied in a file pppdchk.sh
#!/bin/bash
done=0
while:
do
x=0
x='pidof pppd'
if [$x != "\n"]
then
sleep 1
else
pon dsl-provider
sleep 1
fi done

The script runs but I get an output ...unary operator expected...
Why?


Top
 Profile  
 PostPosted: Wed Jul 17, 2013 10:51 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
hi,

due to missing spaces, the script should not run at all.

' is not `

instead of testing if a non-quoted variable (that should be quoted (always quote variables!)) is a line break (that simple test can't see),
you should test whether varibale is empty or not (see help test).


Top
 Profile  
 PostPosted: Wed Jul 17, 2013 7:37 pm   

Joined: Wed Jul 17, 2013 12:13 am
Posts: 5
Watael wrote:
....

Talking to a child of 6 years, "... the reason quantum mechanical problems are addressed to by Hilbert space mathematics is because the states of the system in question obey the laws of linear superposition..."


Top
 Profile  
 PostPosted: Wed Jul 17, 2013 8:30 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
yep.
the cat both agrees, and disagrees.


Top
 Profile  
 PostPosted: Wed Jul 17, 2013 10:39 pm   

Joined: Wed Jul 17, 2013 12:13 am
Posts: 5
Watael wrote:
..hyperbole, hyperbole..

Please step aside...
I request someone to empathise with me, please?!


Top
 Profile  
 PostPosted: Thu Jul 18, 2013 9:57 am   
User avatar

Joined: Fri Jul 22, 2011 5:39 pm
Posts: 47
Code:
if [ $x != "\n" ]

Can you guess what caused the problem?


Top
 Profile WWW  
 PostPosted: Thu Jul 18, 2013 11:11 am   

Joined: Wed Jul 17, 2013 12:13 am
Posts: 5
Habitual wrote:
Can you guess what caused the problem?

Yes, ... What is unary operator?
And that you will lose friends and popularity if you all continue like this ...


Top
 Profile  
 PostPosted: Thu Jul 18, 2013 2:50 pm   
User avatar

Joined: Fri Jul 22, 2011 5:39 pm
Posts: 47
bkpsusmitaa wrote:
And that you will lose friends and popularity if you all continue like this ...


There's 5 minutes I'll never get back.


Top
 Profile WWW  
 PostPosted: Fri Jul 19, 2013 4:56 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
what didn't I say that ubuntuforums people said?


Top
 Profile  
 PostPosted: Fri Jul 19, 2013 6:51 pm   
User avatar

Joined: Fri Jul 22, 2011 5:39 pm
Posts: 47
Here's a working example of a server check I wrote that works, but have supplied your service and what I suspect is what starts it.
Code:
#!/bin/bash
SERVICE='pppd'

if /usr/bin/pgrep $SERVICE > /dev/null
then
    exit 0
else
    pon dsl-provider
    exit 1
fi

Stick that in pppdchk.sh. Save it and exit.
Code:
chmod 700 /path/to/pppdchk.sh
crontab -e
and add:
Code:
*/1 * * * * /path/to/pppdchk.sh


Code:
man bash
> search for CONDITIONAL EXPRESSIONS

Your script barfs because you declared x=0 (a digit) and then tried to compare that to non-digit (if [$x != "\n"]) using an improperly constructed
[[ (missing spaces) ]] test operator. All of which is very well documented in several real-life methods for properly constructed [[ test ]] mechanisms.

Next time, don't let your alligator mouth overload your hummingbird a**hole.

and
uh, You're Welcome.


Top
 Profile WWW  
 PostPosted: Fri Jul 19, 2013 9:14 pm   

Joined: Wed Jul 17, 2013 12:13 am
Posts: 5
I already have received the solution ... ...Unary operator..., ...and... I just typed wrong. The actual code worked. The error message has been taken care of.

Habitual wrote:
don't let your ... overload your ...

Do you usually talk like this?... with your parents?... wife?... child?... boss? ...

Thanks for the hard work you have done. As you have already said 'welcome', 'bye!


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP