Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-26-2011, 01:44 PM   #1
LQ Newbie
Registered: Nov 2011
Posts: 6

Rep: Reputation: Disabled
How to make my script run constantly?

I have written a script to check if a specific username is logged into the server or not. Naturally, I would like the script to run at all times so I can be alerted via email if the user logged in.

My question is what is the best way to constantly run the script? Do I need to keep it in a certain directory? Thanks for the help.
Old 11-26-2011, 01:46 PM   #2
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977
constantly? What does that mean? Sounds like you actually want to run it periodically, not constantly. You can put it in your crontab to run it every 5 minutes or so.
Old 11-26-2011, 02:08 PM   #3
LQ Newbie
Registered: Nov 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Yes Sorry I should have clarified. I would like it to run at a suitable rate to check for the logins, So 5 or 10 seconds would be ideal. I have limited experience with crontab, would I call the crontab command in my script?
Old 11-26-2011, 02:25 PM   #4
Registered: Oct 2011
Location: Bolton, UK
Distribution: Arch local, Debian on VPS
Posts: 258

Rep: Reputation: 41
You could do it with a while loop.
while :
     **** Your Stuff *****
     sleep 5
This would loop every 5 seconds forever.
Old 11-26-2011, 02:43 PM   #5
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
You can use
to sent a mail every time someone logs in.

Kind regards


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
i need to constantly run a script in the background anurupr Linux - Newbie 7 03-20-2010 05:15 PM
How do I make a simple script and make it run on bootup?? coolblue Programming 5 12-18-2006 10:55 PM
make script run on startup pytheas22 Fedora 1 11-08-2006 11:35 PM
Can't make a script run hanasi Linux - Newbie 14 08-27-2005 04:14 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:43 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration