Wolf
Wolf

Reputation: 15

Python Script doesn´t work when started via other script

I´m currently working on a raspberry pi 4 and wrote a script in python that send a mail with a picture and then rename the file and puts it in another folder.

The script works fine when I start with command

sudo python script.py

but when start it with another script it won´t execute the part with the renaming

Now the question what is my mistake ?

import os
import time
from sendmail import mail
from sendmail import file_rename
from time import sleep

pic = '/home/pi/Monitor/Bewegung.jpg'
movie= '/home/pi/Monitor/Aufnahme.avi'
archiv = '/home/pi/Archiv/'
time = time.strftime('%d.%m.%Y %H:%M')


mail(filename = pic )

file_rename(oldname = pic ,name = 'Serverraum Bild' + time ,format = '.jpg' ,place = archiv )

file_rename(oldname = movie ,name = 'Serverraum Video' + time ,format = '.avi' ,place = archiv )

Upvotes: 0

Views: 62

Answers (1)

leiflundberg
leiflundberg

Reputation: 344

I see that you are starting the script as a user with sudo privileges.

but when start it with another script it won´t execute the part with the renaming

This makes me suspicious that the caller script does not have the correct permissions to rename/move a file. You can view the permissions of the script with the following command

ls -la callerscript.py

Upvotes: 1

Related Questions