I created a Python script to execute Linux commands ...
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
I created a Python script to execute Linux commands ...
I got tired of using scraps of papers to save some usable commands so I created a script to run a lot of the Linux commands.
It does not change anything in the system. It just creates text files on the desktop with the results of the commands that are run.
I am not a Python scripter but I did my best to make a usable script. I put the script on github.
https://github.com/AriIris/LinuxEasyCommandCenter
Click on the green CODE button and download as a .zip file.
After unpacking the zip file go to that directory and edit the LinuxEasyCommandCenter.py file and replace the text 'put your password here' with your password. The password is necessary for many of the commands to run.
To run this script create a Launcher on the Linux desktop and point to the script file.
This script is free to use and share. You may change it to your liking.
If changed please rename it to not cause confusion with the original file name.
This script was developed on Linux Mint 20.2 with Python3 using PyCharm.
https://www.jetbrains.com/pycharm/
I am sure that the gurus could make a better script, however I did the best I could ... my first script.
I followed the download, unpack, edit and create launcher instructions and all worked okay.
There will be tabs to go through to look for commands. Some day I might put them in order.
You will see Run and Man buttons. The Man button is to get the manual documentation for that command.
Both buttons will put text files on the desktop starting with a lower case 'z' to keep them together.
Please give me some feedback.
I forgot to mention that many of the commands have comboboxs to choose switches.
Also when making a Launcher you give it a name and comment and then browse for my script, but
you then, when returned to the launcher creation, in front of the script name you must insert
'python3' without the semiquotes and a space.
UPDATE: I added some images at github
It does not change anything in the system. It just creates text files on the desktop with the results of the commands that are run.
I am not a Python scripter but I did my best to make a usable script. I put the script on github.
https://github.com/AriIris/LinuxEasyCommandCenter
Click on the green CODE button and download as a .zip file.
After unpacking the zip file go to that directory and edit the LinuxEasyCommandCenter.py file and replace the text 'put your password here' with your password. The password is necessary for many of the commands to run.
To run this script create a Launcher on the Linux desktop and point to the script file.
This script is free to use and share. You may change it to your liking.
If changed please rename it to not cause confusion with the original file name.
This script was developed on Linux Mint 20.2 with Python3 using PyCharm.
https://www.jetbrains.com/pycharm/
I am sure that the gurus could make a better script, however I did the best I could ... my first script.
I followed the download, unpack, edit and create launcher instructions and all worked okay.
There will be tabs to go through to look for commands. Some day I might put them in order.
You will see Run and Man buttons. The Man button is to get the manual documentation for that command.
Both buttons will put text files on the desktop starting with a lower case 'z' to keep them together.
Please give me some feedback.
I forgot to mention that many of the commands have comboboxs to choose switches.
Also when making a Launcher you give it a name and comment and then browse for my script, but
you then, when returned to the launcher creation, in front of the script name you must insert
'python3' without the semiquotes and a space.
UPDATE: I added some images at github
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: I created a Python script to execute Linux commands ...
Haven't yet checked your script, got sidetracked by your mentioning of PyCharm as I'm in search myself for a nice - but preferrably smaller and less resource-hungry though - Python tool/IDE.
Just a couple ideas for the script based on what you said above:
- take into consideration setups that do not ask for a password when running with sudo
- better create a folder somewhere in user's home dir, create a hardlink to it on the desktop and have the script save all those text files in that folder
Reasoning:
Some users (such as myself) may run with password requirement disabled so the script should be able to pass that stage.
Littering the desktop with text - or any kind of - files is not such a good idea. Keeping them all together is much easier and cleaner when they are all stored away in a dedicated folder accesible from the desktop.
Hope this helps somehow.
Just a couple ideas for the script based on what you said above:
- take into consideration setups that do not ask for a password when running with sudo
- better create a folder somewhere in user's home dir, create a hardlink to it on the desktop and have the script save all those text files in that folder
Reasoning:
Some users (such as myself) may run with password requirement disabled so the script should be able to pass that stage.
Littering the desktop with text - or any kind of - files is not such a good idea. Keeping them all together is much easier and cleaner when they are all stored away in a dedicated folder accesible from the desktop.
Hope this helps somehow.
Codeberg repo; old: @GitLab
Re: I created a Python script to execute Linux commands ...
Here is another idea for you.
I have been using a Perl script for about 2 decades now that opens Nemo in a particular folder. One line in my explore.txt file is this:
If I enter
If I enter
That explore.txt file has 1,360 lines in it! Some are set to open a file name in a program:
A very handy program to have. Like I say I have been using it for almost 20 years now.
I have been using a Perl script for about 2 decades now that opens Nemo in a particular folder. One line in my explore.txt file is this:
desktop|/usr/share/applications
If I enter
desktop
in the program (from within the terminal) it opens a Nemo window to /usr/share/applications
If I enter
term desktop
then it opens a terminal window pointed to /usr/share/applications
That explore.txt file has 1,360 lines in it! Some are set to open a file name in a program:
hf|/media/mike/disk1/Outdoors/HOC/Finances/HOC Financial Records.xls
A very handy program to have. Like I say I have been using it for almost 20 years now.
Re: I created a Python script to execute Linux commands ...
Good ideas guys.
I was very ill for quite some time.
I did alter the script to run on Windows to display many pages of information.
I was very ill for quite some time.
I did alter the script to run on Windows to display many pages of information.
Re: I created a Python script to execute Linux commands ...
I have updated this script to create a desktop directory which will contains all the output text files.
Also removed the leading file name characters 'z_', not necessary now.
I added page displays for Windows which are kept in a text file that is loaded into the script.
This script does not changed anything in the operating systems.
It does not access the Windows registry.
It does not send any information to me.
It would be nice to have someone check it out before I post it on Github.
Also removed the leading file name characters 'z_', not necessary now.
I added page displays for Windows which are kept in a text file that is loaded into the script.
This script does not changed anything in the operating systems.
It does not access the Windows registry.
It does not send any information to me.
It would be nice to have someone check it out before I post it on Github.
Re: I created a Python script to execute Linux commands ...
You might consider having your user password in a python script is acceptable. However it could be discovered by anybody with access to the computer (in person or online) and thus is a definite security risk.
-
- Level 1
- Posts: 18
- Joined: Mon Oct 24, 2022 12:24 am
Re: I created a Python script to execute Linux commands ...
i'm trying press button "man fdisk -i" and terminal write this:
What's a problem? And many others buttons cause this problems too.
Code: Select all
Traceback (most recent call last):
File "/usr/lib/python3.10/tkinter/__init__.py", line 1921, in __call__
return self.func(*args)
File "/home/oleg/Загрузки/LinuxEasyCommandCenter-main/LinuxEasyCommandCenter.py", line 634, in fdisk1b
Popen_Function_Common('man fdisk')
File "/home/oleg/Загрузки/LinuxEasyCommandCenter-main/LinuxEasyCommandCenter.py", line 572, in Popen_Function_Common
log = open(logpath + cmd2 + '.txt', 'w')
FileNotFoundError: [Errno 2] No such file or directory: '/home/oleg/Desktop/z_man fdisk.txt'
What's a problem? And many others buttons cause this problems too.
Re: I created a Python script to execute Linux commands ...
Great idea!reticulatus wrote: ⤴Mon Oct 24, 2022 6:50 am You might consider having your user password in a python script is acceptable. However it could be discovered by anybody with access to the computer (in person or online) and thus is a definite security risk.
I will change the script to accept a password when it first starts.
Re: I created a Python script to execute Linux commands ...
StrangeAngel wrote: ⤴Tue Oct 25, 2022 10:33 am i'm trying press button "man fdisk -i" and terminal write this:Code: Select all
Traceback (most recent call last): File "/usr/lib/python3.10/tkinter/__init__.py", line 1921, in __call__ return self.func(*args) File "/home/oleg/Загрузки/LinuxEasyCommandCenter-main/LinuxEasyCommandCenter.py", line 634, in fdisk1b Popen_Function_Common('man fdisk') File "/home/oleg/Загрузки/LinuxEasyCommandCenter-main/LinuxEasyCommandCenter.py", line 572, in Popen_Function_Common log = open(logpath + cmd2 + '.txt', 'w') FileNotFoundError: [Errno 2] No such file or directory: '/home/oleg/Desktop/z_man fdisk.txt'
What's a problem? And many others buttons cause this problems too.
Do you have PyCharm & Python installed along with 'tkinter'?
I'm learning Python on the fly. I think that the problem is that 'tkinter' is not found.
I don't know a way to use 'tkinter' without PyCharm.
I will be releasing a newer version of the script soon at Github.
-
- Level 1
- Posts: 18
- Joined: Mon Oct 24, 2022 12:24 am
Re: I created a Python script to execute Linux commands ...
I found the reason. Here it is necessary to write but not 'Desktop' for me. i'm using Russian version LInux mint.
Code: Select all
logpath = '/home/' + findme + '/Рабочий стол/z_'
Re: I created a Python script to execute Linux commands ...
I changed the script to prompt for a password.
If desired a password can be coded into the script and the password prompt will not appear.
However if the password is incorrect the Popen will hang, hence I had to add a timout for a
few seconds for specific commands and a couple of seconds for the remaining commands.
I bit tacky, but I don't know any other way to handle the hang.
I removed all the Windows code.
If desired a password can be coded into the script and the password prompt will not appear.
However if the password is incorrect the Popen will hang, hence I had to add a timout for a
few seconds for specific commands and a couple of seconds for the remaining commands.
I bit tacky, but I don't know any other way to handle the hang.
I removed all the Windows code.
Re: I created a Python script to execute Linux commands ...
The new script release will put a folder on the desktop and the command results in text files within that folder without the 'z_' characters.StrangeAngel wrote: ⤴Wed Oct 26, 2022 3:19 am I found the reason. Here it is necessary to writebut not 'Desktop' for me. i'm using Russian version LInux mint.Code: Select all
logpath = '/home/' + findme + '/Рабочий стол/z_'
What does the path to the desktop look like in the Russian version?
I wonder if the space is causing the problem? '/Рабочий стол/z_'
-
- Level 1
- Posts: 18
- Joined: Mon Oct 24, 2022 12:24 am
Re: I created a Python script to execute Linux commands ...
/home/oleg/Рабочий столMintmann wrote: ⤴Sat Oct 29, 2022 3:22 pmWhat does the path to the desktop look like in the Russian version?StrangeAngel wrote: ⤴Wed Oct 26, 2022 3:19 am I found the reason. Here it is necessary to writebut not 'Desktop' for me. i'm using Russian version LInux mint.Code: Select all
logpath = '/home/' + findme + '/Рабочий стол/z_'
Re: I created a Python script to execute Linux commands ...
Lets forget this version of the script. I have a new script and it works differently.
I plan to release it soon, like maybe tomorrow on Github. I'm currently testing it.
What I do to run the next script release named: 'LECC.py'.
Place the script somewhere on disk such as in Documents.
To make the script usable change its permissions to allow running it as a program
Start Terminal, cd to were you put the script and type: 'python3 LECC.py' without the semiquotes.
There might be a way to create a shortcut, but I have no idea how to do that yet.
I plan to release it soon, like maybe tomorrow on Github. I'm currently testing it.
What I do to run the next script release named: 'LECC.py'.
Place the script somewhere on disk such as in Documents.
To make the script usable change its permissions to allow running it as a program
Start Terminal, cd to were you put the script and type: 'python3 LECC.py' without the semiquotes.
There might be a way to create a shortcut, but I have no idea how to do that yet.
Re: I created a Python script to execute Linux commands ...
I have an idea: edit the script and change all 'Desktop' entries to 'Рабочий стол'.
Where did you get the Russian version of Mint 21 Cinnamon?
Where did you get the Russian version of Mint 21 Cinnamon?
Re: I created a Python script to execute Linux commands ...
According to this accepted reply at StackOverflow the correct code would be:
Please note the returned value is bytes and ends with a new line character.
import subprocess
subprocess.check_output(['xdg-user-dir', 'DESKTOP'])
Please note the returned value is bytes and ends with a new line character.
Codeberg repo; old: @GitLab
-
- Level 1
- Posts: 18
- Joined: Mon Oct 24, 2022 12:24 am
Re: I created a Python script to execute Linux commands ...
@StrangeAngel: could you please try the code above and post the result?
Just open a terminal, type
When finished press
Just open a terminal, type
python3
and hit Enter (or if it fails type python
and hit Enter), then type each of the two lines above and press Enter. It should yield the full path to the Desktop in system's language.When finished press
Ctrl+D
to exit the Python environment.Codeberg repo; old: @GitLab
Re: I created a Python script to execute Linux commands ...
Works great, thanks!Drugwash wrote: ⤴Mon Oct 31, 2022 7:22 am @StrangeAngel: could you please try the code above and post the result?
Just open a terminal, typepython3
and hit Enter (or if it fails typepython
and hit Enter), then type each of the two lines above and press Enter. It should yield the full path to the Desktop in system's language.
When finished pressCtrl+D
to exit the Python environment.
below code gives me exactly what I need:
global_folder_path = subprocess.check_output(['xdg-user-dir', 'DESKTOP']).decode()
global_folder_path = global_folder_path.strip('\n')
I wish I could get a return code when using the Popen statement ... it's always 'None'.
Update:
I have the returncode working now.
I have been testing all the command and their options.
Re: I created a Python script to execute Linux commands ...
Well here it is.
Hopefully it will work on everyone's Linux Mint computer.
Works on three of mine. Two laptops and one desktop.
I posted a few screen shots.
I would like someone to try is out to see if it's working correctly.
I think that it should work on computers not using English ... I can't test that situation.
Download:
https://github.com/AriIris/Linux-Easy-Command-Center
Give me some feedback good or bad.
Hopefully it will work on everyone's Linux Mint computer.
Works on three of mine. Two laptops and one desktop.
I posted a few screen shots.
I would like someone to try is out to see if it's working correctly.
I think that it should work on computers not using English ... I can't test that situation.
Download:
https://github.com/AriIris/Linux-Easy-Command-Center
Give me some feedback good or bad.