bash scripting cannot executed in crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash scripting cannot executed in crontab
# 1  
Old 11-11-2005
bash scripting cannot executed in crontab

hi guys,
i have a problem.

a week ago i made a successful crontab that execute bash scripting daily, it worked well

but now, it doesn't work at all, in the mail i have:
"
/home/jimmy/cha/scripts/cekpderr

produced the following output:

lagi jalan
/home/jimmy/cha/scripts/cekpderr: isql: command not found
nawk: can't open file /home/jimmy/cha/db/cekpderr.db
source line number 1
isi variabel var adalah
/home/jimmy/cha/scripts/cekpderr: [: =: unary operator expected
cat: cannot open /home/jimmy/cha/db/cekpderr.db
"

i wonder why suddenly the crontab cannot execute the isql command.

and...
when i execute the script manually, not with crontab, it works well and produce the expected result

i have also tried to run the crontab using another user in the same group.

please help guys...

thanks before
# 2  
Old 11-11-2005
Check for your crontab environment i.e and compare with your shell environment where your script did successful.
# 3  
Old 11-11-2005
still doesn't work

thanks for helping ,

but i can't find the crontab environment like u said.

i have also tried to run the crontab using other user's login, and it still doesn't work.

is there more idea friend?
# 4  
Old 11-11-2005
you searched the forums FAQs, you would've found this. Smilie
# 5  
Old 11-11-2005
again :)

i think i get what u said,

the crontab env lies in "/etc/crontab"

but i am not the root

i cannot even "cat /etc/crontab"

how do i change the crontab environment SHELL to bash?

thanks
# 6  
Old 11-11-2005
Quote:
Originally Posted by jimmbp
i think i get what u said,

the crontab env lies in "/etc/crontab"

but i am not the root

i cannot even "cat /etc/crontab"

how do i change the crontab environment SHELL to bash?

thanks
for example...... if all your needed environment seetings are done in your $HOME/.profile file:
Code:
0,30 * * * * [ -f /home/jimmy/.profile ] && . /home/jimmy/.profile && /home/jimmy/cha/scripts/cekpderr

# 7  
Old 11-11-2005
This part in the Cron tutorial speaks to your problem:

It works from the command line but not in crontab

This is perhaps our number one complaint with cron. When you login to Unix, startup scripts setup your environment. You can see your environment with the commands "printenv" or "env". On the other hand, cron sets up only a sparse environment (See Problem with crontab for the details.)

I think that the best solution is to write shell scripts that set up their own environment and run these via cron. That's what worked in not running in cron.

In ping from cron, the user used an absolute path rather than redefining the PATH environment variable.

In this thread: Cron problem?, the user sourced the .profile file to set up the environment and it worked. But that technique caused a problem in stty: tcgetattr: Not a typewriter And I also think that it sets you up for a mysterious problem. Change .profile and your cronjobs may suddenly fail.

Check that part out and the links provided. They should point you in the right direction. Good Luck.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to detect and fix why crontab job is not executed?

I have set several cron jobs. I recently added a new cron job that copies a file of last day from another server and is executed each day (for example at 04:00 am) but when I check next day the file hasn't been copied. I'm working in GNU/Linux CentOS (2.6.32) system. The files that I need to... (23 Replies)
Discussion started by: Ophiuchus
23 Replies

2. Shell Programming and Scripting

To check if the JAVA Program is successfully executed in sh shell scripting

Hi , I have written a shell script to call a java program say load_id.sh .This sh script indeed is executed implicitly in other sh script which calls 2 more sh scripts one by one. I need to check if the load_id.sh (which calls java program) is executed successfully only then continue with... (1 Reply)
Discussion started by: preema
1 Replies

3. Shell Programming and Scripting

Linux/bash Script only working if executed from shell prompt

Hi, maybe I'm asking a VERY dumb question, but would anybody out there tell me, why this f****** script won't work if executed as a cronjob, but works fine if executed from a shell prompt? #! /bin/bash set PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin date >>... (3 Replies)
Discussion started by: beislhur
3 Replies

4. UNIX for Dummies Questions & Answers

Bash script dont works when executed as cronjob

Hello, i have cronjob: crontab -l * * * * * pkill -f domexpcheck;sh /root/dom/domexpcheck.sh it runs: /var/log/cron Mar 25 12:11:01 vps crond: (root) CMD (pkill -f domexpcheck;sh /root/dom/domexpcheck.sh) but somehow script dont run properly via cronjob. But when i execute cronjob... (7 Replies)
Discussion started by: postcd
7 Replies

5. Shell Programming and Scripting

crontab job not executed with variables

Hi, I am trying to execute a script (for once) during the booting time in Ubuntu system. However, the result is only showing the strings without without the variables. Here is the script: MgrIp=$(ec2-describe-instances --filter tag:Name=Mgr --filter instance-state-name=running | egrep... (4 Replies)
Discussion started by: turki_00
4 Replies

6. Shell Programming and Scripting

Users who desire to have their .profile executed must explicitly do so in the crontab entry. Why?

The .profile file should be read when the user logs in. So, there should be no need to execute .profile file again in a cron job (since the cron job is run after the user logs in). Doesn't the cron require login from the user. Then, from where does the cron execute? Please help!! (1 Reply)
Discussion started by: thulasidharan2k
1 Replies

7. Shell Programming and Scripting

can't executed bash from PHP..

dear list, i've just write a simple php script to add user to my iptables, but some times it works and it dosn't work,, here's my script for my adduser.php <?php exec('/var/www/html/backup.sh'); $hash = "# $_POST\n"; $ip = "-A INPUT -p tcp -m tcp -s $_POST -d 10.10.105.18 --dport 8080 -j... (2 Replies)
Discussion started by: ridwanfi
2 Replies

8. Shell Programming and Scripting

Routine doesn't give output when executed in crontab

I have a script running in the crontab that gets data from a database every hour. Now I would like to execute a fortran routine to process the data in some way, after getting it and saving it locally. I have added the following commands to my script: set convert =... (1 Reply)
Discussion started by: SharkM
1 Replies

9. Shell Programming and Scripting

how to make a bash script that can be executed by people simultaneously?

dear friends, i want to make a bash script that can be executed by many people simultaneously. do you have any idea to make it? there will be many dependent-variables(which is input from people) in the scripts. i am thinking about a random temporary file that created by the bash script each... (4 Replies)
Discussion started by: jimmbp
4 Replies

10. Shell Programming and Scripting

Shell script doesn't get executed using crontab

I have the following crontab entry to run a shell script for every 30 minutes of every day: 30 * * * * $HOME/main.sh > $HOME/main.log 2>$HOME/error.log after I created the crontab file I have also done: $crontab my_crontab I also check to make sure it exists, by using the following... (11 Replies)
Discussion started by: radhika
11 Replies
Login or Register to Ask a Question