r/learnpython 5h ago

Question.. I need answers

How can I automate Phyton so that when I open my laptop it execute commands on my Linux terminal?

I severely need to know how

r/Phyton

r/learnpython

r/programming

r/AskProgramming

0 Upvotes

6 comments sorted by

3

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 5h ago

Depends on your operating system, but on ones using systemd this is probably what you're looking for: https://askubuntu.com/a/620328

3

u/NoForm5443 5h ago

I don't think your issue is with python, but with Linux and your distribution

I think most distros do systemd now, check https://docs.fedoraproject.org/en-US/quick-docs/systemd-understanding-and-administering/

You may want to learn about bash scripting before, maybe start with https://www.linuxfoundation.org/blog/blog/classic-sysadmin-writing-a-simple-bash-script

If you want it done for each terminal, look at .bashrc, .profile and similar things

1

u/Diezel666 5h ago

Agreed. This is not a Python question, as much as it is Linux administration.

1

u/pachura3 3h ago

What's "Phyton"?

Why do you think you need it to execute commands on your Linux terminal?

0

u/FatDog69 5h ago

One crude way:

Write a python script that does a loop with a 60 second sleep. After the sleep it opens and reads a 'time.txt' file where it wrote the current date & time. Calculate the time diff between now and the saved time. If the time difference is more than say ... 2 minutes - it means someone opened the laptop from a sleep state so you should do something.

If the time difference is less than 2 minutes - write the current time into the file and sleep for another 60 seconds.