Register
It is currently Wed Jul 23, 2014 5:53 am

Hi, i need a bit of help...


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sun Aug 02, 2009 11:55 pm   

Joined: Sun Aug 02, 2009 11:26 pm
Posts: 2
Hi mates, i need a bit of help...

i writing a script for monitoring a users that connecting a machine...

but i have a error when execute this script...

i want detect when more a 1 users is connected, send a mail...but i try write first part, detect for more of 1 user...

this is script...a very tiny script...
Code:
#!/usr/bin/bash

function num { who | wc -l; }

if [ $num > 2]; then
        echo "La cantidad de usuarios es inferior a 2"
        else
        echo "La cantidad de usuarios conectados es `num`"
        fi

echo $num


And this is the output.

Code:
bash-2.03$ prueba
.//prueba: 2: No such file or directory
La cantidad de usuarios conectados es        3


why responding whit this error?

.//prueba: 2: No such file or directory


Top
 Profile  
 PostPosted: Mon Aug 03, 2009 1:18 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
This is probably because you're missing a space.

if [ $num > 2]; then needs to be if [ $num > 2 ]; then

Also, I would recommend using text based comparision operators.
> can be written as -gt
< can be written as -lt
<= can be written as -le
>= can be written as -ge

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Mon Aug 03, 2009 1:15 pm   

Joined: Sun Aug 02, 2009 11:26 pm
Posts: 2
Thankz man, i try this when can open my work laptop xD

let know is all is ok ;)


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 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