Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8931877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:12:39+00:00 2026-06-15T09:12:39+00:00

I created a simple PHP site we would like to use to disable/enable ports

  • 0

I created a simple PHP site we would like to use to disable/enable ports on a cisco switch.
I am passing over two arguments (port and action) to a bash script via the php function exec(). For debugging I set those arguments at the end inside the bash script.

The important part of the php function I am calling looks like this:

function PortAction($port, $action){
    echo "<hr /> Port:".$port."<br />Action:".$action;
    chdir('/usr/local/icinga-1.7.0/videowand/');
    echo exec('sh /usr/local/icinga-1.7.0/videowand/action2.sh 2>&1',$output, $return);
    echo "Return / Output: ".$return;
    print_r($output);    
}

The bash script “action2.sh”:

#!/bin/bash
/usr/libexec/rancid/clogin -c "conf t; int Fa0/1; shutdown" 192.168.6.6

If i execute the bash script manually (or even the directly the clogin command) as apache user, it all works as expected, the port gets disabled.
But as soon as I call it over the PHP function, I get the output:

Array ( [0] => no such variable [1] => (read trace on “env(HOME)”) [2] => invoked from within [3] => “set password_file $env(HOME)/.cloginrc” [4] => (file “/usr/libexec/rancid/clogin” line 66)

And nothing gets done.
Which indicates some problem with the password entry (as far as I can see).
Permissions on this file(s) are correct, I guess they have to otherwise it wouldn’t work directly inside the shell.
Even tried to change the .cloginrc path using the -f switch, no success.
PHP Safe-mode: Off
Display errors: On

The script takes a while because a telnet connection needs to be opened. This is why I put this into a separate bash script.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:12:41+00:00Added an answer on June 15, 2026 at 9:12 am

    Provide the full path to the sh binary, like this:

    echo exec('/bin/sh /usr/local/icinga-1.7.0/videowand/action2.sh 2>&1',$output, $return);
    

    I’m assuming /bin/sh above, as that is commonly the standard path for sh, but make sure with
    which sh command.

    /bin/sh is a soft link to your shell, which usually is /bin/bash, I’m not sure exec() can work with soft links of binaries, so if above doesn’t works then just use /bin/bash instead of /bin/sh

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a very simple PHP page for a site, which
I created a simple PHP site for a friend last year. I went to
I would like to consume WCF service (created by ASP .NET) with PHP. I
How to manually create Friendly URLs? (PHP) So I have created simple php file
I've created a simple socket php 5.3 script where the server script calls... socket_select($read_set,
I would like to create a simple web statistics javascript code ( analytics )
What I would like to do is a simple HTML5 chatroom, nothing fancy, once
I would like to create simple serial key checker but it needs to be
I have a site that currently serves results as example.com/index.php?show=foo and I'd like it
I have a very simple website, and would like to create a 'Comments' section

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.