简体   繁体   中英

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 )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM