Why won't my script run?

On the following script that I get an error when I try to execute as root:

#./mv_log.sh
bash: /root/util/mv_log.sh: Permission denied

#!/usr/bin
datetag=`date --date='1 day ago' +"%b%d%Y"`

logname=`find /opt/bea/wlserver6.1/config//logs/ -iname 'access.log0' -mtime -1 -print`

mv $logname $logname.$datetag

It will run just fine if I do this

# . ./mv_log.sh

What am I missing? I would like to run this from crontab.

Try checking the file permissions on that script, and changing it as necessary to have execute permissions. :slight_smile:

you could do a "chmod +x mv_log.sh" and it should run.

The first line:
#!/usr/bin
should be #!/usr/bin/sh or #!/usr/bin/ksh, or which ever shell you use.
When run as a script (./script_name), it tries to use /usr/bin as an interpreter, which of course a directory can not do.
When you source it ( . ./script_name ), it takes the # to mean it's a comment, so ignores it and executes the rest.

Also, dont forget to give the full filepath from root in the crontab file (in addition to changing the mode of file as told by doeboy)

The file has permissions set to 770.

I changed to #!/bin/bash and that fixed it.

Thanks LivinFree, doeboy, & inpavan.