How to get the output of channel.exec_command(cmd) while usingparamiko ?

S

sactiw

Hi Friends,
I am trying to create a file on remote machine and then
setting its file permissions to remote only thus now this file will act as a
lock for me and as any body else now can't create same file on that machine
and when my work is over I will reset the file permissions and then delete
the file. Thus in our team we can use this mechanism to acquire and release
lock on a remote machine.

Problem is that I using Python thus to run remote command means I have to
use paramiko module present in site-package.

Now problem which I am facing are:

- How can I make the channel.exec_command(cmd) to return its exit code.

- Problem is that when i run the lock acquiring code then even though in
that code after creating the file
using touch command it changes the file's permissions to read only but
then also any other person is
able to create file with same name on same location running the same lock
acquiring code that I had ran.
In short for the second person the lock acquiring code should fail ahs he
is using touch command to
create a file of same name which already exists with RO file permissions.
So how can I avoid that ?

Thanks in Advance.

-sactiw
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top