LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-12-2006, 06:33 AM   #1
hi_msh
LQ Newbie
 
Registered: Dec 2005
Distribution: RedHat Linux9
Posts: 23

Rep: Reputation: 15
How to automatically start a command


Hi all. i m new to linux.I work in a small company where all has same user to view a log file of proxy server.I want to tell that when we logon to computer giving our username and passwd log file of proxy server is automatically shown to us using, i think "tail" is used to show us that log file. we cant do any thing else with this user. even if we press Ctrl+c it logout us.Now i want to ask 2 things, one is that how is it possible to create that type of user and assinging that kind of rights to him that he could view only the log file which is automatically started at the time of logon.Simply i'll say i want to create a user of same type, which when logon to system view some log file which i specify.2nd thing i want to know is how to set things that we can view a log file in same directory with different name.e.g if currently we r viewing 2005.log but now we want to view 2006.log in the same directory. Please help and tell how to change it and also how to create and that type of rights to a user that he can view only specific log file.
 
Old 01-12-2006, 07:46 AM   #2
BinJajer
Member
 
Registered: Sep 2005
Location: Warsaw, Poland
Distribution: Slackware 10.2, Caldera OpenLinux 3.1, Corel Linux (Thanks xhi!), Debian GNU/HURD etc...
Posts: 296
Blog Entries: 1

Rep: Reputation: 30
If your'e using a csh-type shell (tcsh,csh,44bsd-csh -- the best ones) then just add the command you wish to be issued to .login in the user's homedir.
 
Old 01-12-2006, 08:29 AM   #3
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Lightbulb

Hi,

I don't know if it will work, but you can try to modify your user shell settings. I mean instead of assigning a shell like bash, csh or something else, you assign it the "tail" command with the appropriate log file as an argument...
If you want I can test it tonight at home and tell you how to do that if it works

Oliv'
 
Old 01-12-2006, 08:38 AM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
Adding commands to be called at login time is not bullet proof.
A more secure approach is changing the default shell by a program that only do what you need. Using your case, that program could be something like that:

Quote:
#!/usr/bin/rbash

/usr/bin/tail -f /var/log/messages
rbash is the bash shell operating in a restrict way. RTFM.

To setup this, change the last last entry in /etc/passwd to the path of such program, for example, /home/joe/readlog. In some systems you may have to add this program to the /etc/shells file, which controls what are the valid shells in you system.

Answering your second question, I am not sure what you want, but if you change the /var/log/messages to /var/log/afixedname in the above script and you want to associate the real file /var/log/messages to it,

ln -s /var/log/message /var/log/afixedname

now, if you want the same user, get the output of /var/log/boot.msg, using the same script,

rm /var/log/afixedname
ln -s /var/log/boot.msg /var/log/afixedname

best regards,

PS: change the user's shell only after you have tested the script /home/joe/readlog. Doing this make the debuging of /home/joe/readlog very easy. When all looks fine, than change the user's shell to /home/joe/readlog.

PS2: Start with the regular shell /bin/bash. After debugging, than change to the restrict shell until you manage it to work as expected.

Last edited by marozsas; 01-12-2006 at 08:45 AM.
 
Old 01-14-2006, 08:14 AM   #5
hi_msh
LQ Newbie
 
Registered: Dec 2005
Distribution: RedHat Linux9
Posts: 23

Original Poster
Rep: Reputation: 15
Yes oliv i want a simple method to do this. but my problem is solved and i succeded to change the name of log file. but still i want to know that how to create a user which whenever login a command like "tail -f /var/log/messeges" is executed automatically. please help me out to do this.
 
Old 01-14-2006, 09:45 AM   #6
hi_msh
LQ Newbie
 
Registered: Dec 2005
Distribution: RedHat Linux9
Posts: 23

Original Poster
Rep: Reputation: 15
Here i want to give details of the settings which our system admin have done on the machine. He simply created a user on the linux machine and then changes the last entry against that username in passwd file (as "marozsas" tell) and give it the path of that file which is to be accessed at the time of login. e.g he gave a path like /usr/bin/pro Now when i see that pro file only two lines are written in it as "1st line:#!/bin/sh 2nd line:tail -f /var/log/message". Now i try to create a file with same lines written in that file named pro1 and save it in the same directory and in passwd file also change it to /usr/bin/pro1 But it didnt work.Actually when I use ls command to list all files in bin directory the color of file "pro" is green but the color of file which i created named "pro1" is white.I think there is some problem with the file type. If any one understand my problem please help me. Simply tell me the way to create a user and assign him the only right to view that log file which is automatically executed with the help of a command. In otherwords we can say that i want to create a user which when login A command is executed automatically. Waiting for Kind replies. Thanx in advance
 
Old 01-16-2006, 05:16 AM   #7
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
You didn't take in account the "post scriptum" in my first reply: "change the user's shell only after you have tested the script"

Check the owner. group and permissions of pro and make pro1 to look like it.

ls -l /usr/bin/pro /usr/bin/pro1

use chmod to change the permissions, chown to change the owner and chgrp to change the group.

BTW, RTFM, means "Read the Fine Manual", regardless you may have heard about his acronym. ;-)

regards,

Last edited by marozsas; 01-16-2006 at 05:21 AM.
 
Old 01-25-2006, 02:31 AM   #8
BinJajer
Member
 
Registered: Sep 2005
Location: Warsaw, Poland
Distribution: Slackware 10.2, Caldera OpenLinux 3.1, Corel Linux (Thanks xhi!), Debian GNU/HURD etc...
Posts: 296
Blog Entries: 1

Rep: Reputation: 30
Just to end this thread: one should not use the term RTFM without having negative intents. Although it can be interpreted even as Reffer to The fine Manual or ReadTheFineMan, it is in most cases interpreted as Read The F***** Man!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I automatically start a program at start up? victordh Linux - General 7 10-27-2013 06:02 AM
How to run a command automatically on start up TKD SUSE / openSUSE 6 11-03-2005 04:41 AM
start apps automatically on start up? chunlee Linux - Newbie 3 09-04-2004 12:58 PM
start terminal & run command automatically peeples Linux - General 2 09-08-2003 02:57 PM
X won't start automatically urinal cake Linux - Newbie 5 03-08-2002 05:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration