Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call bash script from php

Tags:

bash

php

web

I need to capture user input on a web form and pass it to a script to create a user account but I cannot get it to work. so far I have a add_user.sh script that reads like this:

adduser -u $NAME -p $PASS -g users -s /bin/bash

but im not sure if that's going to capture user entered data from the web form?

like image 213
user2938994 Avatar asked Mar 24 '26 00:03

user2938994


1 Answers

You can build it into a string and then use exec If your server has it enabled

$str = 'adduser -u ' . $NAME . ' -p ' . $PASS . ' -g users -s /bin/bash';
exec(escapeshellcmd($str));

I should have probably noted before, many hosts disable this and any functions that perform command line commands for security reasons. Just because this exists doesn't make it a good idea.

like image 131
Machavity Avatar answered Mar 26 '26 13:03

Machavity



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!