-   Programming (
-   -   msg bash script (

unkn0wn 04-25-2006 02:54 AM

msg bash script
How can i build shell script for example:

-script name mesg
-when user type mesg prompt is displayed
-> type your message to $user
> msg
> msg

-when $user log in he read mesg which is sent by some user.

Artanicus 04-25-2006 04:42 AM

a quick example, adapt and extend, don't use it just plain as I wrote it..

if [ -z $1 ]; then
echo "Usage: $0 <target_user>"
exit 1

echo "Enter your msg:"
echo -n "-> "
read msg

echo "$USER wrote you on $(date): $msg >> /tmp/$1-mesg
echo "=======================" >> /tmp/$1-mesg
# has to have write permissions via some way, not that safe d:

And /etc/profile could have something like this:

cat /tmp/$USER-mesg && echo > /tmp/$USER-mesg
It needs alot more error-checking and stuff like tyhat but something to work from (:

unkn0wn 04-28-2006 02:21 AM

tnx thats it.
any sugestions to delete first three line in file.

Artanicus 04-28-2006 03:31 AM

Well.. I'd prolly do that in C++ myself.. Alot more effective than toying around with wc and tail.. But it would look something like this:

lines=$(wc -l $1 | cut -d " " -f 1)
tail -n $(echo lines - 3 | bc) $1

Not pretty, but it works (;

muha 04-28-2006 04:01 AM

Cut the three first lines of <file> with sed (looks better :D):

sed -i '1,3d' file

Artanicus 04-28-2006 04:13 AM


Originally Posted by muha
Cut the three first lines of <file> with sed (looks better :D):

sed -i '1,3d' file

wow.. looks like its time to start learning sed.. It looks pretty powerful (:

muha 04-28-2006 04:30 AM

It is very, yes. Try the sed one-liners if you want to get started:

All times are GMT -5. The time now is 11:19 AM.