Crontab with bash


 
Thread Tools Search this Thread
Operating Systems HP-UX Crontab with bash
# 1  
Old 02-23-2010
Crontab with bash

hi,

i have a big problem with executing a bash script via crontab. I put the following line in the crontab:

Code:
0,10,20,30,40,50 * * * * /usr/bin/bash /home/tes/ausgabescript.sh > /dev/null 2>&1

/bin/bash and /bin/ksh doesen't work also.
When I save the following line appears: warning: commands will be executed using /usr/bin/sh

So I think my script uses the sh shell, but if I run the script with /usr/bin/sh /home/tes/ausgabescript.sh I will got a syntax error in the line of creating an array.

Does someone know how I can execute my script via bash? If I run my script normaly on the bash-shell, everything works fine.

my system is B.11.11
# 2  
Old 02-23-2010
Remove /usr/bin/bash from your crontab entry. Add as first line, even before the 1st comments) the shebang in your script with shell you want to use:

Code:
#!/usr/bin/bash

...
..<here comes your script and comments etc>
.

# 3  
Old 02-23-2010
There is no need of specifying the /usr/bin/bash in the crontab entry. Instead of that you can give sh simply. So it will automatically execute the sh command from where the sh command is located. (/usr/bin/sh)

Last edited by thillai_selvan; 02-23-2010 at 05:16 AM..
# 4  
Old 02-23-2010
#!/usr/bin/bash is already the first line of my script.

If i make no entry the script is executed via sh and that does not work.
# 5  
Old 02-23-2010
If #!/usr/bin/bash is already the first line of your script, just be sure its executable!
There is nothing more to do ( and no it is not executed by sh since this first line means:
open a new shell - This one (bash) to execute the following lines...)
# 6  
Old 02-23-2010
I logon on the server, then type bash then execute the script ./script.sh (everything works fine). Script is executeable (chmod u+x)

If I run the script with /usr/bin/sh I will get this error: Syntax error at line 12 : `(' is not expected.

This is the line in the script:
Code:
IFS='
' x=($(/opt/H/script -1|grep hidst))

(the second line is 12)

On the console with bash the script works perfect, but crontab seems not to be able to execute my script with bash.
# 7  
Old 02-23-2010
The message
Code:
warning: commands will be executed using /usr/bin/sh

just means that any commands you specified in the crontab are run by passing them to sh -c. So your command will be run similar to
Code:
sh -c '/usr/bin/bash /home/tes/ausgabescript.sh'

If that works, so will your command.

The warning is IMO a historical remnant from the time when users actually tried to program using the C Shell, which has a very different syntax from the Bourne/Korn Shell
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

3. Shell Programming and Scripting

Bash to select text and apply it to a selected file in bash

In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you :) ... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Simple Bash Script - Crontab

I've put together a very simple bash script to check for software patches and bounce the server, once complete. This is on a Mac server. The script works just fine upon execution, however, cron responds with: /bin/sh: /usr/local/bin/softwareupdates.sh: No such file or directory Crontab: ... (6 Replies)
Discussion started by: Nvizn
6 Replies

5. Shell Programming and Scripting

Bash script acting funny when run from Crontab

Hello, first time here. I have a script that seems to ignore the if statement when run from the cron. I am using Ubuntu 12.10 #!/bin/bash DOWN=/usr/sbin/dcon UP="pon dsl-provider" LOG=/var/log/dsl-reconnect.log RECV=`ifconfig 2>&1|grep ppp0|cut -d , -f 5|cut -d " " -f 1` if ] then... (1 Reply)
Discussion started by: mkoster
1 Replies

6. Shell Programming and Scripting

Cannot get this bash/expect script to run under a crontab

#!/bin/bash # # RAP configuration script # # Usage: ./rap.sh # # Requires: expect, tcl # # Script expects to find a file called rap.csv located in the same directory as the script. If the file is placed # in a different directory, modify the custom entries section to specify the absolute... (8 Replies)
Discussion started by: mrkool
8 Replies

7. Linux

Problem with crontab + bash script

Crontab: 16 14 * * * /root/bin/./empty_mail.sh >> /root/bin/log.txt L=`mailq |grep -c frozen` echo "${NUMMAIL} frozen mail to be removed from the mailq" #echo "Press Enter to continue" #read CONTINUE echo -en "-> " for i in `mailq | grep frozen | awk '{print $3}'` ; do exim4 -Mrm $i... (1 Reply)
Discussion started by: wessberg
1 Replies

8. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

9. UNIX for Dummies Questions & Answers

how to execute sh script in bash shell via crontab

hello. we are porting over from HPUX Shell to Linux. my default shell is bash so i can no longer schedule to execute a sh script in crontab. can anyone pls help me out? I searched the site but didnt find any details. thanks! (1 Reply)
Discussion started by: jigarlakhani
1 Replies

10. Shell Programming and Scripting

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:... (6 Replies)
Discussion started by: jimmbp
6 Replies
Login or Register to Ask a Question