Linux - NewbieThis 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
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.
Does the cron.hourly folderr work the same way as a cron job? Forgive me if I use any of the vocabulary wrong, I don't quite understand all of it yet. So if I make a symbolic link to proftpd in the cron.hourly directory it will first check if proftpd is running, then it will start it if it isn't?
Also, can I make a symbolic link that has commands attached to it? I wanted to put "/usr/local/apache2/bin/apachectl start" in the cron.hourly directory so it would check if apache was running or not and then start it if it wasn't.
Well, kind of. If you look in your /etc/crontab file, you will see that it is set up to run a program named "run-parts" on the various /etc/cron.* directories every so often. It will run "run-parts /etc/cron.hourly" at the beginning of each hour. What that run-parts script does is look in the directory it is given and run each program in there.
So if you make a link to proftpd in there, it will run it every hour, even if it is already running. This is probably not what you want, unless proftpd detects that another copy is already running and exits cleanly. You can probably do that and it will just log a message saying that the FTP server couldn't start up every hour.
A better solution is to write a little shell script that checks to see if proftpd is running or not (using ps or something), and runs it only if it is not already running. This won't fill up your log files.
You can't make a symlink with arguments. To do what you want with apachectl, you should create a shell script and put that in /etc/cron.hourly. Try something like this:
#! /bin/sh
cmd=/usr/local/apache2/bin/apachectl
if $cmd status
then : # Apache is running
else $cmd start # Apache was stopped: start it again.
fi
That should work, but check the exit code from "apachectl status" to see if I've gotten the test right. I don't remember just what it returns in various conditions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.