Running Commandline Scripts Through PHP
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am having difficulties running bash scripts with
php's exec() and wanted to get some suggestions.
I would love to be more flexible in this area because I can
see a lot of potential for my small intranet if I combine the
power of a commandline language. Thus far using bash
with php has been problematic and I am wondering if there
might be a better combination to try. Other Recommendations
welcome! I am not sure what other options are available.
Anyway, I thought I might tell how I got to where I am
currently stuck.
BEFORE
Ubuntu Mate running a LAMP setup
I had been using a raspberry pi as my server but
recently upgraded to a bigger machine. In the past
I was able to use php to run a few bash scripts
that gave me more flexibility with my program.
I use these bash scripts in some cases with sudo
rights to do things like mount a network drive...
I accomplished this before by editing my sudoers
file and giving apache(user = www-data) privileges
to run those particular bash scripts only. The bash scripts
did a few different things.
One task that I frequently needed to do was to mount a windows
network share to my ubuntu pi.
my PHP file used
exec("sudo path/to/my/myscript.sh 2>&1");
to call the bash script
then the bash script initiated a mount using a command like
sudo mount -t cifs -o username=XXXXX,password=XXXXX WindowsMountAddress UbuntuSystemMountPoint
It all worked consistently....and other scripts and commmands
executed fine as well.
NOW
Ubuntu 18.04 running LAMP
Since migrating my system, I have been UNABLE to
mount my network share using the bash script approach described
above.
I can mount the share with commandline fine. If I run the the php file that then calls my script which in turn mounts the drive... it is fine too.... All is good from commandline.
Here is the strange thing that I don't get...
Before I was checking to see what was mounted using the command....
mount -t cifs
I hooked this into my same pipeline
PHP exec calls bash script runs commandline
If there was a call to my function to mount the Windows network drive I would
check to see if it was mounted first.
The weird thing is this shows entries even when the mount is not working.
If I run the PHP page to mount... it will continue to add entries here but...
in fact the folder is not properly mounted. So using webpages and apache adds entries and also returns no errors. It is like apache is mounting the folder but the files are just not there.... If I a page refresh and have three entries in my report... and then go to commandline to check the report again....
Running the same command (mount -t cifs) on the actual commandline shows
nothing.... in commandline... only "real" mounts show. Only mounts issued via commandline...
It is almost like apache has one view and when I use root on commandline it has another. But the following command suggests apache is not running in a chroot:
ls -l /proc/2304/root
lrwxrwxrwx 1 root root 0 Oct 5 19:10 /proc/2304/root -> /
Any ideas on this or alternatives for this problem would be appreciated.
Incidently, I used these scripts because I am on a network where dynamic IPs
are assigned so I was using a few scripts to first check the IP of my Windows
share and then mount the folder when needed.
As I said... I really want more flexibility... I would be willing to dive into another programming language if it hooked up nice with php in some fashion and I could get access to the sudo commandline with less hassle. Suggestions?
mount sudo php cifs exec
New contributor
 |Â
show 6 more comments
up vote
0
down vote
favorite
I am having difficulties running bash scripts with
php's exec() and wanted to get some suggestions.
I would love to be more flexible in this area because I can
see a lot of potential for my small intranet if I combine the
power of a commandline language. Thus far using bash
with php has been problematic and I am wondering if there
might be a better combination to try. Other Recommendations
welcome! I am not sure what other options are available.
Anyway, I thought I might tell how I got to where I am
currently stuck.
BEFORE
Ubuntu Mate running a LAMP setup
I had been using a raspberry pi as my server but
recently upgraded to a bigger machine. In the past
I was able to use php to run a few bash scripts
that gave me more flexibility with my program.
I use these bash scripts in some cases with sudo
rights to do things like mount a network drive...
I accomplished this before by editing my sudoers
file and giving apache(user = www-data) privileges
to run those particular bash scripts only. The bash scripts
did a few different things.
One task that I frequently needed to do was to mount a windows
network share to my ubuntu pi.
my PHP file used
exec("sudo path/to/my/myscript.sh 2>&1");
to call the bash script
then the bash script initiated a mount using a command like
sudo mount -t cifs -o username=XXXXX,password=XXXXX WindowsMountAddress UbuntuSystemMountPoint
It all worked consistently....and other scripts and commmands
executed fine as well.
NOW
Ubuntu 18.04 running LAMP
Since migrating my system, I have been UNABLE to
mount my network share using the bash script approach described
above.
I can mount the share with commandline fine. If I run the the php file that then calls my script which in turn mounts the drive... it is fine too.... All is good from commandline.
Here is the strange thing that I don't get...
Before I was checking to see what was mounted using the command....
mount -t cifs
I hooked this into my same pipeline
PHP exec calls bash script runs commandline
If there was a call to my function to mount the Windows network drive I would
check to see if it was mounted first.
The weird thing is this shows entries even when the mount is not working.
If I run the PHP page to mount... it will continue to add entries here but...
in fact the folder is not properly mounted. So using webpages and apache adds entries and also returns no errors. It is like apache is mounting the folder but the files are just not there.... If I a page refresh and have three entries in my report... and then go to commandline to check the report again....
Running the same command (mount -t cifs) on the actual commandline shows
nothing.... in commandline... only "real" mounts show. Only mounts issued via commandline...
It is almost like apache has one view and when I use root on commandline it has another. But the following command suggests apache is not running in a chroot:
ls -l /proc/2304/root
lrwxrwxrwx 1 root root 0 Oct 5 19:10 /proc/2304/root -> /
Any ideas on this or alternatives for this problem would be appreciated.
Incidently, I used these scripts because I am on a network where dynamic IPs
are assigned so I was using a few scripts to first check the IP of my Windows
share and then mount the folder when needed.
As I said... I really want more flexibility... I would be willing to dive into another programming language if it hooked up nice with php in some fashion and I could get access to the sudo commandline with less hassle. Suggestions?
mount sudo php cifs exec
New contributor
"it is almost like apache has one view and when I use root on commandline it has another...". Is your apache running in a chroot?
â JigglyNaga
Oct 4 at 15:42
Hmmm.... first I heard of chroot. How would I check?
â TotoTornado
Oct 4 at 16:28
See where its/proc/<pid>/root
points (from unix.stackexchange.com/questions/156471/⦠)
â JigglyNaga
Oct 4 at 16:37
If I run the page that is supposed to mount my share and thenps -ef
... the report says root made the mount request it is listed as root 2915 command [cifssd]
â TotoTornado
Oct 5 at 1:54
Thanks... I am kind of learning as I go here... the output for that is...lrwxrwxrwx 1 www-data www-data 0 Oct 5 17:09 /proc/self/root -> /
This would indicate it is not chroot right? Guessing from what I read in various posts but have no real idea to be honest....
â TotoTornado
2 days ago
 |Â
show 6 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am having difficulties running bash scripts with
php's exec() and wanted to get some suggestions.
I would love to be more flexible in this area because I can
see a lot of potential for my small intranet if I combine the
power of a commandline language. Thus far using bash
with php has been problematic and I am wondering if there
might be a better combination to try. Other Recommendations
welcome! I am not sure what other options are available.
Anyway, I thought I might tell how I got to where I am
currently stuck.
BEFORE
Ubuntu Mate running a LAMP setup
I had been using a raspberry pi as my server but
recently upgraded to a bigger machine. In the past
I was able to use php to run a few bash scripts
that gave me more flexibility with my program.
I use these bash scripts in some cases with sudo
rights to do things like mount a network drive...
I accomplished this before by editing my sudoers
file and giving apache(user = www-data) privileges
to run those particular bash scripts only. The bash scripts
did a few different things.
One task that I frequently needed to do was to mount a windows
network share to my ubuntu pi.
my PHP file used
exec("sudo path/to/my/myscript.sh 2>&1");
to call the bash script
then the bash script initiated a mount using a command like
sudo mount -t cifs -o username=XXXXX,password=XXXXX WindowsMountAddress UbuntuSystemMountPoint
It all worked consistently....and other scripts and commmands
executed fine as well.
NOW
Ubuntu 18.04 running LAMP
Since migrating my system, I have been UNABLE to
mount my network share using the bash script approach described
above.
I can mount the share with commandline fine. If I run the the php file that then calls my script which in turn mounts the drive... it is fine too.... All is good from commandline.
Here is the strange thing that I don't get...
Before I was checking to see what was mounted using the command....
mount -t cifs
I hooked this into my same pipeline
PHP exec calls bash script runs commandline
If there was a call to my function to mount the Windows network drive I would
check to see if it was mounted first.
The weird thing is this shows entries even when the mount is not working.
If I run the PHP page to mount... it will continue to add entries here but...
in fact the folder is not properly mounted. So using webpages and apache adds entries and also returns no errors. It is like apache is mounting the folder but the files are just not there.... If I a page refresh and have three entries in my report... and then go to commandline to check the report again....
Running the same command (mount -t cifs) on the actual commandline shows
nothing.... in commandline... only "real" mounts show. Only mounts issued via commandline...
It is almost like apache has one view and when I use root on commandline it has another. But the following command suggests apache is not running in a chroot:
ls -l /proc/2304/root
lrwxrwxrwx 1 root root 0 Oct 5 19:10 /proc/2304/root -> /
Any ideas on this or alternatives for this problem would be appreciated.
Incidently, I used these scripts because I am on a network where dynamic IPs
are assigned so I was using a few scripts to first check the IP of my Windows
share and then mount the folder when needed.
As I said... I really want more flexibility... I would be willing to dive into another programming language if it hooked up nice with php in some fashion and I could get access to the sudo commandline with less hassle. Suggestions?
mount sudo php cifs exec
New contributor
I am having difficulties running bash scripts with
php's exec() and wanted to get some suggestions.
I would love to be more flexible in this area because I can
see a lot of potential for my small intranet if I combine the
power of a commandline language. Thus far using bash
with php has been problematic and I am wondering if there
might be a better combination to try. Other Recommendations
welcome! I am not sure what other options are available.
Anyway, I thought I might tell how I got to where I am
currently stuck.
BEFORE
Ubuntu Mate running a LAMP setup
I had been using a raspberry pi as my server but
recently upgraded to a bigger machine. In the past
I was able to use php to run a few bash scripts
that gave me more flexibility with my program.
I use these bash scripts in some cases with sudo
rights to do things like mount a network drive...
I accomplished this before by editing my sudoers
file and giving apache(user = www-data) privileges
to run those particular bash scripts only. The bash scripts
did a few different things.
One task that I frequently needed to do was to mount a windows
network share to my ubuntu pi.
my PHP file used
exec("sudo path/to/my/myscript.sh 2>&1");
to call the bash script
then the bash script initiated a mount using a command like
sudo mount -t cifs -o username=XXXXX,password=XXXXX WindowsMountAddress UbuntuSystemMountPoint
It all worked consistently....and other scripts and commmands
executed fine as well.
NOW
Ubuntu 18.04 running LAMP
Since migrating my system, I have been UNABLE to
mount my network share using the bash script approach described
above.
I can mount the share with commandline fine. If I run the the php file that then calls my script which in turn mounts the drive... it is fine too.... All is good from commandline.
Here is the strange thing that I don't get...
Before I was checking to see what was mounted using the command....
mount -t cifs
I hooked this into my same pipeline
PHP exec calls bash script runs commandline
If there was a call to my function to mount the Windows network drive I would
check to see if it was mounted first.
The weird thing is this shows entries even when the mount is not working.
If I run the PHP page to mount... it will continue to add entries here but...
in fact the folder is not properly mounted. So using webpages and apache adds entries and also returns no errors. It is like apache is mounting the folder but the files are just not there.... If I a page refresh and have three entries in my report... and then go to commandline to check the report again....
Running the same command (mount -t cifs) on the actual commandline shows
nothing.... in commandline... only "real" mounts show. Only mounts issued via commandline...
It is almost like apache has one view and when I use root on commandline it has another. But the following command suggests apache is not running in a chroot:
ls -l /proc/2304/root
lrwxrwxrwx 1 root root 0 Oct 5 19:10 /proc/2304/root -> /
Any ideas on this or alternatives for this problem would be appreciated.
Incidently, I used these scripts because I am on a network where dynamic IPs
are assigned so I was using a few scripts to first check the IP of my Windows
share and then mount the folder when needed.
As I said... I really want more flexibility... I would be willing to dive into another programming language if it hooked up nice with php in some fashion and I could get access to the sudo commandline with less hassle. Suggestions?
mount sudo php cifs exec
mount sudo php cifs exec
New contributor
New contributor
edited 2 days ago
JigglyNaga
3,062626
3,062626
New contributor
asked Oct 4 at 13:36
TotoTornado
1
1
New contributor
New contributor
"it is almost like apache has one view and when I use root on commandline it has another...". Is your apache running in a chroot?
â JigglyNaga
Oct 4 at 15:42
Hmmm.... first I heard of chroot. How would I check?
â TotoTornado
Oct 4 at 16:28
See where its/proc/<pid>/root
points (from unix.stackexchange.com/questions/156471/⦠)
â JigglyNaga
Oct 4 at 16:37
If I run the page that is supposed to mount my share and thenps -ef
... the report says root made the mount request it is listed as root 2915 command [cifssd]
â TotoTornado
Oct 5 at 1:54
Thanks... I am kind of learning as I go here... the output for that is...lrwxrwxrwx 1 www-data www-data 0 Oct 5 17:09 /proc/self/root -> /
This would indicate it is not chroot right? Guessing from what I read in various posts but have no real idea to be honest....
â TotoTornado
2 days ago
 |Â
show 6 more comments
"it is almost like apache has one view and when I use root on commandline it has another...". Is your apache running in a chroot?
â JigglyNaga
Oct 4 at 15:42
Hmmm.... first I heard of chroot. How would I check?
â TotoTornado
Oct 4 at 16:28
See where its/proc/<pid>/root
points (from unix.stackexchange.com/questions/156471/⦠)
â JigglyNaga
Oct 4 at 16:37
If I run the page that is supposed to mount my share and thenps -ef
... the report says root made the mount request it is listed as root 2915 command [cifssd]
â TotoTornado
Oct 5 at 1:54
Thanks... I am kind of learning as I go here... the output for that is...lrwxrwxrwx 1 www-data www-data 0 Oct 5 17:09 /proc/self/root -> /
This would indicate it is not chroot right? Guessing from what I read in various posts but have no real idea to be honest....
â TotoTornado
2 days ago
"it is almost like apache has one view and when I use root on commandline it has another...". Is your apache running in a chroot?
â JigglyNaga
Oct 4 at 15:42
"it is almost like apache has one view and when I use root on commandline it has another...". Is your apache running in a chroot?
â JigglyNaga
Oct 4 at 15:42
Hmmm.... first I heard of chroot. How would I check?
â TotoTornado
Oct 4 at 16:28
Hmmm.... first I heard of chroot. How would I check?
â TotoTornado
Oct 4 at 16:28
See where its
/proc/<pid>/root
points (from unix.stackexchange.com/questions/156471/⦠)â JigglyNaga
Oct 4 at 16:37
See where its
/proc/<pid>/root
points (from unix.stackexchange.com/questions/156471/⦠)â JigglyNaga
Oct 4 at 16:37
If I run the page that is supposed to mount my share and then
ps -ef
... the report says root made the mount request it is listed as root 2915 command [cifssd]â TotoTornado
Oct 5 at 1:54
If I run the page that is supposed to mount my share and then
ps -ef
... the report says root made the mount request it is listed as root 2915 command [cifssd]â TotoTornado
Oct 5 at 1:54
Thanks... I am kind of learning as I go here... the output for that is...
lrwxrwxrwx 1 www-data www-data 0 Oct 5 17:09 /proc/self/root -> /
This would indicate it is not chroot right? Guessing from what I read in various posts but have no real idea to be honest....â TotoTornado
2 days ago
Thanks... I am kind of learning as I go here... the output for that is...
lrwxrwxrwx 1 www-data www-data 0 Oct 5 17:09 /proc/self/root -> /
This would indicate it is not chroot right? Guessing from what I read in various posts but have no real idea to be honest....â TotoTornado
2 days ago
 |Â
show 6 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
TotoTornado is a new contributor. Be nice, and check out our Code of Conduct.
TotoTornado is a new contributor. Be nice, and check out our Code of Conduct.
TotoTornado is a new contributor. Be nice, and check out our Code of Conduct.
TotoTornado is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473242%2frunning-commandline-scripts-through-php%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
"it is almost like apache has one view and when I use root on commandline it has another...". Is your apache running in a chroot?
â JigglyNaga
Oct 4 at 15:42
Hmmm.... first I heard of chroot. How would I check?
â TotoTornado
Oct 4 at 16:28
See where its
/proc/<pid>/root
points (from unix.stackexchange.com/questions/156471/⦠)â JigglyNaga
Oct 4 at 16:37
If I run the page that is supposed to mount my share and then
ps -ef
... the report says root made the mount request it is listed as root 2915 command [cifssd]â TotoTornado
Oct 5 at 1:54
Thanks... I am kind of learning as I go here... the output for that is...
lrwxrwxrwx 1 www-data www-data 0 Oct 5 17:09 /proc/self/root -> /
This would indicate it is not chroot right? Guessing from what I read in various posts but have no real idea to be honest....â TotoTornado
2 days ago