LinuxQuestions.org
Visit Jeremy's Blog.
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 04-25-2006, 02:54 AM   #1
unkn0wn
Member
 
Registered: Mar 2006
Posts: 60

Rep: Reputation: 15
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.
 
Old 04-25-2006, 04:42 AM   #2
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
a quick example, adapt and extend, don't use it just plain as I wrote it..
Code:
#!/bin/bash
if [ -z $1 ]; then
echo "Usage: $0 <target_user>"
exit 1
fi

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:
Code:
cat /tmp/$USER-mesg && echo > /tmp/$USER-mesg
It needs alot more error-checking and stuff like tyhat but something to work from (:
 
Old 04-28-2006, 02:21 AM   #3
unkn0wn
Member
 
Registered: Mar 2006
Posts: 60

Original Poster
Rep: Reputation: 15
tnx thats it.
any sugestions to delete first three line in file.
 
Old 04-28-2006, 03:31 AM   #4
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
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:
Code:
#!/bin/bash
lines=$(wc -l $1 | cut -d " " -f 1)
tail -n $(echo lines - 3 | bc) $1
Not pretty, but it works (;
 
Old 04-28-2006, 04:01 AM   #5
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
Cut the three first lines of <file> with sed (looks better ):
Code:
sed -i '1,3d' file
 
Old 04-28-2006, 04:13 AM   #6
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
Quote:
Originally Posted by muha
Cut the three first lines of <file> with sed (looks better ):
Code:
sed -i '1,3d' file
wow.. looks like its time to start learning sed.. It looks pretty powerful (:
 
Old 04-28-2006, 04:30 AM   #7
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
It is very, yes. Try the sed one-liners if you want to get started: http://bookmarks.linuxquestions.org/...tries/tags/sed
 
  


Reply

Tags
bash, example, shell script


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
Bash script - executing a script through subdirectories bubkus_jones Programming 5 04-24-2006 05:05 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM
slooze error: validateInputs(); $msg = $mySlooze->renderPage($vars); echo $msg; ?> rioguia Linux - Software 0 01-26-2003 08:59 PM


All times are GMT -5. The time now is 01:21 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration