LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 03-11-2009, 01:10 AM   #1
CoffeeKing!!!
Member
 
Registered: Mar 2008
Posts: 117

Rep: Reputation: Disabled
how can i send the status of init script to update-motd.d? (kubuntu)


I'd like my motd to state if my firewall loaded successfully.

Last edited by CoffeeKing!!!; 03-13-2009 at 01:02 AM. Reason: lack of sleep led to poor grammar
 
Old 04-03-2009, 10:32 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Something rather simple like:

Code:
echo "`. /path/to/firewall-script`" > /path/to/motd-file
..should do it, assuming your firewall-script actually returns some sort of success or failure message, though if the firewall script outputs more than just a simple message, you might want to pipe the echo statement through a grep and/or gawk command to filter out only the success or failure message, and then direct that to the motd file.
 
Old 04-03-2009, 11:29 PM   #3
CoffeeKing!!!
Member
 
Registered: Mar 2008
Posts: 117

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by GrapefruiTgirl View Post
Something rather simple like:

Code:
echo "`. /path/to/firewall-script`" > /path/to/motd-file
..should do it, assuming your firewall-script actually returns some sort of success or failure message, though if the firewall script outputs more than just a simple message, you might want to pipe the echo statement through a grep and/or gawk command to filter out only the success or failure message, and then direct that to the motd file.
Wow. Thanks GrapefruiTgirl. I was just sifting through the newbie forums to learn something new and saw that you had answered my message from long ago.

After reading your message I realised I could just do something like
Code:
if [ $? = 0 ]; then
... echo a "success" message to append to the motd.

I don't understand your method though. Can a bash script echo a success message without me using the "[$! = 0]; then ...echo " method. If so, could you go into more detail or point me to a page to read. I already have the ABS guide but, It's currently eight hundred pages long and wouldn't know where to start to find your method.

By the way I'm in Halifax. I went to a NSLUG meeting a few months ago. Have you been to any of them?

Last edited by CoffeeKing!!!; 04-03-2009 at 11:31 PM.
 
Old 04-03-2009, 11:56 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
BASH stuff

Likely there are bundles of ways of doing the same thing, but they all boil down to the same thing: checking if a condition is true, and acting accordingly.

The method I showed just executes the script (the `` marks are called backticks, and they mean 'execute this stuff in a separate shell') and then uses the > (called a shell redirect) to direct ANY output from the script, into the motd. The reason I did it this way is because: the fact that a script executed to completion does NOT necessarily mean that the desired outcome was achieved. This is because BASH does not under normal circumstances quit executing if an error occurs, rather it spits out an error and keeps on plowing along. So doing that my way makes all output, good or bad, end up in the motd; your motd would then contain the substance of any errors that occurred..

Another way, comparable to yours there in post#3, is to execute the script in ["brackets"] as a conditional argument and act on the result, like:

Code:
[ "`/path/to/script`" ] && echo "Success" > motd || echo "Failure" > motd
so this example, if the script terminates with a 0 status, print 'success', otherwise print 'failure'.
In this case, the [..] means IF TRUE and the && means THEN and the || means ELSE.

Again, there are LOTS of ways to accomplish this, and I don't probably know even a fraction of them!
As for what page to read in what tutorial, I cannot point you there, but Googling for bash tutorials and the Advanced Bash Guide as you have are good steps in the right direction. However, don't forget 'man bash'!! The bash man page is very comprehensive indeed!


PS - VERY cool that you are in Halifax you are the first person I have ever seen on here in N.S. One other was in N.B. but that's the closest to me that I have seen to date before you.
I wasn't aware there even *was* a NSLUG despite searching on and off online for one. I may well go sometime though, that would be grand! How are the meetings?? The last UG I was in was a LOOOONG time ago-- it was the NSCCUG. In case you aren't familiar, that was the 'Nova Scotia Commodore Computer Users Group'!! LOL
I'll update my email address on my profile so perhaps you could give me a link or details about the NSLUG. EDIT: Isn't there a forum area here for LUGs? I'll check there too.
I'm from Halifax but moved to Stewiacke (the sticks) a couple years ago.

Last edited by GrapefruiTgirl; 04-04-2009 at 12:20 AM.
 
Old 04-04-2009, 02:04 AM   #5
CoffeeKing!!!
Member
 
Registered: Mar 2008
Posts: 117

Original Poster
Rep: Reputation: Disabled
Thanks for the help GFG. I understand your method now. Here's the NSLUG contact:
http://www.nslug.ns.ca/index.php/Main_Page
There hasn't been a lot of activity in the past two weeks. Hopefully, we'll have a meeting this month.
 
  


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 can I update from Kubuntu 7.10 to Kubuntu 8.10 without loosing my files? sandey Linux - Newbie 2 11-27-2008 10:07 AM
Implement status for my init.d script ashok449 Linux - General 1 07-04-2008 07:24 AM
init script link clashes, debian, update-rc.d, /etc/rc2.d maxvonseibold Linux - General 2 12-07-2007 04:07 AM
Which script overwrites /ect/motd? Nerox Debian 6 12-29-2004 03:25 PM
motd script or something like that linuxtesting2 Linux - General 2 06-09-2004 03:13 PM

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

All times are GMT -5. The time now is 03:59 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration