#Bash - Do some stuff, do some more, shut my system down..
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Interesting, great explanation. I tried to do the less trick but it gave 'cannot edit standard input <press return>'. I will try to play with these settings although it seems unnecessary, I have 1 user & root, which is both me. Bash does not even allow me to sudo things, I have to su - root if I want to do stuff from command line. That's why I want to make a php-script of it and then just su & php runmything.php the question is will it run from command line when I
Code:
<?php echo 'shutdown -h now'; ?>
NOPASSWD: NOEXEC: seems like a really handy trick when working with multiple users
That's why I want to make a php-script of it and then just su & php runmything.php the question is will it run from command line when I
Code:
<?php echo 'shutdown -h now'; ?>
That would just print the string "shutdown -h now" to the screen, it wouldn't actually run anything.
If you want to run a command line program from php you need to use exec(), eg:
Code:
exec("ps -f -p " . $pid,$output,$retval);
to run ps -f -p on whatever process ID is contained in the variable $pid, and save the output of the command to the variable $output and the return value to the variable $retval.
Just as you answered I tried a test-script, so I found out it wasn't working. Indeed it just echoes. However with the exec(), I should be able to come up with something. Thanks.
Ah Firerat, on my macbook now but will try it out tomorrow. If someone has an agenda of compromising the security of computers I doubt this topic would be of much interest to him/her. If anything I think it's great you point out the potential risks.
I still have a lot to learn in those command line- editors. For now I've just learned how to use the command line a bit. I'll probably wallpaper the bedroom with cheat sheets, to get me there faster. Loving this distro, easy enough to get it all up and running, hard enough to learn some stuff. (Hate those fancy gui packet management tools almost as much as I hate 'app stores'.) Good responsive forum to ask questions, feeling confident that I'll be finding my way.
On topic, I will post what I come up with when I do. Thanks again.
So far it works fine with command line commands.
For example:
Code:
passthru ('clamscan -r -i /home/') . PHP_EOL;
However:
Code:
exec('/var/www/something.php'); //does not work
passthru('/var/www/something.php'); //does not work
$pid = '/var/www/something.php';
exec("ps -f -p " . $pid,$output,$retval); //does not work.
What am I not seeing here? It's needed to run a php-script to update a database I have.
The problem that the terminal gives me has to do with the processing of the php file. As in every php file it starts with <?php and ends with ?>. The terminal will give me an error when executing a php file from within a popen/passthru/exec command because it will process <?php again literally. So I think the problem with the execution is that it will read <?php inside the already existing tags. Like <html><html> bla </html></html> for html-script, does that make sense? I tried to let the terminal ignore the tags with
Code:
php -R something.php
as I read something about ignoring those tags, but no luck with that either. So far I've come up with a cool script that does almost everything I want it to. Just not execute php. This would not pose a serious problem, but I think I would want to learn it for future reference.
Is what I have so far, works fine and will be adding more to it in the future. Pretty simple way of batching stuff up.
Code:
Retrieve spots for the last time..
/var/www/html/spotweb/retrieve.php: line 1: ?php: No such file or directory
/var/www/html/spotweb/retrieve.php: line 2: syntax error near unexpected token `2147483647'
/var/www/html/spotweb/retrieve.php: line 2: `error_reporting(2147483647);'
Last edited by rockhopper_penguin; 10-26-2013 at 01:27 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.