0

On Linux Machine A, i have a script running which is supposed to ssh into Linux Machine B, sync the p4 workspace on B and then execute a piece of code.

I've set up Perforce on B and I'm able to manually execute p4 client and other commands on B and they work.

However, when i attempt to do the same thing while sshing from Machine A, i get the following error:

Perforce client error: Connect to server failed; check $P4PORT. TCP connect to perforce:1666 failed. Temporary failure in name resolution

Here's my piece of code:

def ssh_connect(ip,user,pwd):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip, username=user, password=pwd)  
    return ssh


def execute_command(device_details, command):
    try:
        ip = device_details.get('ip')
        username = device_details.get('username')
        password = device_details.get('password')
        ssh_ns_obj = ssh_connect(ip, username, password)

        ssh_stdin, ssh_stdout, ssh_stderr = ssh_ns_obj.exec_command(command)
        print ssh_stdout.read()
        print ssh_stderr.read()
        print ssh_stdin.read()
        return ssh_stdout.read()
    except Exception as e:
        print_exception_details()      


perforce_sync_command = "cd /root/hello/;chmod -R 444 *;p4 sync ...;chmod -R 755 *"
output = execute_command(device_details, perforce_sync_command)

What am i missing?

syam
  • 799
  • 1
  • 12
  • 30
Randomly Named User
  • 1,889
  • 7
  • 27
  • 47

1 Answers1

1

Perforce needs a set of environment variables to run - on ssh, the environment variables were not visible on the ssh session.

To solve this, i edited the file /etc/environment and added the P4PORT, P4USER, P4CLIENT, P4PASSWD vars in the file.

Randomly Named User
  • 1,889
  • 7
  • 27
  • 47
  • 1
    A more standard way of doing this would be to either use the `p4 set` command (which writes to your `.p4enviro` file) or to specify the `-p PORT -u USER -c CLIENT` flags within the script. – Samwise Mar 22 '18 at 16:29