Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am currently launching fetchmail on a machine on which I normally log in locally. Originally, I put the command to launch the daemon in my ~/.bashrc file, but once I realized that every time I launched another terminal window it was running another copy of the daemon, I tried to figure out where to put it so it would only be launched once when I logged in. I settled on ~/.bashrc_profile. Locally, this seems to work just fine.
The problem is, if I log on to this machine from elsewhere, it starts up another copy of the daemon.
How do I set this up so it only launches the fetchmail daemon when I'm logged on locally, and only once, because presumably I could log on multiple times locally and I still don't want multiple daemons running.
ooh, I just got another idea! If you have it in you ~/.bashrc or something, when you start it up, also do a "touch ~/.fetchmail_is_running" ... kindof like your own lock file. then you can check if that is there, so you don't have to deal with the "ps" command. then, in you ~/.bash_logout file you can put something like "rm ~/.fetchmail_is_running"
maybe something like this:
in ~/.bash_profile:
if [ ! -e ~/.fetchmail_is_on ] ; then
sendmail -k
touch /root/.fetchmail_is_on
fi
then in ~/.bash_logout :
rm ~/.fetchmail_is_on
try that out... it should do the job
EDIT:
just another thought....
you might want to put that file in a world readable place, or /tmp or something, then put the script to delete it in /etc/rc.d/rc6.d/ named K05rm_fetchmail_is_on (don't forget to make it executable)
this way, if you log on then log off, the file won't be deleted...
Cool idea. I thought of one problem though. If there's a power failure, the file would prevent restarting fetchmail until I removed it by hand.
I think your other idea of doing a ps -A | grep fetchmail is going to work. I am trying to figure out how to get bash to evaluate and test the return of that command now.
if [ -z "$(ps -A | grep fetchmail)" ]; then
/usr/bin/fetchmail
fi
I think "-z str" delivers the value true if the length of str is equal to zero!!
right?
how should this string equal zero. I receive following when I check for "ps -ef | grep fetchmail":
realos 4273 1 0 01:14 ? 00:00:01 /usr/bin/fetchmail -d 180
As you see it is not zero. Am I doing some silly mistake?
The z is there because jkcunningham wanted to test if fetchmail was running on his system.
the stuff inside the [ ]'s is tested, and if it is returned true, then fetchmail will be run. The -z returns true if the "ps -A | grep fetchmail" doesn't return anything... that is... the string is empty.
ps -A | grep init
and
ps -A | grep someprog
the first one will return a string, which means that the -z will make the test return false, while the second one will return nothing, and the -z will make the test return true
You probably have a fetchmailrc file that tells it to start up in daemon mode.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.