Bash script can't find file
php /srv/www/domain.com/public_html/item.php
However bash says that it can't find the file.
From the command line this command works:
file /srv/www/domain.com/public_html/item.php
From my bash script that same command does not work, it says it can't find the file.
Must be something basic I'm missing here?
8 Replies
@rebrunius:
I have a bash script that wants to run a php script like this:
php /srv/www/domain.com/public_html/item.php
However bash says that it can't find the file.
From the command line this command works:
file /srv/www/domain.com/public_html/item.php
From my bash script that same command does not work, it says it can't find the file.
Must be something basic I'm missing here?
Can you clarify what it is that isn't found specifically? (Maybe paste the actual output?
If it's really bash saying that it can't find the file, I assume it would be php that can't be found (different PATH?)?
' (No such file or directory)w/php-insite.com/public_html/iptablesxyz/iptableDatabaseBuild.php
Notably, the error notice is not quoting the full path. The full path which I've echoed from the script is:
/srv/www/php-insite.com/public_html/iptablesxyz/iptableDatabaseBuild.php
php -f '/srv/www/php-insite.com/public_html/iptablesxyz/iptableDatabaseBuild.php'
@rebrunius:
It's not php that it can't find. Even using the file command it comes back with the following error (exact quote):
' (No such file or directory)w/php-insite.com/public_html/iptablesxyz/iptableDatabaseBuild.php
Note the error message has overwritten the first part of the filename. This likely means your bash script is in DOS format and has a CR-LF line ending. So the bash script is trying to open ….Build.php^M (control-M at the end) which, of course, doesn't exist.
"dos2unix" will convert it to Unix format.
Thanks
However, crontab does not recognize any file with a period in it so you can't use the ".sh" extension for those crontab scripts. That sucks?
run-parts
> If neither the –lsbsysinit option nor the --regex option is given then the names must consist entirely of upper and lower case letters, digits, underscores, and hyphens.
The reason is that there may be files in those directories that should not be executed (e.g., those ending in .dpkg-old or .dpkg-dist, or editor backup files ending in ~). It's just one of those quirks that you have to file away in the back of your head.
Note that you can create a symbolic link without a dot to a file with a dot, e.g. ln -s /root/backup.sh /etc/cron.daily/backup and it will be run.