Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a bash script (let's call it script.sh) which looks like this

while true; do
  if [ $someFile -eq = "1" ]
  then
    # make laptop LED blink here
  fi
done

So when some file has some value (in my case, this file is changed when messages arrives), the script make a LED blink. As you can guess, this script never stops.

I usually call it when I need to know wether there is new mail and I can't open the laptop and check the screen.

Today I said to myself: let's put this in .bash_profile so the script gets fired up at login.

But when I try to login, alas the screen freezes.

How can I tell bash: execute this, but in a non blocking way?

Or: is there another solution to fire this at startup without freezing the machine?

share|improve this question
add comment

3 Answers

Nice thought. But, you have stalled the login sequence in your infinite loop :-)
So, try to launch your script with a command like,

nohup ~/script.sh &

That way, it will be sent into background and let your login continue.

Better still, read up about cron and sleep ...

share|improve this answer
    
mhhh, I can login with nohup ~/script.sh &, but it seems the script is not working... –  Sefertto Apr 10 '13 at 16:25
1  
Why nohup? Sending it to the background should be enough shouldn't it? –  terdon Apr 10 '13 at 16:37
    
@terdon, just a habit :) you are right, send it to background is the idea. –  nik Apr 10 '13 at 17:36
add comment

The best way would probably be to add this to cron. Create a crontab with the following line:

@reboot ~/script.sh &

There may also be complications from the way you are making the led blink. You might get better answers if you include the entire script so we can see what is going on.

share|improve this answer
add comment

Rather than running this via cron with an explicit loop, read up on inotify, "a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes to applications".

The inotify-tools tools documentation show how to install and give usage examples.

share|improve this answer
add comment

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.