LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-21-2015, 04:51 AM   #1
pbr85at
LQ Newbie
 
Registered: Mar 2015
Posts: 2

Rep: Reputation: Disabled
Cron ignoring changes made in file


Hi,

i have a small problem on my system... I recently wrote a small bash script and added it via crontab -u root -e and it's executed as it should.
Then a few days after i did edit my bash script, but once it is run by cron it doesn't reflect the changes i made to the script. I did manually restart crond, tryed sync, moved my script, renamed it even rstart the server - no success.
If i run my script manually it returns me the expected output.
part of my script (/root/sd.sh):
Code:
#!/bin/sh

echo -n "Checking Raid... "
RAID=`tw-cli /c0/u0 show status | cut -c17-31 | grep -ci OK`
RAIDSTATUS=`tw-cli /c0/u0 show status | head -n1 | cut -c17-31`
if [ $RAID -eq 0 ]; then
  VERIFYING=`tw-cli /c0/u0 show status | cut -c17-31 | grep -ci VERIFYING`
  REBUILDING=`tw-cli /c0/u0 show status | cut -c17-31 | grep -ci REBUILDING`
  if [ $VERIFYING -eq 1 ]; then
    CURRENTSTATUS=`tw-cli /c0/u0 show verifystatus | head -n1 | cut -c46-49`
  fi
  if [ $REBUILDING -eq 1 ]; then
    CURRENTSTATUS=`tw-cli /c0/u0 show rebuildstatus | head -n1 | cut -c47-50`
  fi
  echo "Raid is busy (Raid $RAIDSTATUS$CURRENTSTATUS)"
  exit 1
fi
echo "Raid is idle (Raid $RAIDSTATUS)"

echo -n "Checking for logged in Users... "
USERS=`who | wc -l`
if [ $USERS -gt 0 ]; then
  echo "Users online"
  exit 1
fi
echo "None logged in"
crontab -l :
Code:
root@monster:~# crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
*/10 * * * * /root/sd.sh | logger
*/30 * * * * /root/dropbox.sh > /dev/null
syslog:
Code:
Mar 21 09:10:01 monster /USR/SBIN/CRON[3998]: (root) CMD (/root/sd.sh | logger)
Mar 21 09:10:01 monster logger: Checking Raid... Raid is busy (Raid )
Mar 21 09:17:01 monster /USR/SBIN/CRON[4045]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 21 09:20:01 monster /USR/SBIN/CRON[4105]: (root) CMD (/root/sd.sh | logger)
Mar 21 09:20:01 monster logger: Checking Raid... Raid is busy (Raid )
Mar 21 09:30:01 monster /USR/SBIN/CRON[4266]: (root) CMD (/root/sd.sh | logger)
Mar 21 09:30:01 monster /USR/SBIN/CRON[4265]: (root) CMD (/root/dropbox.sh > /dev/null)
Mar 21 09:30:01 monster logger: Checking Raid... Raid is busy (Raid )
when i run sh /root/sd.sh
Code:
root@monster:~# sh /root/sd.sh
Checking Raid... Raid is idle (Raid OK)
Checking for logged in Users... Users online
root@monster:~#
Any ideas why? - any help or thoughts appreciated

regards
Pat
 
Old 03-21-2015, 08:07 PM   #2
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 808

Rep: Reputation: 216Reputation: 216Reputation: 216
Normally you should not have to restart cron or anything. Cron reads the script on every invokation.

The problem is not obvious to me, but here are a few thoughts on how to debug it:

- I see that you manually invoked it with "sh /root/sd.sh"... Why not "/root/sd.sh"? That does not make it 100% comparable to the cron entry. Is your script executable at all? If it isn't, run
Code:
chmod +x /root/sd.sh
- To check that your script changes are seen by cron, add a line at the beginning of sd.sh that says something like
Code:
touch /tmp/cron.test
Is the file /tmp/cron.test created on the next cron run? If it is, this means that your problem is not that changes are not taken into account, but that something else still isn't quite right.

- Are you sure that everything was done under root? Maybe something is lying around in a user crontab?

- Note that you only have a very limited $PATH variable content in the cron environment. If your script calls other scripts (tw-cli ?) it's best to call them with their full path.

- Consider echoing the contents of your variables to a text file to check what they get assigned to. Maybe that'll give you a hint on what goes wrong.
 
1 members found this post helpful.
Old 03-22-2015, 08:12 AM   #3
pbr85at
LQ Newbie
 
Registered: Mar 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi, thank you for the hints - you were right, it's not cron ignoring my code, it's the issue in the script, especially what you pointed out below:

Quote:
Originally Posted by joe_2000 View Post
- Note that you only have a very limited $PATH variable content in the cron environment. If your script calls other scripts (tw-cli ?) it's best to call them with their full path.
i'm calling tw-cli not with it's full path /usr/sbin/tw-cli and it's working !!!
fyi, tw-cli is the cmd line interface for my 3ware hardware raid controller.

thank you very much

regards
Pat
 
Old 03-22-2015, 02:33 PM   #4
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 808

Rep: Reputation: 216Reputation: 216Reputation: 216
You are welcome, glad that you've been able to get it working
 
  


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
[SOLVED] cron.d is ignoring my script chaying Linux - Newbie 6 11-26-2010 12:18 AM
cron is ignoring lines... true_atlantis Linux - Software 4 04-09-2009 06:35 AM
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 09:09 AM
cron file 000-delay.cron (it is on my FC5) - what is the purpose? jtmoon Linux - Server 1 03-08-2007 12:15 PM


All times are GMT -5. The time now is 10:45 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