![]() |
|
C++ Easy command runner - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: C++ Easy command runner (/showthread.php?tid=6258990) |
C++ Easy command runner - Hackers - Dec 20, 2023 Hi all, this is nothing crazy, but I made this last night to assist with some startup commands on a server. I created a C++ file that would run commands, and then I set this program to run on server reboots. However, I didn't want to have to recompile the code every time I change the startup commands, so I made a program that reads the commands (by line) from a file, and then runs each one as-is. Please note that this is technically a security issue: If you give this C++ program escalated/admin permissions, then someone could modify the commands.txt file and then run the program. It would be important to ensure that the commands.txt file is only editable by a secure account (root, admin, etc) and also that the program only has the permissions it needs for your specific use case. Here is the source code for the very very small C++ program: Code #include <iostream>Here is an example of some commands in commands.txt, in same folder as compiled program: Code cd /home/username/cron && pm2 start ecosystem.config.jsIn this example I am starting 1 site with pm2 and 1 cron-style node app with pm2, and also starting a screen to start a forever process for a 3rd project. I compiled with: Code g++ -static startup_run.cpp -o startup_run |