LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Validate User Command (https://www.linuxquestions.org/questions/linux-general-1/validate-user-command-4175454423/)

cparky2 03-17-2013 12:21 PM

Validate User Command
 
Hi There

I have developed a virtual tutorial environment for Asterisk PBX. I would like the commands entered by users of this environment to be checked against a database of commands. Also i would like a simple application that would say success or fail depending on the outcome of a command. For instance, if the tutorial asked them to set chmod commands to 777 then it would say success if it had been applied properly. Any suggestions would be great.

Thanks

Snark1994 03-18-2013 10:10 AM

Quote:

Originally Posted by cparky2 (Post 4913411)
I would like the commands entered by users of this environment to be checked against a database of commands.

Well, what part of this are you having difficulty with? You can set up a database (or even just a list of strings in your program) and check if the command entered is in this list.

Quote:

Also i would like a simple application that would say success or fail depending on the outcome of a command. For instance, if the tutorial asked them to set chmod commands to 777 then it would say success if it had been applied properly.
Again, what part of this are you struggling with? For each task, you would have to define a list of criteria which check if the command has been executed correctly (e.g.
Code:

ls -l commands | grep "^-rwxrwxrwx" -q
for your example) and then get the program to execute each command in turn and check their return code: if they all return 0 for success, print "success", otherwise you can print an error message appropriate to which command failed.

cparky2 03-18-2013 11:13 AM

Thanks for the response, much appreciated.

Well I would like it to display a percentage, for example of I asked for read/write privileges to be granted and the user only executed read privileges then It would say 50% or something similar. Is that possible? Would it be possible to write the application using C#?

chrism01 03-18-2013 11:35 PM

For the sort of detail you want, use the stat cmd to check the file/dir.
However, a percentage is meaningless in this context.

Snark1994 03-19-2013 05:58 AM

Quote:

Originally Posted by cparky2 (Post 4913927)
Thanks for the response, much appreciated.

Well I would like it to display a percentage, for example of I asked for read/write privileges to be granted and the user only executed read privileges then It would say 50% or something similar. Is that possible? Would it be possible to write the application using C#?

In both cases, yes - though I would probably attempt it in bash rather than C#.


All times are GMT -5. The time now is 11:39 AM.