LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-23-2003, 08:15 AM   #1
mtest
LQ Newbie
 
Registered: Oct 2003
Location: India
Posts: 22

Rep: Reputation: 15
shell script problems


there are 3 questions. pls reply this

-----------------------------------------
how to execute wall command in shell script
how to pass messages to users logged in thru wall command from shell script
-----------------------------------------

how to change directory(cd command) from shell script
for eg:
in shell script i have given cd/home
but when i execute shell scipt the directory remains the same with out change.
-----------------------------------------

how to flash a message when user logs in
desc:
to give a message from root to a particular user so that when ever the user logs in, the first message must be "Contact System Administrator" and system should not allow the user to do any thing further. only message should be flashed
-----------------------------------------
thanks in advance
 
Old 10-23-2003, 08:37 AM   #2
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
1)

Code:
#!/bin/bash
echo "This is a message to all users." | wall
This already send's it to all user's.

2)

I think the script is run in a subshell, so it won't change the directory of the person running the script.

3) The only thing I found was '/etc/nologin', which can be used to prevent user login and give the user's a message, just add the message in '/etc/nologin'...unfortunatly, that would prevent all users.

However, what you could do is 'write' to the specified users terminal, notify them to see you, then lock their password with 'usermod -L <username>'.

That's the best I can come up with.

Last edited by Tarts; 10-23-2003 at 09:51 AM.
 
Old 10-23-2003, 11:11 AM   #3
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Code:
if [ "$UID" = 1000 ]; then
  echo "See system admin." | write stratus
  usermod -L stratus 2> /dev/null
  echo "root, stratus logged in." | write root 2> /dev/null
  logout
fi
Add this to '/etc/profile', change the parts in bold, such as '"$UID"' , 'echo $UID' to get this info about the user. Change the:

'echo "See system admin." | write <user>',

and

'echo "root, <user> logged in." | write root'

aswell as :

'usermod -L <user> 2> /dev/null'.


Enjoy.

Tarts.

Last edited by Tarts; 10-23-2003 at 11:29 AM.
 
Old 10-23-2003, 12:25 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
2) it is exec'ed or forked so that when it returns the old current directory is restored.

The only way to do this is to change the user's default directory
before they log in. I'm assuming you want certain users to be blocked from their home directories at login.
 
Old 10-23-2003, 12:36 PM   #5
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Quote:
Originally posted by jim mcnamara
2) it is exec'ed or forked so that when it returns the old current directory is restored.

The only way to do this is to change the user's default directory
before they log in. I'm assuming you want certain users to be blocked from their home directories at login.
From what I gather mtest wants to not allow the user to do anything..
 
Old 10-23-2003, 01:57 PM   #6
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Then why not just disuser the guy(s)/girl(s) ?

This is a waste of his time
 
Old 10-25-2003, 09:25 AM   #7
silatts
LQ Newbie
 
Registered: Oct 2003
Posts: 19

Rep: Reputation: 0
q3)

do not try doing it in the /etc profile - as it can be escaped from,,

..

make a new 'shell'

Code:
cat >> /usr/local/bin/goawayshell
#!/bin/sh
echo go away
exit 0

cntrl D

chmod 555 /usr/local/bin/goawayshell
now in the password file - set certain (or all?!?) users shell to /usr/local/bin/goawayshell - I think that is reasonably safe to do... but I haven't tried it...

Sil
 
Old 10-25-2003, 09:27 AM   #8
silatts
LQ Newbie
 
Registered: Oct 2003
Posts: 19

Rep: Reputation: 0
Quote:
Originally posted by jim mcnamara
Then why not just disuser the guy(s)/girl(s) ?

This is a waste of his time
yeah - it would appear so,. easier to no access them an b4 the login prompt put a message saying if you can't login contact admin?

Sil
 
Old 10-25-2003, 04:26 PM   #9
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Quote:
Originally posted by silatts
yeah - it would appear so,. easier to no access them an b4 the login prompt put a message saying if you can't login contact admin?

Sil
That sounds better, I found '/etc/issue' where you can put a message seen before the login prompt.

Tarts

Last edited by Tarts; 10-25-2003 at 04:34 PM.
 
  


Reply



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
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Problems with linux shell script linuxstrugler Programming 17 08-18-2005 08:35 AM
shell script problems BC1 Linux - General 1 05-01-2005 11:42 PM
Shell script problems, passing options to gcc usernamed Programming 2 09-10-2003 06:47 AM
Slackware 8.1 rc.inet1 shell script problems matruschka Linux - Networking 3 07-22-2002 02:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:18 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