Crontab with bash

hi,

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

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

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:

#!/usr/bin/bash

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

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)

#!/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.

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...)

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:

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.

The message

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

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

Omg it's absolutely mysterious your command is also working without a problem. Now I renamed my script, an now crontab work with the script. But not right. There is a if-else-tie and crontab works only with the true part.
I don't understand why.

---------- Post updated at 05:06 AM ---------- Previous update was at 04:49 AM ----------

sry sry sry i found my fault.

I used aliases in my script, so with bash on the console it worked. But with crontab there are no aliases available.

Ok solved!

There is nothing stopping you to put a

. <myhome>/.profile 

in your cron bash script if you wish to use your aliases

When did /usr/bin/bash become available for HP-UX B.11.11 ?

bash-4.0.033 #sept 2009
But what does it bring more compared to hpux standard ksh?
I certainly would not use it for administration tasks...(compatibility purpose for a start...)

Thanks vbe. I didn't know that.