Append Status to echo'd line after process completes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append Status to echo'd line after process completes
# 1  
Old 01-25-2008
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.
# 2  
Old 01-25-2008
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
# 3  
Old 01-25-2008
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.
# 4  
Old 01-25-2008
Quote:
Originally Posted by Setan
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!
# 5  
Old 01-25-2008
Code:
echo 'Stopping digital processes...\c'
/usr/local/xgate.ment/xgate.ment stop
echo 'Stopped'

# 6  
Old 01-25-2008
Looks like I'm all set now. I used what shamrock showed and it's working now.

Thanks for the help guys!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gnu tool; sed awk echo etc to prepend or append string to a file

Looking to add text to a file, example File example; nodegroups: check-hosts: L@host.domain.com,host2.domain.com,host3.domain.com I need to take a file with a one line list of hosts separated by commas host.domain.com,host2.domain.com,host3.domain.comand prepend the string " ... (6 Replies)
Discussion started by: bash_in_my_head
6 Replies

2. Shell Programming and Scripting

Echo printing a line in 2 lines; expected to print in one line

Dear All, fileName: therm.txt nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41 1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2 -2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3 ... (7 Replies)
Discussion started by: linuxUser_
7 Replies

3. UNIX for Dummies Questions & Answers

Echo does not work to append to a new line

Hi, i am witing a function in a shell script which will echo the file name and witre in to the new line, but i dont get expected results. The below is my code #!/bin/bash DATE=$1 myview(){ base_name=$1 echo -ne "${base_name}${DATE}">> /path/to/file/txt } myview sample3030 myview... (5 Replies)
Discussion started by: vikatakavi
5 Replies

4. UNIX for Dummies Questions & Answers

How can I learn the status of a process

how can I learn the status of a process (sleeping, running or ready.) (2 Replies)
Discussion started by: merturk
2 Replies

5. UNIX for Advanced & Expert Users

Status of a Linux process

All, I have fair amount of knowledge about shell scripting, but only liitle on system administration. I would like to know how to analyze whether the particular linux process is alive or not ? If it is alive, will it affect the performace of other process ?. Also is it still consuming... (1 Reply)
Discussion started by: apsprabhu
1 Replies

6. UNIX for Advanced & Expert Users

how to delay a process getting killed before it completes its work

The problem i am encountering is the process is getting killed before it dispalys the details.The details are displayed using printf.I created a new buffer for printing the details using setvbuf function call instead of output buffer.This is not working.The thing is,killing of the process must be... (1 Reply)
Discussion started by: cijkmysj
1 Replies

7. Programming

process status

hello everybody!! i want to post a question! is there any way to get process status using C commands? To be more specific, i want to know whether a process is running or is stop or killed. thanks in advance! (3 Replies)
Discussion started by: nicos
3 Replies

8. Shell Programming and Scripting

How to capture status code and echo a message

Im trying to execute application and its return code is below IF Status code=o echo "........" else Staus Code =-2 DJRE then echo "......" Can any one help me how to handle the status code and echo some message. (12 Replies)
Discussion started by: laknar
12 Replies

9. Shell Programming and Scripting

killing unix job after the job process completes

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. ... (1 Reply)
Discussion started by: dtazv
1 Replies

10. Shell Programming and Scripting

echo, append to end of file

I need the line printed with echo to append to eof of to exactly line, am i able to do that? i mean echo "sysctl -w lalala=1" > to end of file /etc/sysctl.conf or to the 21st line, if the line exist, open new line and insert text there. Thx.maybe i'm in wrong topic but anyway... (2 Replies)
Discussion started by: hachik
2 Replies
Login or Register to Ask a Question