LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-26-2011, 01:44 PM   #1
SecureScript
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
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
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
SecureScript
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
Roken
Member
 
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.
Code:
while :
do
     **** Your Stuff *****
     sleep 5
done
This would loop every 5 seconds forever.
 
Old 11-26-2011, 02:43 PM   #5
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
You can use
Code:
/etc/profile
to sent a mail every time someone logs in.

Kind regards
 
  


Reply


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


All times are GMT -5. The time now is 12:58 AM.

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