Reputation: 231
I'm trying to run a Python script remotely via ssh local for a Linux machine but I'm getting an error when my script is reading a txt file, the script is running well without errors on my Python IDE.
I'm using ssh root@ip_adress python2 < script.py
to run the script.
Part of my script where i'm reading the txt file:
import os
import smtplib
with open("file.txt") as fp:
conteudo = fp.readlines()
conteudo = [linhas.strip() for linhas in conteudo]
Error:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
IOError: [Errno 2] No such file or directory: 'file.txt'
Upvotes: 1
Views: 531
Reputation: 231
The main problem is that the file.txt only exist on my computer, so for that to work i would need a direct connection to my server to share my filesystem with it, but that's unsafe. So i decided to transfer the file.txt to my server using scp file.txt root@ip_adress:/path/where/the/file/is/going/to
and then i had to change the path in the "with open() as" function to the path where my file was going to. After that i was able to execute the script without errors.
Upvotes: 1