The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
List Process with their Status. varungupta UNIX for Advanced & Expert Users 2 03-21-2008 05:27 PM
Ftp Service /process Status GaneshB Linux 1 03-10-2008 06:15 AM
append a line to the last line in a file subhrap.das UNIX Desktop for Dummies Questions & Answers 5 04-25-2007 06:17 AM
append line ymeyaw UNIX for Dummies Questions & Answers 7 04-09-2006 07:14 PM
killing unix job after the job process completes dtazv Shell Programming and Scripting 1 07-22-2005 03:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-25-2008
Registered User
 

Join Date: Jan 2008
Location: Buffalo, NY
Posts: 5
Stumble this Post!
Append Status to echo'd line after process completes

Hello All,

I'm very new to scripting and I'm writing a very simple script to restart a couple processes because I'm getting to lazy to cd between directories.

This is pretty much my first script and I just want to add a little cosmetics to it.

Here's what I have:
Code:
#!/bin/ksh
echo 'Stopping digital processes...'
/usr/local/xgate.ment/xgate.ment stop
/usr/local/xgate.liver/xgate.liver stop

echo 'Starting digital processes...'
/usr/local/xgate.ment/xgate.ment start
/usr/local/xgate.liver/xgate.liver start

point xgate

I'd like to add something that will append the word "Stopped" to 'Stopping digital processes...', when the two processes are stopped, but display it on the same line, so I don't have two lines like the following:

Stopping digital processes...
Stopping digital processes...Stopped

Is there a way to do this.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-25-2008
Registered User
 

Join Date: Oct 2007
Posts: 120
Stumble this Post!
You can use

Code:
#!/bin/ksh
echo -n 'Stopping digital processes...'
/usr/local/xgate.ment/xgate.ment stop
/usr/local/xgate.liver/xgate.liver stop
echo stopped
echo -n 'Starting digital processes...'
/usr/local/xgate.ment/xgate.ment start
/usr/local/xgate.liver/xgate.liver start
echo stopped

point xgate
If the programs produce output You may want to do something like
/usr/local/xgate.ment/xgate.ment stop &> error.log
if You are sure that it will stop and output isn't interesting or read return value and act upon, such as

/usr/local/xgate.ment/xgate.ment stop &> error.log
if [ $? -eq 0 ] ; then echo stopped; else echo Something went wrong, read error.log;fi

or something like that?

/Lakris
Reply With Quote
  #3 (permalink)  
Old 01-25-2008
Registered User
 

Join Date: Jan 2008
Location: Buffalo, NY
Posts: 5
Stumble this Post!
Ok, I've changed the script like you have shown and my script now looks like:
Code:
#!/bin/ksh
echo -n 'Stopping digital processes...'
#/usr/local/xgate.ment/xgate.ment stop
#/usr/local/xgate.liver/xgate.liver stop
echo Stopped

echo -n 'Starting digital processes...'
#/usr/local/xgate.ment/xgate.ment start
#/usr/local/xgate.liver/xgate.liver start
echo Stopped
This is the output I get:
Code:
aaawcny:/home/itmike/scripts # ./digital.restart
-n Stopping digital processes...
Stopped
-n Starting digital processes...
Stopped
It's close but I'd like to have "Stopped" appended to the original, like this:
"Starting digital processes...Stopped"

Rather than underneath it. Is that possible without too much work?


Also, what does the -n argument do with echo? It doesn't seem to do anything as it printed to the terminal.
Reply With Quote
  #4 (permalink)  
Old 01-25-2008
Registered User
 

Join Date: Oct 2007
Posts: 120
Stumble this Post!
Quote:
Originally Posted by Setan View Post
Also, what does the -n argument do with echo? It doesn't seem to do anything as it printed to the terminal.
It should produce the output without a linefeed. What shell are You using?

sorry ksh i guess, well... it should work!
Reply With Quote
  #5 (permalink)  
Old 01-25-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 541
Stumble this Post!
Code:
echo 'Stopping digital processes...\c'
/usr/local/xgate.ment/xgate.ment stop
echo 'Stopped'
Reply With Quote
  #6 (permalink)  
Old 01-25-2008
Registered User
 

Join Date: Jan 2008
Location: Buffalo, NY
Posts: 5
Stumble this Post!
Looks like I'm all set now. I used what shamrock showed and it's working now.

Thanks for the help guys!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0