LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 04-08-2008, 01:45 AM   #1
sobo32
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Rep: Reputation: 0
my script shell not works automaticaly


my script shell is the follow

#!/bin/bash
Njour=$(date +%A|awk '{print toupper($1)}')

if [[ $Njour == JEUDI ]]
then
echo '====== backup JEUDI =========' >> /tmp/log.cron
else
echo '====== backup NON JEUDI =====' >> /tmp/log.cron
fi


my script work normaly with command line but it not works with unix cron
#ls -lrt test.sh
-rwx------ 1 root root 1760 apr 4 2008 test
#whoami
root
#crontab -l

00 11 * * * /home/test.sh

can anyone help me
 
Old 04-08-2008, 07:36 AM   #2
cmnorton
Member
 
Registered: Feb 2005
Distribution: Ubuntu, CentOS
Posts: 585

Rep: Reputation: 35
Shell Script Location

Is your shell script really in /home or in /home/your_login?
 
Old 04-08-2008, 07:41 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Also check the root mail to see the standard output and the standard error of the crontab job, or use redirection to put messages in a file:
Code:
00 11 * * * /home/test.sh > /root/crontab.log 2>&1
 
Old 04-09-2008, 03:46 AM   #4
sobo32
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
yes my script is locate in /home but I'm root user .. changing crontab
# crontab -l
00 11 * * * /home/test.sh > /tmp/crontab.log 2>&1

always not works and my out file crontab.log is empty also the file /tmp/log.cron

?????
 
Old 04-09-2008, 05:11 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If the file /tmp/crontab.log has been created, the crontab job has been executed (unless you have created it before). First, you can verify if the crontab works properly with a simple command, like this
Code:
00 11 * * * /bin/echo crontab test > /tmp/log.cron
Second, have you checked if root has received some mail from the cron daemon, before you added the redirection to crontab.log?
 
Old 04-09-2008, 09:05 AM   #6
sobo32
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
my crontab now is :
#crontab -l
00 11 * * * /home/test.sh
00 11 * * * /bin/echo 'crontab test' > /tmp/log.cron

firstly I deleted a file /tmp/log.cron for testing if the file log.cron is created or not ..
the result is : no file with name "log.cron" in /tmp directory

???
 
Old 04-09-2008, 09:06 AM   #7
sobo32
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
in more i don't any mail in root box ??
 
Old 04-09-2008, 12:16 PM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Is the cron daemon up and running?
Code:
ps -C crond    # On redhat-based
ps -C cron     # On other systems
 
Old 04-09-2008, 03:40 PM   #9
sshd.root
LQ Newbie
 
Registered: Jan 2008
Posts: 17

Rep: Reputation: 0
Defaults, cron deamon write messages in log files. What do you see in logs files?
 
Old 04-12-2008, 03:34 AM   #10
sobo32
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
my crond is up and where is the log file that the crond write ??
 
Old 04-12-2008, 08:31 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Look at /var/log/messages.
 
Old 04-20-2008, 09:05 AM   #12
sobo32
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
ok my script works now !!!!!! thanks 5/5
 
Old 04-20-2008, 11:52 AM   #13
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Which problem was it?
 
Old 04-21-2008, 03:34 AM   #14
sobo32
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
when I execute the scripts with command line the variable Njour is :
# Njour=$(date +%A|awk '{print toupper($1)}')
# echo $Njour
LUNDI
# echo $LANG
fr_FR.UTF-8

but when I excute with cron I must change my test

if [[ $Njour == MONDAY ]]

So it is a problem of variable LANG
 
  


Reply



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 connecting to erlang shell works only in interactive mode ineya Linux - Server 1 10-25-2007 07:05 AM
Command that works on BASH promp but not from a shell script! ChrisScott Linux - General 4 11-27-2006 07:11 PM
Shell Script to kill a process automaticaly brazilian_user Programming 11 06-12-2006 09:09 PM
Shell script works on RH 7.2 but not on RH ES brian Red Hat 1 08-31-2004 11:55 AM
Shell Script that misbehaves under Linux but works in HP UX well... ksh environ. sammathew Linux - Software 7 09-17-2003 08:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 06:59 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
Open Source Consulting | Domain Registration