keep track of the last 10 commands the user typed


 
Thread Tools Search this Thread
Top Forums Programming keep track of the last 10 commands the user typed
# 8  
Old 09-18-2006
zhshqzyc

"history' is an alias for "fc"!!!
ALTRUNVRSOFLN
# 9  
Old 09-18-2006
ALTRUNVRSOFLN, what the OP is trying to say is that (s)he is trying to write a shell and wants to keep track of the command history in a manner that is similar to what our usual shells do.

A simple solution would be to have a 2-D array where you store commands. When you execute each command, you store it in the array. When the user types 'history', you can run a for loop that will go over the 2-D array and print the last 10 commands.
# 10  
Old 09-19-2006
So, can we enforce
Code:
argv[0] = "history";
argv[1]  = "10";

by assigning them. then call system
Code:
execvp[argv[0],argv);

# 11  
Old 09-19-2006
No, you cannot do that. history is a shell builtin command. You can only execute actual command-files that way. You will have to write code that implements what history does if you want it to work.
# 12  
Old 09-19-2006
Okay. thanks.

I am encountering a pointer assignment problem.

Suppose
Code:
extern char **hist;//record history commands


Code:
 static char cmd[MAXLINE];//command line characters
  char *cmdp;

What I did is to record all the commands.
Code:
 cmdp=cmd;
   while ((*hist[j] = *cmdp)!='\0')
   {
        hist[j]++;cmdp++;
   }

However,after I execute the program,
Segmentation fault
# 13  
Old 09-19-2006
You are hitting a NULL pointer somewhere. Put printf statements at different points in your program, as in before entering the while loop, for each iteration, print the value that you are comparing, after the while loop, etc. This will tell you exactly where the problem is occurring and what is the state of your data at that point.

You can then find the cause and fix it.
# 14  
Old 09-19-2006
Code:
A simple solution would be to have a 2-D array where you store commands. When you execute each command, you store it in the array. When the user types 'history', you can run a for loop that will go over the 2-D array and print the last 10 commands.

Dear blowtorch:
If I create this 2D array in a function,how can I return the array into the main function? I am going to print them in the main function.
Use extern variables or pointer?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to track what Commands run in a login session

Hi I need to track what commands run in login session in solaris whether it is root or any normal users in bash shell. My actual requirement is that when a user (nomal/root) login into the system, whatever commands he run, it should log into file on specified path . I don't require command... (4 Replies)
Discussion started by: hb00
4 Replies

2. UNIX for Advanced & Expert Users

Track activity of a user

Hi All We have a job which writes files to a server at a particular time. The files will be created by a particular user ID Today, during the execution of the job, it created a file to the server and the file sat on the server for sometime, but was deleted immediately at the end of the... (4 Replies)
Discussion started by: sparks
4 Replies

3. UNIX for Dummies Questions & Answers

How to track user activity?

Hi All Please can you help me with the following issue: A certain vendor installed an application in which for a user to log in; the user must use a user created/predefined by the application. And because this application has more than one user its difficult to track who did what and when,... (6 Replies)
Discussion started by: fretagi
6 Replies

4. AIX

track commands run as root after sudo

I'm looking for a way to track commands that are run as root after a user runs sudo su - root. I have a profile set up for root that will track the commands by userid but if we change the shell it only stores it in that shells history file. (2 Replies)
Discussion started by: toor13
2 Replies

5. AIX

"/" doesn't work on command prompt for searching commands last typed

When I use "/" to look for a particular command that I typed in the current session it says D02:-/home/user1/temp> /job ksh: /job: not found. D02:-/home/user1/temp> previously it used to fetch all the commands which had job in it.. for example subjob, endjob, joblist etc... may I... (7 Replies)
Discussion started by: meetzap
7 Replies

6. Homework & Coursework Questions

Track user log!

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The task is to measure the density of users that are logged on system. The program should check that every 30... (7 Replies)
Discussion started by: petel1
7 Replies

7. UNIX for Dummies Questions & Answers

Track user

Hi, i suddenly realized that a directory is deleted unfortunately there are many user have pervilages on this directory is there a way to track the user who delete this directory or atleast from now can i enable something so that i can track from now I think there is way from... (2 Replies)
Discussion started by: crackgeek
2 Replies

8. UNIX for Advanced & Expert Users

Track user commands

Hi, I have a unix server and I am concerned about the security on that server. I would like to be able to write a script that records all the commands that were typed at the command prompt before the user calls the 'history -c' command and deletes all the history. I was thinking about firing or... (7 Replies)
Discussion started by: mishkamima
7 Replies

9. Shell Programming and Scripting

keep track of every user

dear all , I m new to shell programming and I need your help. Actually i want to keep track of all the commands executed in a bash prompt of users , very much in same manner as it is displayed when we run "history" command. now the users are smart enough as they delete their history by... (6 Replies)
Discussion started by: xander
6 Replies

10. UNIX for Dummies Questions & Answers

Possible to track FTP user last login? Last and Finger don't track them.

Like the topic says, does anyone know if it is possible to check to see when an FTP only user has logged in? Because the shell is /bin/false and they are only using FTP to access the system doing a "finger" or "last" it says they have never logged in. Is there a way to see when ftp users log in... (1 Reply)
Discussion started by: LordJezo
1 Replies
Login or Register to Ask a Question