Guest User

i was bored

a guest
Aug 20th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <sstream>
  6. #include <algorithm>
  7. #include <fstream>
  8. #include <cstdio>
  9. #include <sys/stat.h>
  10. #include <sys/types.h>
  11. #include <unistd.h>
  12. #include <dirent.h>
  13.  
  14. void displayHelp() {
  15. std::cout << "Available commands:\n";
  16. std::cout << " help - Display this help message\n";
  17. std::cout << " echo <message> - Repeat the following message\n";
  18. std::cout << " add <num1> <num2> - Add two numbers\n";
  19. std::cout << " subtract <num1> <num2> - Subtract the second number from the first\n";
  20. std::cout << " multiply <num1> <num2> - Multiply two numbers\n";
  21. std::cout << " divide <num1> <num2> - Divide the first number by the second\n";
  22. std::cout << " date - Display the current date\n";
  23. std::cout << " time - Display the current time\n";
  24. std::cout << " clear - Clear the console screen\n";
  25. std::cout << " mkdir <directory> - Create a new directory\n";
  26. std::cout << " rmdir <directory> - Remove a directory\n";
  27. std::cout << " dir - List files and directories in the current directory\n";
  28. std::cout << " whoami - Display the current user\n";
  29. std::cout << " hostname - Display the system's hostname\n";
  30. std::cout << " reverse <text> - Reverse the given text\n";
  31. std::cout << " upper <text> - Convert text to uppercase\n";
  32. std::cout << " lower <text> - Convert text to lowercase\n";
  33. std::cout << " repeat <count> <text> - Repeat the text a specified number of times\n";
  34. std::cout << " length <text> - Display the length of the text\n";
  35. std::cout << " copy <source> <destination> - Copy a file\n";
  36. std::cout << " move <source> <destination> - Move a file\n";
  37. std::cout << " delete <file> - Delete a specified file\n";
  38. std::cout << " rename <oldname> <newname> - Rename a file\n";
  39. std::cout << " timestamp <file> - Display the last modification time of a file\n";
  40. std::cout << " exists <file> - Check if a file or directory exists\n";
  41. std::cout << " diskspace - Display disk usage information\n";
  42. std::cout << " uptime - Display system uptime\n";
  43. std::cout << " ipconfig - Display IP configuration (Windows)\n";
  44. std::cout << " ifconfig - Display IP configuration (Unix-based systems)\n";
  45. std::cout << " ping <host> - Ping a specified host\n";
  46. std::cout << " top - Display system processes (Unix-based systems)\n";
  47. std::cout << " tasklist - Display running processes (Windows)\n";
  48. std::cout << " netstat - Display network connections and statistics\n";
  49. std::cout << " who - Display logged-in users\n";
  50. std::cout << " md5 <file> - Calculate MD5 hash of a file\n";
  51. std::cout << " sha256 <file> - Calculate SHA-256 hash of a file\n";
  52. std::cout << " concat <file1> <file2> - Concatenate the contents of two files\n";
  53. std::cout << " grep <pattern> <file> - Search for a pattern in a file\n";
  54. std::cout << " replace <old> <new> <file> - Replace text in a file\n";
  55. std::cout << " tail <file> - Display the last 10 lines of a file\n";
  56. std::cout << " head <file> - Display the first 10 lines of a file\n";
  57. std::cout << " diff <file1> <file2> - Show differences between two files\n";
  58. std::cout << " sort <file> - Sort lines in a file\n";
  59. std::cout << " unique <file> - Remove duplicate lines from a file\n";
  60. std::cout << " compress <file> - Compress a file (using gzip)\n";
  61. std::cout << " decompress <file> - Decompress a file (using gzip)\n";
  62. std::cout << " archive <file> - Archive a file (using tar)\n";
  63. std::cout << " extract <file> - Extract an archive file (using tar)\n";
  64. std::cout << " find <directory> <pattern> - Find files matching a pattern\n";
  65. std::cout << " locate <file> - Locate a file by name\n";
  66. std::cout << " chmod <permissions> <file> - Change file permissions\n";
  67. std::cout << " chown <owner>:<group> <file> - Change file ownership\n";
  68. std::cout << " touch <file> - Create an empty file or update its timestamp\n";
  69. std::cout << " kill <pid> - Kill a process by its PID\n";
  70. std::cout << " ps - List running processes\n";
  71. std::cout << " history - Show command history\n";
  72. std::cout << " alias <name>=<command> - Create an alias for a command\n";
  73. std::cout << " unalias <name> - Remove an alias\n";
  74. std::cout << " jobs - List current jobs (background processes)\n";
  75. std::cout << " fg <job> - Bring a background job to the foreground\n";
  76. std::cout << " bg <job> - Send a job to the background\n";
  77. std::cout << " killall <name> - Kill all processes with a given name\n";
  78. std::cout << " wget <url> - Download a file from the internet\n";
  79. std::cout << " curl <url> - Fetch data from a URL\n";
  80. std::cout << " ftp <url> - Open an FTP connection to a server\n";
  81. std::cout << " telnet <host> <port> - Open a Telnet connection\n";
  82. std::cout << " ssh <user>@<host> - SSH into a remote server\n";
  83. std::cout << " scp <source> <destination> - Copy files between hosts using SSH\n";
  84. std::cout << " tr <set1> <set2> - Translate or delete characters in a file\n";
  85. std::cout << " basename <path> - Strip directory and suffix from filenames\n";
  86. std::cout << " dirname <path> - Strip the last component from the file name\n";
  87. std::cout << " file <file> - Determine the file type\n";
  88. std::cout << " wc <file> - Count lines, words, and characters in a file\n";
  89. std::cout << " sleep <seconds> - Pause for a specified number of seconds\n";
  90. std::cout << " dateformat <date> - Format a date (e.g., YYYY-MM-DD)\n";
  91. std::cout << " uuid - Generate a UUID\n";
  92. std::cout << " grep -v <pattern> <file> - Invert match of a pattern\n";
  93. std::cout << " find <path> -name <pattern> - Find files by name\n";
  94. std::cout << " df - Display disk space usage\n";
  95. std::cout << " du <path> - Show disk usage of files and directories\n";
  96. std::cout << " chmod <mode> <file> - Change file mode (permissions)\n";
  97. std::cout << " chgrp <group> <file> - Change file group\n";
  98. std::cout << " mount <device> <mountpoint> - Mount a filesystem\n";
  99. std::cout << " umount <mountpoint> - Unmount a filesystem\n";
  100. std::cout << " top - Display system tasks\n";
  101. std::cout << " htop - Interactive process viewer\n";
  102. std::cout << " kill -9 <pid> - Forcefully kill a process\n";
  103. std::cout << " free - Display memory usage\n";
  104. std::cout << " uptime - Show system uptime\n";
  105. std::cout << " ps aux - Show detailed process information\n";
  106. std::cout << " crontab -l - List cron jobs\n";
  107. std::cout << " crontab -e - Edit cron jobs\n";
  108. std::cout << " exit - Exit the command prompt\n";
  109. }
  110.  
  111. std::string computeHash(const std::string& filePath, const std::string& algorithm) {
  112. std::string command = "openssl dgst -";
  113. command += algorithm + " ";
  114. command += filePath;
  115. char buffer[128];
  116. std::string result = "";
  117. FILE* pipe = popen(command.c_str(), "r");
  118. if (!pipe) {
  119. return "Error: Unable to compute hash";
  120. }
  121. while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
  122. result += buffer;
  123. }
  124. pclose(pipe);
  125. return result;
  126. }
  127.  
  128. void concatenateFiles(const std::string& file1, const std::string& file2) {
  129. std::ifstream in1(file1);
  130. std::ifstream in2(file2);
  131. if (!in1 || !in2) {
  132. std::cout << "Error: One or both files cannot be opened." << std::endl;
  133. return;
  134. }
  135. std::cout << in1.rdbuf() << std::endl;
  136. std::cout << in2.rdbuf() << std::endl;
  137. }
  138.  
  139. void grepPattern(const std::string& pattern, const std::string& file) {
  140. std::string command = "grep '" + pattern + "' " + file;
  141. std::system(command.c_str());
  142. }
  143.  
  144. void replaceText(const std::string& oldText, const std::string& newText, const std::string& file) {
  145. std::ifstream inFile(file);
  146. if (!inFile) {
  147. std::cout << "Error: File cannot be opened." << std::endl;
  148. return;
  149. }
  150. std::string content((std::istreambuf_iterator<char>(inFile)), std::istreambuf_iterator<char>());
  151. size_t pos = 0;
  152. while ((pos = content.find(oldText, pos)) != std::string::npos) {
  153. content.replace(pos, oldText.length(), newText);
  154. pos += newText.length();
  155. }
  156. inFile.close();
  157. std::ofstream outFile(file);
  158. outFile << content;
  159. }
  160.  
  161. void tailFile(const std::string& file) {
  162. std::string command = "tail -n 10 " + file;
  163. std::system(command.c_str());
  164. }
  165.  
  166. void headFile(const std::string& file) {
  167. std::string command = "head -n 10 " + file;
  168. std::system(command.c_str());
  169. }
  170.  
  171. void diffFiles(const std::string& file1, const std::string& file2) {
  172. std::string command = "diff " + file1 + " " + file2;
  173. std::system(command.c_str());
  174. }
  175.  
  176. void sortFile(const std::string& file) {
  177. std::string command = "sort " + file;
  178. std::system(command.c_str());
  179. }
  180.  
  181. void uniqueFile(const std::string& file) {
  182. std::string command = "uniq " + file;
  183. std::system(command.c_str());
  184. }
  185.  
  186. void compressFile(const std::string& file) {
  187. std::string command = "gzip " + file;
  188. std::system(command.c_str());
  189. }
  190.  
  191. void decompressFile(const std::string& file) {
  192. std::string command = "gunzip " + file;
  193. std::system(command.c_str());
  194. }
  195.  
  196. void archiveFile(const std::string& file) {
  197. std::string command = "tar -cvf " + file + ".tar " + file;
  198. std::system(command.c_str());
  199. }
  200.  
  201. void extractFile(const std::string& file) {
  202. std::string command = "tar -xvf " + file;
  203. std::system(command.c_str());
  204. }
  205.  
  206. void findFiles(const std::string& directory, const std::string& pattern) {
  207. std::string command = "find " + directory + " -name '" + pattern + "'";
  208. std::system(command.c_str());
  209. }
  210.  
  211. void locateFile(const std::string& file) {
  212. std::string command = "locate " + file;
  213. std::system(command.c_str());
  214. }
  215.  
  216. void chmodFile(const std::string& permissions, const std::string& file) {
  217. std::string command = "chmod " + permissions + " " + file;
  218. std::system(command.c_str());
  219. }
  220.  
  221. void chownFile(const std::string& ownerGroup, const std::string& file) {
  222. std::string command = "chown " + ownerGroup + " " + file;
  223. std::system(command.c_str());
  224. }
  225.  
  226. void touchFile(const std::string& file) {
  227. std::string command = "touch " + file;
  228. std::system(command.c_str());
  229. }
  230.  
  231. void killProcess(const std::string& pid) {
  232. std::string command = "kill " + pid;
  233. std::system(command.c_str());
  234. }
  235.  
  236. void listProcesses() {
  237. std::string command = "ps";
  238. std::system(command.c_str());
  239. }
  240.  
  241. void showHistory() {
  242. std::string command = "history";
  243. std::system(command.c_str());
  244. }
  245.  
  246. void createAlias(const std::string& alias, const std::string& command) {
  247. std::string commandString = "alias " + alias + "='" + command + "'";
  248. std::system(commandString.c_str());
  249. }
  250.  
  251. void removeAlias(const std::string& alias) {
  252. std::string command = "unalias " + alias;
  253. std::system(command.c_str());
  254. }
  255.  
  256. void listJobs() {
  257. std::string command = "jobs";
  258. std::system(command.c_str());
  259. }
  260.  
  261. void bringToForeground(const std::string& job) {
  262. std::string command = "fg " + job;
  263. std::system(command.c_str());
  264. }
  265.  
  266. void sendToBackground(const std::string& job) {
  267. std::string command = "bg " + job;
  268. std::system(command.c_str());
  269. }
  270.  
  271. void killAllProcesses(const std::string& name) {
  272. std::string command = "pkill " + name;
  273. std::system(command.c_str());
  274. }
  275.  
  276. void downloadFile(const std::string& url) {
  277. std::string command = "wget " + url;
  278. std::system(command.c_str());
  279. }
  280.  
  281. void fetchURL(const std::string& url) {
  282. std::string command = "curl " + url;
  283. std::system(command.c_str());
  284. }
  285.  
  286. void openFTP(const std::string& url) {
  287. std::string command = "ftp " + url;
  288. std::system(command.c_str());
  289. }
  290.  
  291. void openTelnet(const std::string& host, const std::string& port) {
  292. std::string command = "telnet " + host + " " + port;
  293. std::system(command.c_str());
  294. }
  295.  
  296. void sshIntoServer(const std::string& userHost) {
  297. std::string command = "ssh " + userHost;
  298. std::system(command.c_str());
  299. }
  300.  
  301. void copySSH(const std::string& source, const std::string& destination) {
  302. std::string command = "scp " + source + " " + destination;
  303. std::system(command.c_str());
  304. }
  305.  
  306. void translateCharacters(const std::string& set1, const std::string& set2) {
  307. std::string command = "tr '" + set1 + "' '" + set2 + "'";
  308. std::system(command.c_str());
  309. }
  310.  
  311. void basenamePath(const std::string& path) {
  312. std::string command = "basename " + path;
  313. std::system(command.c_str());
  314. }
  315.  
  316. void dirnamePath(const std::string& path) {
  317. std::string command = "dirname " + path;
  318. std::system(command.c_str());
  319. }
  320.  
  321. void fileType(const std::string& file) {
  322. std::string command = "file " + file;
  323. std::system(command.c_str());
  324. }
  325.  
  326. void wcFile(const std::string& file) {
  327. std::string command = "wc " + file;
  328. std::system(command.c_str());
  329. }
  330.  
  331. void sleepSeconds(const std::string& seconds) {
  332. std::string command = "sleep " + seconds;
  333. std::system(command.c_str());
  334. }
  335.  
  336. void formatDate(const std::string& date) {
  337. std::string command = "date -d '" + date + "'";
  338. std::system(command.c_str());
  339. }
  340.  
  341. void generateUUID() {
  342. std::string command = "uuidgen";
  343. std::system(command.c_str());
  344. }
  345.  
  346. void invertGrep(const std::string& pattern, const std::string& file) {
  347. std::string command = "grep -v '" + pattern + "' " + file;
  348. std::system(command.c_str());
  349. }
  350.  
  351. void findByName(const std::string& path, const std::string& pattern) {
  352. std::string command = "find " + path + " -name '" + pattern + "'";
  353. std::system(command.c_str());
  354. }
  355.  
  356. void displayDiskSpace() {
  357. std::string command = "df";
  358. std::system(command.c_str());
  359. }
  360.  
  361. void displayDiskUsage(const std::string& path) {
  362. std::string command = "du " + path;
  363. std::system(command.c_str());
  364. }
  365.  
  366. void changeFileMode(const std::string& mode, const std::string& file) {
  367. std::string command = "chmod " + mode + " " + file;
  368. std::system(command.c_str());
  369. }
  370.  
  371. void changeFileGroup(const std::string& group, const std::string& file) {
  372. std::string command = "chgrp " + group + " " + file;
  373. std::system(command.c_str());
  374. }
  375.  
  376. void mountFileSystem(const std::string& device, const std::string& mountpoint) {
  377. std::string command = "mount " + device + " " + mountpoint;
  378. std::system(command.c_str());
  379. }
  380.  
  381. void unmountFileSystem(const std::string& mountpoint) {
  382. std::string command = "umount " + mountpoint;
  383. std::system(command.c_str());
  384. }
  385.  
  386. void displayTasks() {
  387. std::string command = "top";
  388. std::system(command.c_str());
  389. }
  390.  
  391. void interactiveProcessViewer() {
  392. std::string command = "htop";
  393. std::system(command.c_str());
  394. }
  395.  
  396. void forceKillProcess(const std::string& pid) {
  397. std::string command = "kill -9 " + pid;
  398. std::system(command.c_str());
  399. }
  400.  
  401. void displayMemoryUsage() {
  402. std::string command = "free";
  403. std::system(command.c_str());
  404. }
  405.  
  406. void showSystemUptime() {
  407. std::string command = "uptime";
  408. std::system(command.c_str());
  409. }
  410.  
  411. void detailedProcessInfo() {
  412. std::string command = "ps aux";
  413. std::system(command.c_str());
  414. }
  415.  
  416. void listCronJobs() {
  417. std::string command = "crontab -l";
  418. std::system(command.c_str());
  419. }
  420.  
  421. void editCronJobs() {
  422. std::string command = "crontab -e";
  423. std::system(command.c_str());
  424. }
  425.  
  426. void executeCommand(const std::string& input) {
  427. std::istringstream iss(input);
  428. std::string cmd;
  429. iss >> cmd;
  430.  
  431. if (cmd == "help") {
  432. displayHelp();
  433. } else if (cmd == "echo") {
  434. std::string message;
  435. std::getline(iss, message);
  436. std::cout << message << std::endl;
  437. } else if (cmd == "add") {
  438. int num1, num2;
  439. if (iss >> num1 >> num2) {
  440. std::cout << (num1 + num2) << std::endl;
  441. } else {
  442. std::cout << "Error: Invalid numbers" << std::endl;
  443. }
  444. } else if (cmd == "subtract") {
  445. int num1, num2;
  446. if (iss >> num1 >> num2) {
  447. std::cout << (num1 - num2) << std::endl;
  448. } else {
  449. std::cout << "Error: Invalid numbers" << std::endl;
  450. }
  451. } else if (cmd == "multiply") {
  452. int num1, num2;
  453. if (iss >> num1 >> num2) {
  454. std::cout << (num1 * num2) << std::endl;
  455. } else {
  456. std::cout << "Error: Invalid numbers" << std::endl;
  457. }
  458. } else if (cmd == "divide") {
  459. int num1, num2;
  460. if (iss >> num1 >> num2) {
  461. if (num2 != 0) {
  462. std::cout << (num1 / num2) << std::endl;
  463. } else {
  464. std::cout << "Error: Division by zero" << std::endl;
  465. }
  466. } else {
  467. std::cout << "Error: Invalid numbers" << std::endl;
  468. }
  469. } else if (cmd == "hash") {
  470. std::string filePath, algorithm;
  471. iss >> filePath >> algorithm;
  472. std::cout << computeHash(filePath, algorithm) << std::endl;
  473. } else if (cmd == "cat") {
  474. std::string file1, file2;
  475. iss >> file1 >> file2;
  476. concatenateFiles(file1, file2);
  477. } else if (cmd == "grep") {
  478. std::string pattern, file;
  479. iss >> pattern >> file;
  480. grepPattern(pattern, file);
  481. } else if (cmd == "replace") {
  482. std::string oldText, newText, file;
  483. iss >> oldText >> newText >> file;
  484. replaceText(oldText, newText, file);
  485. } else if (cmd == "tail") {
  486. std::string file;
  487. iss >> file;
  488. tailFile(file);
  489. } else if (cmd == "head") {
  490. std::string file;
  491. iss >> file;
  492. headFile(file);
  493. } else if (cmd == "diff") {
  494. std::string file1, file2;
  495. iss >> file1 >> file2;
  496. diffFiles(file1, file2);
  497. } else if (cmd == "sort") {
  498. std::string file;
  499. iss >> file;
  500. sortFile(file);
  501. } else if (cmd == "unique") {
  502. std::string file;
  503. iss >> file;
  504. uniqueFile(file);
  505. } else if (cmd == "compress") {
  506. std::string file;
  507. iss >> file;
  508. compressFile(file);
  509. } else if (cmd == "decompress") {
  510. std::string file;
  511. iss >> file;
  512. decompressFile(file);
  513. } else if (cmd == "archive") {
  514. std::string file;
  515. iss >> file;
  516. archiveFile(file);
  517. } else if (cmd == "extract") {
  518. std::string file;
  519. iss >> file;
  520. extractFile(file);
  521. } else if (cmd == "find") {
  522. std::string directory, pattern;
  523. iss >> directory >> pattern;
  524. findFiles(directory, pattern);
  525. } else if (cmd == "locate") {
  526. std::string file;
  527. iss >> file;
  528. locateFile(file);
  529. } else if (cmd == "chmod") {
  530. std::string permissions, file;
  531. iss >> permissions >> file;
  532. chmodFile(permissions, file);
  533. } else if (cmd == "chown") {
  534. std::string ownerGroup, file;
  535. iss >> ownerGroup >> file;
  536. chownFile(ownerGroup, file);
  537. } else if (cmd == "touch") {
  538. std::string file;
  539. iss >> file;
  540. touchFile(file);
  541. } else if (cmd == "kill") {
  542. std::string pid;
  543. iss >> pid;
  544. killProcess(pid);
  545. } else if (cmd == "ps") {
  546. listProcesses();
  547. } else if (cmd == "history") {
  548. showHistory();
  549. } else if (cmd == "alias") {
  550. std::string alias, command;
  551. std::getline(iss, alias, '=');
  552. std::getline(iss, command);
  553. createAlias(alias, command);
  554. } else if (cmd == "unalias") {
  555. std::string alias;
  556. iss >> alias;
  557. removeAlias(alias);
  558. } else if (cmd == "jobs") {
  559. listJobs();
  560. } else if (cmd == "fg") {
  561. std::string job;
  562. iss >> job;
  563. bringToForeground(job);
  564. } else if (cmd == "bg") {
  565. std::string job;
  566. iss >> job;
  567. sendToBackground(job);
  568. } else if (cmd == "killall") {
  569. std::string name;
  570. iss >> name;
  571. killAllProcesses(name);
  572. } else if (cmd == "wget") {
  573. std::string url;
  574. iss >> url;
  575. downloadFile(url);
  576. } else if (cmd == "curl") {
  577. std::string url;
  578. iss >> url;
  579. fetchURL(url);
  580. } else if (cmd == "ftp") {
  581. std::string url;
  582. iss >> url;
  583. openFTP(url);
  584. } else if (cmd == "telnet") {
  585. std::string host, port;
  586. iss >> host >> port;
  587. openTelnet(host, port);
  588. } else if (cmd == "ssh") {
  589. std::string userHost;
  590. iss >> userHost;
  591. sshIntoServer(userHost);
  592. } else if (cmd == "scp") {
  593. std::string source, destination;
  594. iss >> source >> destination;
  595. copySSH(source, destination);
  596. } else if (cmd == "tr") {
  597. std::string set1, set2;
  598. iss >> set1 >> set2;
  599. translateCharacters(set1, set2);
  600. } else if (cmd == "basename") {
  601. std::string path;
  602. iss >> path;
  603. basenamePath(path);
  604. } else if (cmd == "dirname") {
  605. std::string path;
  606. iss >> path;
  607. dirnamePath(path);
  608. } else if (cmd == "file") {
  609. std::string file;
  610. iss >> file;
  611. fileType(file);
  612. } else if (cmd == "wc") {
  613. std::string file;
  614. iss >> file;
  615. wcFile(file);
  616. } else if (cmd == "sleep") {
  617. std::string seconds;
  618. iss >> seconds;
  619. sleepSeconds(seconds);
  620. } else if (cmd == "dateformat") {
  621. std::string date;
  622. iss >> date;
  623. formatDate(date);
  624. } else if (cmd == "uuid") {
  625. generateUUID();
  626. } else if (cmd == "grep -v") {
  627. std::string pattern, file;
  628. iss >> pattern >> file;
  629. invertGrep(pattern, file);
  630. } else if (cmd == "find -name") {
  631. std::string path, pattern;
  632. iss >> path >> pattern;
  633. findByName(path, pattern);
  634. } else if (cmd == "df") {
  635. displayDiskSpace();
  636. } else if (cmd == "du") {
  637. std::string path;
  638. iss >> path;
  639. displayDiskUsage(path);
  640. } else if (cmd == "chmod") {
  641. std::string mode, file;
  642. iss >> mode >> file;
  643. changeFileMode(mode, file);
  644. } else if (cmd == "chgrp") {
  645. std::string group, file;
  646. iss >> group >> file;
  647. changeFileGroup(group, file);
  648. } else if (cmd == "mount") {
  649. std::string device, mountpoint;
  650. iss >> device >> mountpoint;
  651. mountFileSystem(device, mountpoint);
  652. } else if (cmd == "umount") {
  653. std::string mountpoint;
  654. iss >> mountpoint;
  655. unmountFileSystem(mountpoint);
  656. } else if (cmd == "top") {
  657. displayTasks();
  658. } else if (cmd == "htop") {
  659. interactiveProcessViewer();
  660. } else if (cmd == "kill -9") {
  661. std::string pid;
  662. iss >> pid;
  663. forceKillProcess(pid);
  664. } else if (cmd == "free") {
  665. displayMemoryUsage();
  666. } else if (cmd == "uptime") {
  667. showSystemUptime();
  668. } else if (cmd == "ps aux") {
  669. detailedProcessInfo();
  670. } else if (cmd == "crontab -l") {
  671. listCronJobs();
  672. } else if (cmd == "crontab -e") {
  673. editCronJobs();
  674. } else if (cmd == "exit") {
  675. std::exit(0);
  676. } else {
  677. std::cout << "Error: Unknown command" << std::endl;
  678. }
  679. }
  680.  
  681. int main() {
  682. std::string input;
  683. while (true) {
  684. std::cout << "> ";
  685. std::getline(std::cin, input);
  686. if (input.empty()) {
  687. continue;
  688. }
  689. executeCommand(input);
  690. }
  691. return 0;
  692. }
Advertisement
Add Comment
Please, Sign In to add comment