Running Commandline Scripts Through PHP

The name of the pictureThe name of the pictureThe name of the pictureClash 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.




  1. my PHP file used



    exec("sudo path/to/my/myscript.sh 2>&1");



to call the bash script




  1. 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?










share|improve this question









New contributor




TotoTornado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • "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















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.




  1. my PHP file used



    exec("sudo path/to/my/myscript.sh 2>&1");



to call the bash script




  1. 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?










share|improve this question









New contributor




TotoTornado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • "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













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.




  1. my PHP file used



    exec("sudo path/to/my/myscript.sh 2>&1");



to call the bash script




  1. 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?










share|improve this question









New contributor




TotoTornado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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.




  1. my PHP file used



    exec("sudo path/to/my/myscript.sh 2>&1");



to call the bash script




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






share|improve this question









New contributor




TotoTornado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




TotoTornado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









JigglyNaga

3,062626




3,062626






New contributor




TotoTornado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Oct 4 at 13:36









TotoTornado

1




1




New contributor




TotoTornado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





TotoTornado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






TotoTornado is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • "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

















  • "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
















"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
















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






TotoTornado is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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



































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.









 

draft saved


draft discarded


















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.













 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay