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 01-28-2013, 12:22 PM   #1
dtvietbk02
LQ Newbie
 
Registered: Jan 2013
Posts: 3

Rep: Reputation: Disabled
Why csh script was made a mistake with Crontab in Ubuntu Linux?


Dear Friends
I have csh script file as bellow:

#!/bin/csh -f


1/ When I run this script standalone by using command like this: csh scriptfile
The result was export correctly.
2/ Now I want to run this script every 6 hours in crontab of Ubuntu Linux 10.04. Unfortunately, it was made a mistake.
In crontab, I was set some parameters as bellow:
crontab -e
01 5-23/6 * * * csh /path/scriptfile

Please help me. Thanks a lot!

Last edited by dtvietbk02; 01-31-2013 at 08:15 AM. Reason: edit
 
Old 01-28-2013, 12:28 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
What is the error message you see when it runs from cron? You may need to explicitly set the PATH in your script for it to run correctly from cron.
 
Old 01-28-2013, 12:53 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Specify:
Operating system, because way of crontab entries creation may be different in different OS.
Any error message?
Output of:
Code:
~$ which csh
Also make crontab entry like:
Code:
~$ crontab -e
* 0,6,12,18 * * * csh /path/to/script
OR
* */6 * * * csh /path/to/script
 
Old 01-28-2013, 01:22 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
If the script is marked as executable you can drop the "csh" part and just use /path/to/script
 
Old 01-28-2013, 10:08 PM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by jpollard View Post
If the script is marked as executable you can drop the "csh" part and just use /path/to/script
Just having executable permissions on script does not mean to remove "csh" part.
It can be removed only if user's default shell and shebang (script interpreter) are same, then the script can be executed as:
Code:
~$ ./script.sh
OR
~$ /path/to/script.sh
Else, uesr will need to specify execution shell cmd with script, like:
Code:
~$ csh ./script.sh
OR
~$ csh /path/to/script.sh
 
Old 01-29-2013, 01:43 AM   #6
dtvietbk02
LQ Newbie
 
Registered: Jan 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
RE: Crontab in Ubuntu linux 10.04

Hi, Buddies
I tried to use with all your solution, but it's still not work correctly.

1/ When I run with csh scriptfile the result was exported like this
STATUS: 20130129-1419 (UTC: 2013 01 29 - 0619): Getting igu17252_06.sp3 wait 3 hrs

The file "igu17252_06.sp3" is exactly file that I want to download. You can refer to website: ftp://cddis.gsfc.nasa.gov/gps/products/1725/
(User: anonymous Pw: your email address) to get for more detail information.

2/ Regarding to crontab in Ubuntu Linux, actually it is NOT show any error message when running. However, the result is NOT showed correctly with the same method 1 (csh scriptfile).
STATUS: 20130129-1419 (UTC: 2013 01 29 - 0619) : Getting igu00063_-03.sp3 wait 3 hrs

As you can see two files are different name although it was run at the same time (UTC: 2013 01 29 - 0619). Only file name was show on method 1 (running script file standalone) correctly, and file name "igu00063_-03.sp3" was wrong. That's why my script can not download the file from website when I use crontab.

Please help me.

Last edited by dtvietbk02; 01-29-2013 at 01:46 AM.
 
Old 01-29-2013, 08:27 AM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by shivaa View Post
Just having executable permissions on script does not mean to remove "csh" part.
It can be removed only if user's default shell and shebang (script interpreter) are same, then the script can be executed as:
Code:
~$ ./script.sh
OR
~$ /path/to/script.sh
Else, uesr will need to specify execution shell cmd with script, like:
Code:
~$ csh ./script.sh
OR
~$ csh /path/to/script.sh
That would violate the use of "#!/bin/csh" done at the beginning of the script.

When a script file is marked executable, the first line is used to identify the interpreter, and any flags/parameters that may be required. The only time the users shell is used is when that first line does not have that specification. If the file starts with "#!" but no other specification then the users shell is used.

According to the the first post, the script has "#!/bin/csh -f" which should work just fine without having to use the csh explicitly.
 
Old 01-29-2013, 08:51 AM   #8
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
Can you post the full output of your script when run from cron and command line? It would also help to add an echo after you set each variable for debugging (echo $wd, etc.), so you can see the actual value the variable is getting.
 
Old 01-29-2013, 09:38 AM   #9
dtvietbk02
LQ Newbie
 
Registered: Jan 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Ok, I've get it working by changing crontab like:

# m h dom mon dow command
SHELL=/bin/csh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/abc
15 5-23/6 * * * csh /opt/abc/scriptfile restart

Thanks you for help
 
  


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
Deleted linux partition on a dual boot system...made mistake? shahidsaab1 Linux - Newbie 6 07-06-2006 01:38 AM
I made a mistake :( Megatog615 Slackware 11 04-15-2006 02:22 AM
Linux Mandrake 8.0 -- HELP I made a mistake during install and don't know how to fix! Avatar Linux - Software 9 07-27-2001 11:30 AM


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