LinuxQuestions.org
Help answer threads with 0 replies.
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 03-18-2015, 12:23 AM   #1
rajbhandari.manish
LQ Newbie
 
Registered: Feb 2015
Posts: 3

Rep: Reputation: Disabled
Automating script to run every minute through other manually created user using crond


Hy All,

I have two nodes running RHEL 6.4 which are in cluster. I have clustered httpd service. Now I have certain application suppose X which reside in SAN partition. Now my job is to only automate this script to run by analyzing httpd status. I have successfully created the script apptrigger.sh whose content is given below,

-bash-4.1$ cat apptrigger.sh
a=0
b=0
c=0
d=0
a="service httpd status"
b=`eval $a`
##### CHECKING WHETHER HTTPD SERVICE IS RUNNING OR NOT #####
if [ "$b" != "httpd is stopped" ]; then
c="bash /switchapp/switch/ezlinkenterprise/bin/ezlink-cluster.sh status"
d=`eval $c`
##### CHECKING WHETHER EZ IS RUNNING OR NOT #####
if [ "$d" != "EzTaskMgr is Running" ]; then
ezstart
fi
fi

I have created this script in say test user. Now when I put this script to automate or run every minute through test user and defined its value in crontab -e of test user whose content is as shown below
$crontab -l
* * * * * /bin/bash /home/test/apptrigger.sh

but this script is running as root user so I cannot get the o/p
I think some environment variable need to be set. Anyone can guide me with this step? Thanks for your views and suggestion.
 
Old 03-18-2015, 12:48 AM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
Please use code tag to put your code / script as it becomes difficult to read otherwise. So this is the script:

Code:
a=0
b=0
c=0
d=0
a="service httpd status"
b=`eval $a`
##### CHECKING WHETHER HTTPD SERVICE IS RUNNING OR NOT #####
   if  [ "$b" != "httpd is stopped" ]; then
       c="bash /switchapp/switch/ezlinkenterprise/bin/ezlink-cluster.sh status"
       d=`eval $c`
##### CHECKING WHETHER EZ IS RUNNING OR NOT #####
   if [ "$d" != "EzTaskMgr is Running" ]; then
      ezstart
   fi
   fi
The script which is written by you and is in your crontab should not get execute with root user privilege. I mean this is a major security breach if it is happening.

Does this user has got full sudo access or how did you check if it running by root? I don't see any where are redirecting the output or the result so where you are expecting the output. I also don't see any echo statement which could show anything on the screen, so when you say you don't see output what do you mean by that?
 
  


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
Script runs Manually but not in Cron, yet other parts of the script run mccartjd Linux - Newbie 5 01-08-2012 07:54 PM
Script won't run in crontab.... only manually ScorchPipe Linux - Newbie 7 03-22-2011 11:11 AM
Need to run a script for any user logged in every minute unassassinable Linux - Desktop 21 02-24-2011 04:39 PM
[SOLVED] script not running via crontab, run's fine manually astroboiii Linux - Software 10 02-08-2010 11:36 PM
Newly created user can't run kde neeyo Linux - General 4 04-11-2002 04:29 PM


All times are GMT -5. The time now is 08:39 PM.

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