Welcome to the most active Linux Forum on the web.
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 07-12-2006, 02:18 AM   #1
Registered: Oct 2005
Posts: 540

Rep: Reputation: 32
cronjob questions


I have a forum software on my server that has been having trouble accessing the mySQL database, which is hosted on a different server. The problems can be either too many connections or lost connection. In an effort to restart Apache on the web server (this process somehow reset the connection to the mySQL server), the host has setup some cronjobs to do that. The following is a list of the user cronjob (apparently the "service httpd restart" line has not been working and so they added (cd /root; ./ 2>&1) also):
[root@vps ~]# crontab -l
#*/10 * * * * /root/
#59 */2 * * * /root/
# following is not working in case of httpd already in stop stat !! yes.. strange..
#*/15 * * * * service httpd restart

*/5 * * * * (cd /root; ./ 2>&1)
and ./ contains:

CNT=`ps ax | grep -v grep | grep -c httpd`

if [ $CNT -gt 10 ]

echo $CNT;
echo 'Restarting HTTPD...'

killall httpd
killall httpd
killall httpd
/etc/init.d/httpd restart


if [ $CNT -le 0 ]

/etc/init.d/httpd restart

Can someone please explain to me the following:
1) What exactly does (cd /root; ./ 2>&1) mean? I don't quite follow why we have to change directory to root, and what is this "2>&1" business.
2) What is going on in this ./ file? I really have no idea of what it's doing.
3) Is there a way to setup a .ps file to test the connection to mySQL and only restart if the connection is lost? (like maybe pinging the mySQL server to test the connection)
Old 07-12-2006, 02:31 AM   #2
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,705

Rep: Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496
1. The cmd ./ means run script found in 'current' dir (ie './' bit), so they change to /root where the script is (should be).
"2>&1" means copy stderr to stdout
2. script counts num of httpd processes, if cnt >10 logs a msg, kills them all (several times!), then does a restart.
If cnt <= 0, do a restart.
When I did my Apache admin course (1.3.x) at RedHat, they said that 'restart' could be a bit iffy, so always use 'stop' then 'start' instead. You should prob either wait a bit eg 5 secs, or check again eg in a loop, between stop and start; ie ensure Apache really has stopped before starting it.
iirc, theres a .pid file with the main process' pid in it.
3. .ps is usually a postscript file, so you've lost me there, but a ping or logon/off prog is certainly feasible.
Old 07-12-2006, 03:08 AM   #3
Registered: Oct 2005
Posts: 540

Original Poster
Rep: Reputation: 32

Ah I see. Thanks. It makes sense now. Just a few further questions:
1) Why the need to kill the process when Apache is going to restart anyway? Wouldn't restarting Apache kill the httpd process?
2) Why kill several times? Isn't "killall httpd" kills all already?
3) How's "/etc/init.d/httpd restart" different from "service httpd restart"?
4) Sorry made a mistake about ps file. I meant to say a sh file. :P Would you mind illustrating how to do this "ping or logon/off prog" process in a .ps file that I can add to the crontab? All that I want to do is to check the mySQL connection every once in a while with cron and if it's lost, just log off/on.


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
cronjob help meeh Linux - General 1 03-26-2004 12:41 PM
Cronjob engnet Linux - Networking 6 03-03-2004 10:21 AM
cronjob ugob Linux - Software 0 03-03-2004 10:20 AM
Su in a cronjob michedlp Programming 3 11-06-2003 09:30 AM
cronjob FastEddy Linux - General 1 04-12-2003 10:52 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:06 PM.

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