LinuxQuestions.org
Visit Jeremy's Blog.
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 02-18-2010, 02:31 PM   #1
danpaluska
LQ Newbie
 
Registered: Dec 2009
Location: new york city and sometimes boston and hopefully sometime somewhere warmer
Distribution: i'm trying to remain agnostic. but fedora and ubuntu so far.
Posts: 20

Rep: Reputation: 0
difference between cron and command line environment? shell script errors


so i have a few shell scripts that execute wonderfully when i type them at the command line but they fail when they are run from cron.

for example, if i run a script from command line that contains

Code:
shopt -s nullglob
to prevent problems with for f in *.mp4 type loops, it works fine from terminal command line but when called from cron, it gives an error->
Code:
/home/centralsqwall/Videos/videochecker.sh: 91: shopt: not found
a couple other random errors as well...

so there is some difference in the shell from cron and the terminal?

i'm running ubuntu 9.10, #!/bin/bash

what are the commands i should be using to echo my environment or simulate cron environment from the terminal?
 
Old 02-18-2010, 02:49 PM   #2
mpier
Member
 
Registered: Jan 2008
Location: Poland
Distribution: Slackware, Arch
Posts: 38

Rep: Reputation: 17
Hi,
compare cron and terminal environments with env. Shopt is bash builtin, maybe shells are different.
 
Old 02-18-2010, 02:55 PM   #3
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
To add to mpiers comment, always give the full path of any command and make sure you change to the required working directory before running any commands.
 
Old 02-18-2010, 04:38 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
And to finish this off by changing your 'for f in *.mp4; do' loop to 'find /path -iname \*.mp4 -print0|xargs -0' you can do away with the nullglob and make sure spaces in file names won't break things...
 
  


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
Bash script works from command line, fails from cron cmfarley19 Linux - General 4 08-14-2009 12:24 PM
Script runs fine from command line, but not when attempted from Cron hwest Linux - Newbie 8 12-11-2008 06:48 PM
[SOLVED] [bash]difference between script on command line and in file Wim Sturkenboom Programming 4 09-08-2008 02:20 AM
How to execute a command line in a shell script orgazmo Programming 5 05-09-2005 09:16 AM
script runs fine from a command line, but doesn't work from cron? kleptophobiac Linux - Software 5 05-03-2004 04:14 PM


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