Using cron but if i wanna do more??

Using cron but if i wanna do more??

Post by RyLo » Thu, 19 Dec 2002 19:28:26



Ok let me explain,
i use cron and every night at 4:02 it run the poweroff command, and this is
ok and working.
Sometimes, when i am in another room on another PC im watching divx stored
on a samba share on linux and magic,
if im watching it at 4:00 cron turn off linux and i must go poweron it, how
can i test something or can i block cron from executing the scripts if there
is samba working?

Thanks in advance
RyLoS

 
 
 

Using cron but if i wanna do more??

Post by Seth J. Fogart » Thu, 19 Dec 2002 19:43:47



>  Ok let me explain,
>  i use cron and every night at 4:02 it run the poweroff command, and this is
>  ok and working.
>  Sometimes, when i am in another room on another PC im watching divx stored
>  on a samba share on linux and magic,
>  if im watching it at 4:00 cron turn off linux and i must go poweron it, how
>  can i test something or can i block cron from executing the scripts if there
>  is samba working?

Don't use cron, make a shell script. Figure out a way to test if samba
is in use (it probably exists), and make it an if statement in a script.
Then just have cron run the script.

--
Arav        bipsum      |    "The same person. No difference at all. Just a
Bicameral neep-neep     |    different sex." -Orlando   (Orlando, 1992)
--------------------------------------------------------------------------


 
 
 

Using cron but if i wanna do more??

Post by stephan bea » Thu, 19 Dec 2002 19:51:42



> i use cron and every night at 4:02 it run the poweroff command, and this
> is ok and working.
> Sometimes, when i am in another room on another PC im watching divx stored
> on a samba share on linux and magic,
> if im watching it at 4:00 cron turn off linux and i must go poweron it,
> how can i test something or can i block cron from executing the scripts if
> there is samba working?

There are multiple ways to go about it, but i think the first thing you need
to do is not call poweroff directly, but make a wrapper script. In this
wrapper you can do something like:

pgrep -f mbd || /sbin/poweroff

All that does is looks to see if nmbd/smbd are running, and runs poweroff if
they're not.

If you want to get trickier you could parse the output from smbstatus and
see if any files are open. (man smbstatus)

Another option is to test the system load:

uptime | perl -ne '$_=~/(\S+), \S+, \S+$/;print $1;'
Will print out the current system load, so you could do some operation on it
(e.g., see if it's >0.1, and don't poweroff if it is). Because of the
comparison of a floating-point number, that'll probably be much easier if
you'll write your wrapper in perl, instead of as a shell script.

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.