Register
It is currently Mon Dec 22, 2014 10:38 pm

Newbie Help


All times are UTC - 6 hours


Post new topic Reply to topic  [ 10 posts ] 
Author Message
 PostPosted: Sun Sep 27, 2009 11:23 am   

Joined: Sun Sep 27, 2009 11:16 am
Posts: 6
Location: Dubai
Hi,

I just started learning bash scripting. I created this small script:
Code:
#!/bin/bash

echo "You are user $UID on $HOSTNAME"
echo "Your home directory is: $HOME"
echo "$HOSTNAME is running $OSTYPE"


and placed it in /usr/bin directory. It runs fine if I use ./script-name.sh but I want it to execute by just typing script-name in all accounts. How do I do that? And How to put colors to the ouput text? And How can I put this script in MOTD so that whenever a user loggs in He gets this Info without having to type the command?


Top
 Profile  
 PostPosted: Sun Sep 27, 2009 2:40 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
First, read http://linuxgazette.net/issue65/padala.html
Then, in /etc/init.d/bootmisc.sh, you should have (in any Debian-like distro, I don't know RH-like) a line like
Code:
uname -snrvm > /var/run/motd
comment it, and add below
Code:
echo -e "^[[00;30;40mYou are user ${UID:-nc} on ${HOSTNAME:-nc}\n^[[00;30;40mYour home directory is: ${HOME:-nc}\n${HOSTNAME:-nc} is running ${OSTYPE:-nc}" > /var/run/motd
where every second 0 is a code you would find in the page linked above.

Note: you should use vim, and <ctrl-v><ctrl-[>[ to get correct escape sequence: ^[[


Top
 Profile  
 PostPosted: Tue Sep 29, 2009 1:38 pm   

Joined: Sun Sep 27, 2009 11:16 am
Posts: 6
Location: Dubai
Watael wrote:
First, read http://linuxgazette.net/issue65/padala.html
Then, in /etc/init.d/bootmisc.sh, you should have (in any Debian-like distro, I don't know RH-like) a line like
Code:
uname -snrvm > /var/run/motd
comment it, and add below
Code:
echo -e "^[[00;30;40mYou are user ${UID:-nc} on ${HOSTNAME:-nc}\n^[[00;30;40mYour home directory is: ${HOME:-nc}\n${HOSTNAME:-nc} is running ${OSTYPE:-nc}" > /var/run/motd
where every second 0 is a code you would find in the page linked above.

Note: you should use vim, and <ctrl-v><ctrl-[>[ to get correct escape sequence: ^[[


Thanks for your reply. But I tried it and nothing is happening. I know I'm not following you completely. But as you said I created a file "bootmisc.sh" in /var/init.d/, since there was no one before and added these lines:

Code:
#!/bin/bash
#uname -snrvm > /var/run/motd

echo -e "^[[00;30;40mYou are user ${UID:-nc} on
${HOSTNAME:-nc}\n^[[00;30;40mYour home directory is:
${HOME:-nc}\n${HOSTNAME:-nc} is running ${OSTYPE:-nc}" > /var/run/motd


but nothing happened :S. Even If I type ./bootmisc.sh nothing happens. Is it because its not the /bin/bash Dir?

*P.S. I'm using CentOs


Top
 Profile  
 PostPosted: Tue Sep 29, 2009 5:31 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
OK, I played a little with a CentOS live-cd, and finaly it appears that you could write directly into /etc/motd, without the requiring of bootmisc.sh script.

Will changes be sustainable after a reboot... I don't know. Let us know.


Top
 Profile  
 PostPosted: Mon Oct 19, 2009 7:16 am   

Joined: Sun Sep 27, 2009 11:16 am
Posts: 6
Location: Dubai
Hi,

I tried putting these lines in motd; If I put with echo -e " I only see echo -e" , when I login , and If I put the script directly in the /etc/motd file (^[[00; ..) . I see a blank page and the curser is moved to the middle of the page. Can you tell me exactly how to use this command in motd in CentOS?


Top
 Profile  
 PostPosted: Fri Oct 23, 2009 11:20 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 673
Location: Des Moines, Iowa
F0RD wrote:
Hi,

I just started learning bash scripting. I created this small script:
Code:
#!/bin/bash

echo "You are user $UID on $HOSTNAME"
echo "Your home directory is: $HOME"
echo "$HOSTNAME is running $OSTYPE"


and placed it in /usr/bin directory. It runs fine if I use ./script-name.sh but I want it to execute by just typing script-name in all accounts. How do I do that? And How to put colors to the ouput text? And How can I put this script in MOTD so that whenever a user loggs in He gets this Info without having to type the command?



I think the color issue is handled pretty well with the link given above......
first of all, if you want the script named "script-name" and NOT "script-name.sh" ...... change the name....... "mv script-name.sh script-name"
Make sure it's executable ........ "chmod 755 script-name"

Assuming you put this script in /usr/bin ...... you should be able to launch it now by simply typing "script-name".

Alternatively you could also create an alias in your .bashrc file to do the same thing.
The alias would look something like

alias script-name='/usr/bin/script-name.sh'

You would then have to re-source your .bashrc file to make it active with the command
source ~/.bashrc


Top
 Profile WWW  
 PostPosted: Sat Oct 24, 2009 8:52 am   

Joined: Sun Sep 27, 2009 11:16 am
Posts: 6
Location: Dubai
Thanks, It works!! Erm.. Now can you tell me how do I add this in motd? So that Whenever someone logs into shell He gets this info along with the motd?


Top
 Profile  
 PostPosted: Sat Oct 24, 2009 9:35 am   

Joined: Sun Sep 27, 2009 11:16 am
Posts: 6
Location: Dubai
Err.. Can you help me make something similiar to this MOTD?:

Code:
Username.............: User
Home Directory.......: /home/User
Disk Usage...........: 20M
_____________________
Operating System.....: CentOS-5.2
_____________________
eggdrops running.....:  1
irssi's running......:  0
BitchX's running.....:  0
psybnc's running.....:  0
screen'd procs.......:  0
other's running......:  0
_____________________
getegg ...............: To install the eggdrop.
getpsy ...............: To install the psybnc.
getbnc ...............: To install the bnc.
getmuh ...............: To install the muh.
getstats .............: To install eggdrop with stats feature.
vhosts ...............: To view the list of vhosts.
psy-restart ..........: To restart your psybnc.
_____________________
IRC COMMANDS:
BitchX irssi scrollz


?


Top
 Profile  
 PostPosted: Sun Dec 27, 2009 12:36 pm   

Joined: Sun Sep 27, 2009 11:16 am
Posts: 6
Location: Dubai
can someone help me with my previous post please?


Top
 Profile  
 PostPosted: Mon Dec 28, 2009 8:03 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
Hi FORD,

Well, unfortunately, I think what you're asking for can't be done (at least easily, or you could take a look at `man -k getty` pages), or not the way you want as /etc/motd is an ascii text file where no variable will be expanded.
You won't either be able to print user's and machine's usage data, at user's login, in it as it's only root writable.

Therefor, you could add a line at the end of the users and /etc/skeleton/{,.bashrc}, that calls a script that gathers all data you want to prompt


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP