Asked  2 Years ago    Answers:  5   Viewed   93 times

I want to display all the files that are modified after a specified date

the commands are

touch --date '2011-09-19 /home/  , find /home/

How i can execute this two commands in single exec statement.Thanks in advance



You can use either a ; or a && to separate the comands. The ; runs both commands unconditionally. If the first one fails, the second one still runs. Using && makes the second command depend on the first. If the first command fails, the second will NOT run.

command1 ; command2     (run both uncondtionally)
command1 && command2     (run command2 only if command1 succeeds)
Sunday, August 28, 2022

Add 2>&1 to the end of your command to redirect errors from stderr to stdout. This should make it clear what's going wrong.

Monday, December 19, 2022

Try phpseclib, that'll work.


    $server = "myserver";
    $username = "myadmin";
    $password = "mypass";
    $command = "ps";

    $ssh = new Net_SSH2($server);
    if (!$ssh->login($username, $password)) {
        exit('Login Failed');

    echo $ssh->exec($command);
Saturday, August 13, 2022

It seems that you want to implement an interactive shell, yet you need to control individual commands execution. That's not really possible with just SSH interface. "shell" channel in SSH is black box with an input and output. So there's nothing in Paramiko that will help you implementing this.

If you need to find out when a specific command finishes or where an output of a specific command ends, you need to use features of a shell.

You can solve that by inserting a unique separator (string) in between and search for it in the channel output stream. With a common *nix shells something like this works:

channel = ssh.invoke_shell()
channel.send('cd /mytargetRepn')
channel.send('echo unique-string-separating-output-of-the-commandsn')

Though I do not really think that you need that very often. Most commands that are needed to make a specific commands working, like cd or set, do not really output anything.

So in most cases you can use SSHClient.exec_command and your code will be a way simpler and more reliable:
Execute multiple commands in Paramiko so that commands are affected by their predecessors

Even if you need to use something seemingly complex like su/sudo, it is still better to stick with SSHClient.exec_command:
Executing command using "su -l" in SSH using Python

For a similar question (for "exec" channel), see:
How to get each dependent command execution output using Paramiko exec_command

Thursday, September 22, 2022

You can implement your own test runner, for example by extending PHPUnit_TextUI_TestRunner and make it collect and print run times.

Sunday, November 20, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :

Browse Other Code Languages