FoxTribune
FoxTribune

Reputation: 113

How to exec the shell script in PHP

I'm making PHP script to move shell script. when hoge < 50.

Code is this. Does it OK?

When I use that script , I click this link.

http://localhost/index.php?hoge=30

<?php
if(isset($_GET['hoge'])) {
    $hoge = $_GET['hoge'];
    print("$hoge<br>\n");
}
if ($hoge > 50 ){
    echo 'F1';
}        
elseif ($hoge == 50) {
    echo 'F2';
} else {
    echo 'F3';
    exec(' /Users/hoge/Desktop/test.sh');
}
?>

Upvotes: 0

Views: 65

Answers (1)

Dejora
Dejora

Reputation: 44

You can add a test like

   if (file_exists('/Users/hoge/Desktop/test.sh')) {
    exec('/Users/hoge/Desktop/test.sh');
    } else {
    echo 'NO FILE'
    }

Check also that the file /Users/hoge/Desktop/test.sh is executable

Upvotes: 2

Related Questions