Used to run commands via shell on remote host.
Environment variables like $HOSTNAME or operations like *, <, >, |, ;, & will not work. See shell to use these.
These docs were used in the creation of this page.
def test_fun(duthosts, rand_one_dut_hostname):
duthost = duthosts[rand_one_dut_hostname]
free_form_ret = duthost.command("ls -ltr")
cmd_ret = duthost.command(cmd="ls -ltr")
argv_ret = duthost.command(argv=["ls", "-ltr"])
argv- command as list of strings containing main command and its options- Required:
Trueifcmdor free-form argument is not provided,Falseotherwise. - Type:
List- Element-Type:
String
- Element-Type:
- Required:
chdir- change into specified directory before running- Required:
False - Type:
String
- Required:
cmd- The command to be run as a string with space dilineated options.- Required:
Trueifargvor free-form argument is not provided,Falseotherwise - Type:
String
- Required:
creates- filename. If a matching file already exists, command will not be run.- Required:
False - Type:
String
- Required:
removes- filename. If matching file exists, command will be run- Required:
False - Type:
String
- Required:
stdin- Set the stdin command directly to the specified value- Required:
False - Type:
String
- Required:
stdin_add_newline- ifTrue, newline is appended to stdin data- Required:
False - Type:
Boolean - Default:
True
- Required:
strip_empty_ends- Strips empty lines from end of stdout/stderr- Required:
False - Type:
Boolean - Default:
True
- Required:
warn- Enable or disable task warnings (deprecated)- Required:
False - Type:
Boolean - Default:
False
- Required:
Dictionary with information on command output:
cmd- the command executed by taskdelta- the command execution timeend- The command end timemsg- whether the associated task was in achangedstaterc- return code for commandstart- the command execution start timestderr- The standard error as a stringstderr_lines- The standard error as a list of stringsstdout- the standard output as a stringstdout_lines- the standard output as a list of strings