LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why csh script was made a mistake with Crontab in Ubuntu Linux? (https://www.linuxquestions.org/questions/linux-newbie-8/why-csh-script-was-made-a-mistake-with-crontab-in-ubuntu-linux-4175447559/)

dtvietbk02 01-28-2013 11:22 AM

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!

thesnow 01-28-2013 11:28 AM

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.

shivaa 01-28-2013 11:53 AM

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


jpollard 01-28-2013 12:22 PM

If the script is marked as executable you can drop the "csh" part and just use /path/to/script

shivaa 01-28-2013 09:08 PM

Quote:

Originally Posted by jpollard (Post 4879205)
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


dtvietbk02 01-29-2013 12:43 AM

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.

jpollard 01-29-2013 07:27 AM

Quote:

Originally Posted by shivaa (Post 4879504)
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.

thesnow 01-29-2013 07:51 AM

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.

dtvietbk02 01-29-2013 08:38 AM

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


All times are GMT -5. The time now is 04:49 PM.