Jump to content
adi003user

ajutor python

Recommended Posts

Sal,

Vreau un script in python care sa scrie un fisier txt intr-un share de windows.

am inteles ca trebuie sa folosesc WNetAddConnection2. Am tot citit pe net si majoritatea solutiilor se bazeaza pe mount. Eu nu vreau mount.

am gasit scriptul asta bash de ex dar eu vreau in python

#/bin/bash
SERVER_IP="10.10.1.5"
SHARE_NAME="c$"
USR_NAME="myusername"
USR_PASSWORD="mypassword"
DOMAIN="mydomain"
mount.cifs //$SERVER_IP/$SHARE_NAME -o username=$USR_NAME,password=$USR_PASSWORD,dom=$DOMAIN /mnt/Bluecoatman/

Link to comment
Share on other sites

Sal,

Vreau un script in python care sa scrie un fisier txt intr-un share de windows.

am inteles ca trebuie sa folosesc WNetAddConnection2. Am tot citit pe net si majoritatea solutiilor se bazeaza pe mount. Eu nu vreau mount.

am gasit scriptul asta bash de ex dar eu vreau in python

#/bin/bash
SERVER_IP="10.10.1.5"
SHARE_NAME="c$"
USR_NAME="myusername"
USR_PASSWORD="mypassword"
DOMAIN="mydomain"
mount.cifs //$SERVER_IP/$SHARE_NAME -o username=$USR_NAME,password=$USR_PASSWORD,dom=$DOMAIN /mnt/Bluecoatman/

Ti`l fac eu deseara daca vrei, ti`l fac in python dar trebuie sa folosesc tot mount.cifs pentru ce vrei tu sa faci

Acum cum vrei, eu trebuie sa plec dar revin pe la 21:00

EDIT: Scuze man dar abia acum am ajuns in camera. Hai ca ma apuc sa ti`l scriu si il postez

Link to comment
Share on other sites

Done. M`am gandit mai bine si cred ca voi face un tutorial sa stie tot omul sa share-uiasca intre Windows si Linux si vice-versa. ;-)

Sa imi zici daca ceva nu iti merge sau ai nevoie de ceva in plus

Bafta

#/usr/bin/env python
import os
import getpass
print "\n\nAtentie, inainte de a rula acest script trebuie sa creezi directorul unde vrei sa fie mountat share-ul (path-ul absolut) eg: /home/user\n"
server = raw_input("1. Introdu ip-ul serverlului ")
shared = raw_input("2. Introdu numele directorului share-uit ")
user = raw_input ("3. Introdu userul ")
password = getpass.getpass("4. Introdu parola ")
location = raw_input ("6. Introdu locatia unde vrei sa fie mountat ")
fisier = raw_input ("7. Introdu numele fisierului pe care vrei sa il creezi in folderul share-uit ")
text = raw_input ("8. Introdu textul pe care vrei sa il scrii in fisier ")
mountare = "mount.cifs //%s/%s %s -o username=%s,password=%s" % (server,shared,location,user,password)
scriere = "echo '%s\n' >> %s/%s" % (text,location,fisier)
os.system(mountare)
os.system(scriere)

Edit: Am uitat sa iti spun ca eu am probat si merge brici ;-)

Edit2: Desigur, puteai sa ti-l modifici cum vrei :P. Nu ai pt ce

  • Upvote 1
Link to comment
Share on other sites

Multumesc.

L-am adaptat putin deoarece trebuie sa ruleze la 10 min

#!/usr/bin/python
import os
print "\n\nMountul trebuie sa fie deja existentr\n"
server = "ip"
shared = "share"
user = "user"
password = "pass"
location = "/root/kit" #funny
fisier = "test.txt"
text = "fuck eco-drives"
mountare = "mount.cifs //%s/%s %s -o username=%s,password=%s" % (server,shared,location,user,password)
scriere = "echo '%s\n' >> %s/%s" % (text,location,fisier)
os.system(mountare)
os.system(scriere)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...