LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need help with command (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-with-command-363587/)

turalo 09-15-2005 08:56 AM

need help with command
 
Can sombody help me to understand or to lern how to start a command when any or priticular user logs on de system? for example there is a command "script" it logs all activity of the user , to start it you just type it in the commandline : script and it starts logging , by default the log is writen in users home directory.
what I wanna do is that if sombody logs in to the system , then this command automaticly starts for that user and logs hes activity, this way I can later on see what is going on in case somthing is damaged.
in my case we use the ssh many times so I want to know what does the user doe whe he logs in.

Matir 09-15-2005 12:41 PM

First off, keep in mind that if the file is in the user's home directory, he can edit/delete/etc. the file. In fact, it's almost trivial to do 'ln -s /dev/null typescript' to keep the file from ever being created. Anyway. The /etc/profile or ~/.bash_profile files can be used to run commands on login for a user. Good luck with this.

turalo 09-15-2005 12:46 PM

Can you be more specific
 
Can you be more specific, couse I tryd alredy this files but I'cant even find all of them and when I find them there inside in the file is not the info and text wat has to be, and even if it is I'm not realy good at programing , so if you can show me small example , I'll be very thankfull

Matir 09-15-2005 12:49 PM

/etc/profile contains a small bash script usually. Here's a completely fake example:
Code:

# /etc/profile:
PATH=/bin:/usr/bin:/usr/local/bin
# more code
script

Where the bold section is what you want run. Also, have you looked at ~/.bash_history?

Don't forget to disclose to users that actions are being logged.

turalo 09-15-2005 01:01 PM

Here is some example of ...
 
ok this is the end of my profile file

#
# System BASH specials, maybe also good for other shells
#
test -r /etc/bash.bashrc && . /etc/bash.bashrc
if test "$is" = "bash" -a -z "$_HOMEBASHRC" ; then
# loop detection
readonly _HOMEBASHRC=true
test -r $HOME/.bashrc && . $HOME/.bashrc
fi

#
# KSH specials
#
if test "$is" = "ksh" ; then
test -r /etc/ksh.kshrc && . /etc/ksh.kshrc
fi
if test "$is" = "ksh" -a -z "$_HOMEKSHRC" ; then
# loop detection
readonly _HOMEKSHRC=true
test -r $HOME/.kshrc && . $HOME/.kshrc
fi

#
# End of /etc/profile
#
Vigor50:/etc #




Do I make it like this ? :

#
# System BASH specials, maybe also good for other shells
#
test -r /etc/bash.bashrc && . /etc/bash.bashrc
if test "$is" = "bash" -a -z "$_HOMEBASHRC" ; then
# loop detection
readonly _HOMEBASHRC=true
test -r $HOME/.bashrc && . $HOME/.bashrc
fi

#
# KSH specials
#
if test "$is" = "ksh" ; then
test -r /etc/ksh.kshrc && . /etc/ksh.kshrc
fi
if test "$is" = "ksh" -a -z "$_HOMEKSHRC" ; then
# loop detection
readonly _HOMEKSHRC=true
test -r $HOME/.kshrc && . $HOME/.kshrc
fi

# This is the added code for loging
PATH=/bin:/usr/bin:/usr/local/bin
# more code
script

#
# End of /etc/profile
#
Vigor50:/etc #


or my dombo brains are green yet ? sorry if its to stupid, I'm realy trying .Do I make it like this ? :

Matir 09-15-2005 01:04 PM

It's okay, everyone was new to this at one point. :) I'm always glad to help.

No, you do not need the PATH line, that was just for an example. Just leave the 'script' line in.

turalo 09-15-2005 01:22 PM

Ok and....
 
do I heave to resart some file/ demon/ or somthing ? after I made the chage to profile ?

turalo 09-15-2005 01:25 PM

ok ok
 
It works :-D , now lets chalenge it :D thank you for help


I'm going to try it out

Matir 09-15-2005 01:33 PM

No problem. In answer to your question, even though you found out yourself: /etc/profile is automatically re-read everytime someone logs in to a shell. It must be a login shell to be read.

turalo 09-15-2005 01:38 PM

mmmmm
 
There is some problem with this thing,

now its starts everytiyng ok , but for example I loged in , I made soma commands like ls and so on , just to test, after I typed exit then its also normaly says script stoped and file is typescript

then I do : cat typescript and it flys in my screen without stoping it just keeps repeating my comands for examle I just jused 3 commands : ls, cal, ls it has to show

example

cat typescript

then

ls + screen

cal + screen

ls + screen

thats it it has to stop, but it just keeps repeating its like a big file that keeps scroling in the sreen .

so now I'm trying to finde what did I do wrong or what is wrong :D :confused:

Matir 09-15-2005 01:45 PM

Does script work properly if just executed from the command line?

turalo 09-15-2005 01:47 PM

yes
 
but thera are more small problems , for example if the user logs in 2 times the 1 time things are erased :D so I'm going to se which extra atributes to put with it and come back with more info :D

Matir 09-15-2005 01:57 PM

Have you tried script -a to make it append to the previous session?


All times are GMT -5. The time now is 01:38 AM.