LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-24-2008, 01:01 AM   #1
UltraSoul
Member
 
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404

Rep: Reputation: 31
I can execute shell script from CLI but failed to do via cron


I created the following shell to mount/umount network-shared volume.

1> I succeed to execute the shell script to mount/umount my win2003`s filesystem.
2> I tried to enable the shell execution in crontab as follows.
0-30/5 4 * * * sh /net-vol/mount_shell &
3> /var/log/cron tolds me that the crontab has been enabled successfully. But the shell execution seems not to be executed.
I must add the ". /etc/profile" in the head of the shell script so that
mount_shell can mount/umount normally via cron.

4> I think /etc/profile should be executed during system boot. And the
shell script under crontab should inherit all environments viariables.
And I can manually execute the shell without the line of ". /etc/profile". Pls help

======= The last two lines of /etc/profile ===========
. $ENV/`hostname`/env01
. $ENV/`hostname`/env02

================ mount_shell content ====================
#!/bin/sh
### Mount files to /mnt/interchk ####

# . /etc/profile ==> Now, I must add the line for shell execution via crontab.

. $ENV/`hostname`/current-time.sh
mount -t cifs -o credentials=$PASSFILE //win2003/InterChk /mnt/interchk"

if [ $? -eq 0 ] ; then
echo "$CURRENT_TIME $HOSTNAME $PROC: mount /mnt/interchk -- Success " >> "$LOGFILE"
else
echo "$CURRENT_TIME $HOSTNAME $PROC: mount /mnt/interchk -- Failure " >> "$LOGFILE"
exit
fi
....
....

### Umount /mnt/interchk ###
sleep 60
. $ENV/`hostname`/current-time.sh
umount /mnt/interchk

if [ $? -eq 0 ] ; then
echo "$CURRENT_TIME $HOSTNAME $PROC: umount /mnt/interchk -- Success " >> "$LOGFILE"
else
echo "$CURRENT_TIME $HOSTNAME $PROC: umount /mnt/interchk -- Failure " >> "$LOGFILE"
fi

Last edited by UltraSoul; 06-24-2008 at 01:06 AM.
 
Old 06-24-2008, 06:06 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
[QUOTE]I think /etc/profile should be executed during system boot. And the
shell script under crontab should inherit all environments viariables./QUOTE]

This is the problem here. Scripts running from cron don't run on the normal system shell, they run on their own isolated shell. Environment variables that work when you are logged into the system and running the script interactively won't work when it is running via cron. There are also issues with the $PATH variable and installed binaries, though I don't think that is coming into play here.
 
Old 06-24-2008, 10:10 PM   #3
UltraSoul
Member
 
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404

Original Poster
Rep: Reputation: 31
Hi, MS3FGX


Any idea about making crontab task to inherit environment? /etc/crontab edit?
 
  


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
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
Script does not execute with cron Arty Ziff Linux - Newbie 14 05-23-2008 12:08 AM
How to set up cron job to execute bash script lgmqy2000 Linux - General 4 11-22-2006 04:29 AM
php script will not run correctly as cron, fine from cli dtra Linux - Software 2 12-22-2005 07:21 AM
cron issue, php script runs fine in browser and cli dtra Linux - Software 1 07-15-2005 05:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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