Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Mon Nov 19, 2012 5:12 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
I have a bash script that wants to run a php script like this:

Code:
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:

Code:
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?


Top
   
PostPosted: Mon Nov 19, 2012 5:23 pm 
Offline
Senior Member

Joined: Fri Dec 10, 2010 6:21 am
Posts: 144
rebrunius wrote:
I have a bash script that wants to run a php script like this:

Code:
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:

Code:
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?)?


Top
   
PostPosted: Mon Nov 19, 2012 5:57 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
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

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


Top
   
PostPosted: Mon Nov 19, 2012 6:35 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
Try putting the filename in single quotes:

php -f '/srv/www/php-insite.com/public_html/iptablesxyz/iptableDatabaseBuild.php'


Top
   
PostPosted: Mon Nov 19, 2012 7:21 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
That works. :D


Top
   
PostPosted: Mon Nov 19, 2012 9:07 pm 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
rebrunius wrote:
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.

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
PostPosted: Tue Nov 20, 2012 4:02 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
I am using Notepad++ for the shell scripts and it does have a selection for Windows or Unix which I just changed to Unix. It seems to be helping. Notepad++ also recognizes the .sh extension and formats the source presentation nicely when it recognizes it.

Thanks


Top
   
PostPosted: Sun Nov 25, 2012 8:52 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
"Notepad++ also recognizes the .sh extension and formats the source presentation nicely when it recognizes it"

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?


Top
   
PostPosted: Sun Nov 25, 2012 9:26 pm 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
This is actually not a crontab behavior; it's the behavior of run-parts which is what executes the scripts in /etc/cron.hourly/, /etc/cron.daily/, and so on:
Quote:
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group