mocosoft Posted May 16, 2009 at 06:34 PM Report #264671 Posted May 16, 2009 at 06:34 PM Boas, Alguem ja fez um codigo parecido ao que se pretende neste? O trabalho é sobre um shell monitor em que se pretende personalizar a prompt com “@myshell>” Depois com um comandos personalizados: cd [directoria] – exit - listBG ![-n] __________________________________________________________________________________ O que se pretende é : Listar todas as shells activas; O monitor de shells deve guardar todos os comandos introduzidos pelos utilizadores os respectivos resultados produzidos (output) em todas as shells de utilização activas; Monitorizar em tempo real uma determinada shell de utilização; Mandar terminar uma shell de utilização; Bloquear e desbloquear utilizadores que pretendam utilizar shells de utilização. Os utilizadores em lista negra (blacklist) não poderão utilizar shells de utilização Alguem ajuda com algum codigo?
bruno1234 Posted May 16, 2009 at 07:04 PM Report #264685 Posted May 16, 2009 at 07:04 PM Vai pondo as tuas duvidas e o codigo q já desenvolveste q o pessoal vai ajudando como conseguir. Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos
Guest id194 Posted May 17, 2009 at 04:06 AM Report #264763 Posted May 17, 2009 at 04:06 AM Universidade do Minho? Eu também estou a fazer isso mas não estou a reconhecer o que tu queres fazer. Que guião é esse? Eu acabei à pouco o 5 e não vou pegar no 6 até à próxima aula (que é sexta) e já agora. Estás em LCC ou LEI?
Triton Posted May 17, 2009 at 04:20 AM Report #264766 Posted May 17, 2009 at 04:20 AM Vou deixar algum código que fiz o semestre passado. Pelo que vi não vai chegar para o que queres, o que é bom, assim tens de trabalhar. E também não vai compilar sem uma implementação de uma lista. 😄 #include <stdio.h> // -------------------------------------------- #include <stdlib.h> // fluSH (flushOS Shell) #include <string.h> // by triton <http://www.triton.com.pt> #include <unistd.h> // Features: #include <sys/types.h> // * Basic fork() & exec() #include <sys/wait.h> // * Change working directory (cd) #include <sys/param.h> // * History and pattern-based match execution // * Easily extensible and understood #include "list.h" // -------------------------------------------- #define min(a,b) (a>b) ? b : a #define CMD(cmd, fn) if(strcmp(parsebuf[0], cmd) == 0) { fn(); return; } #define CMD_C(c, fn) if(parsebuf[0][0] == c) { fn(); return; } #define IMPLEMENT_CMD(command, fn) void cmd_##command() { fn; } #define VT(esc) "27["esc const char VT_CLEAR[] = "2J", VT_RESET[] = "0m", VT_FG_GREEN[] = "32m"; const int MAX_HOSTNAME = 255, MAX_EXECUTE = 32; void match_cmmds(); #define MAX_BUFFER 255+1 char inputbuf[MAX_BUFFER]; // input buffer char* parsebuf[MAX_BUFFER]; // parser buffer char execbuf[MAX_BUFFER]; // exec path buffer char wdbuf[MAXPATHLEN]; // working dir buffer list history; // history info char help_str[] = "fluSH 0.02a by triton\n\n" " available commands:\n" " cd - change working directory\n" " history - lists previously typed commands\n" " !# - executes last issued command starting with #\n" " help - lists all available shell commands\n" " exit - exits the shell"; void get_input() { gethostname(execbuf, MAX_HOSTNAME); printf("%s\n%s@%s", VT(VT_FG_GREEN), getlogin(), execbuf); printf("%s[%s]\n $ ", VT(VT_RESET), getwd(wdbuf)); fflush(stdout); memset(inputbuf, '\0', MAX_BUFFER); fgets(inputbuf, MAX_BUFFER, stdin); inputbuf[strlen(inputbuf)-1] = '\0'; } void parse_input() { char* ptr; int i = 0; ptr = strtok(inputbuf, " "); while(ptr) { parsebuf[i++] = ptr; ptr = strtok(NULL, " "); } parsebuf[i] = '\0'; } int spawn_process(char str[]) { pid_t pid = fork(); if(pid < 0) { perror("fork error"); return -1; } if (pid) { // parent int status; waitpid(pid, &status, 0); return status; } else { // child strcpy(execbuf, "/usr/bin/"); strcat(execbuf, str ? str : parsebuf[0]); if(execv(execbuf, parsebuf) < 0) perror("exec error"); return -1; } } void save_history() { if(!strlen(inputbuf)) return; char* ptr = malloc(strlen(inputbuf)+1); strcpy(ptr, inputbuf); insert(&history, (void*) ptr); } IMPLEMENT_CMD(exit, exit(0)) IMPLEMENT_CMD(help, printf("%s\n", help_str)) void cmd_cd() { if(chdir(parsebuf[1]) < 0) perror("chdir error"); } void cmd_history() { item* it = history.first; int i = 0; for(; i < history.nitems-1; it = it->next) printf("%d %s\n", i++, (char*)it->ptr); } void cmd_execute() { item* cmd = NULL; item* it = history.first; while(it) { int m = min(strlen(inputbuf+1), MAX_EXECUTE); if(strncmp(inputbuf+1, (char*)it->ptr, m) == 0) { cmd = it; } it = it->next; } if(!cmd) { printf("command not found in history.\n"); return; } strcpy(inputbuf, (char*)cmd->ptr); parse_input(); match_cmmds(); } void match_cmmds() { if(!parsebuf[0]) return; CMD("cd", cmd_cd) CMD("help", cmd_help) CMD("exit", cmd_exit) CMD("history", cmd_history) CMD_C('!', cmd_execute) spawn_process(NULL); } int main() { init(&history); VT100(VT_CLEAR) while (1) { get_input(); // get input save_history(); // save history parse_input(); // parse input match_cmmds(); // match commands } clear(&history); return 0; } <3 life
pedrosorio Posted May 17, 2009 at 10:12 AM Report #264774 Posted May 17, 2009 at 10:12 AM E também não vai compilar sem uma implementação de uma lista. 🙂 Agora é que o tramaste =P Não respondo a dúvidas por mensagem.
mocosoft Posted May 17, 2009 at 02:01 PM Author Report #264810 Posted May 17, 2009 at 02:01 PM Desculpem so responder agora mas é que estive sem net. O trabalho que me foi proposto fazer foi o seguinte: http://img196.imageshack.us/img196/5240/trabso.gif Obrigado a todos pelas respostas, o que so mostra que este forum é de qualidade.
Guest id194 Posted May 17, 2009 at 03:51 PM Report #264831 Posted May 17, 2009 at 03:51 PM Ok, não tem nada a ver com o meu...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now