Better KSH commands


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Better KSH commands
# 1  
Old 11-16-2009
Better KSH commands

Are there any documents available for checking the execution time taken by ksh commands?

My requirement is to fine tune a set of shell scripts having lot of "echos" and "date"s.
Is there a better replacement for the below code?.
Code:
 
echo "ABC process started on `date`"
some code..
echo "ABC process ended on `date`"
echo "BAC process started on `date`"
some code
echo "BAC process ended on `date`"
.......................
.......................
Thus it goes on...

These lines with very less difference is repeated more than 3000 times in my shell script.Please post any method by which I can reduce the execution time.

Last edited by engineer; 11-16-2009 at 05:04 AM..
# 2  
Old 11-16-2009
We don't know what
Code:
process command

is doing. Could you please explain that?

Check this command for capturing time taken to run a process
Code:
time

# 3  
Old 11-16-2009
"process commands" are the other lines in my shell script through which I complete my tasks. Its not code.
# 4  
Old 11-16-2009
Quote:
Originally Posted by engineer
"process commands" are the other lines in my shell script through which I complete my tasks. Its not code.
I guess your initial question was optimization of the script. In that case, without knowing what " process command " is doing, its not possible to provide suggestions on script optimization. Sorry if process optimization is not ur question Smilie
# 5  
Old 11-16-2009
Sorry if I created any confusion here. I will explain my query.

I have these similar lines of code all through my korn shell script(my_script.sh). I have many shell scripts (ABC.sh,BAC.sh,CAC.sh,LKJ.sh,POI.sh and many hundreds) which is run through this parent shell script.
Below is my_script.sh:
Code:
echo "ABC.sh started at `date`"
sh ABC.sh
echo "ABC.sh ended at`date`"
echo "BAC.sh started at `date`"
sh BAC.sh 
echo "BAC.sh ended at `date`"
.......................
.......................

Thus it goes on for other files too...

Can I reduce the execution time of my parent script by changing the echo command or date command? I have heard that cat is a better replacement for echo. But will it work in this case?
# 6  
Old 11-16-2009
3000 lines with `date` in them means you create 3000 child processes - one for each date command. This is very expensive timewise.
# 7  
Old 11-16-2009
Quote:
Originally Posted by engineer
Sorry if I created any confusion here. I will explain my query.

I have these similar lines of code all through my korn shell script(my_script.sh). I have many shell scripts (ABC.sh,BAC.sh,CAC.sh,LKJ.sh,POI.sh and many hundreds) which is run through this parent shell script.
Below is my_script.sh:
Code:
echo "ABC.sh started at `date`"
sh ABC.sh
echo "ABC.sh ended at`date`"
echo "BAC.sh started at `date`"
sh BAC.sh 
echo "BAC.sh ended at `date`"
.......................
.......................

Thus it goes on for other files too...

Can I reduce the execution time of my parent script by changing the echo command or date command? I have heard that cat is a better replacement for echo. But will it work in this case?
Probably you could try embedding these multiple commands into a perl script and make use of localtime() instead, so that you dont have to call date command 3000 times or more

If you are using cat, essentially you will have to push that to a file and display from that, am not sure why do you want to do that!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: run commands from pipe

I create commands within a pipe and finally want them to be executed instead of being displayed on the screen. What is the last stage in this pipe? I found by guessing that "ksh" is working, but is this the best to use here? It boils down to this: echo "print Hello World!"| kshWhat is the... (15 Replies)
Discussion started by: Cochise
15 Replies

2. UNIX for Dummies Questions & Answers

ksh with Oracle commands

works fine. echo "Deleting CHOPOne Coreaccess from LAUA..." $ORACLE_HOME/bin/sqlplus username/password@servername << ! delete from usergrpdtl where username='acker'; commit; ! but not working with "if statement" even $TMPDIR/adlogin.log exists and greater than 0. if then ... (9 Replies)
Discussion started by: lawsongeek
9 Replies

3. Shell Programming and Scripting

Sequential execution of commands in ksh

I need to run few commands in a ksh script sequentially. Some of the commands are jobs submitted to the server and the consecutive commands are dependent on the completion of the jobs submitted to the server. It works if i separate the commands into different files like this #!/bin/ksh... (1 Reply)
Discussion started by: prashob123
1 Replies

4. Shell Programming and Scripting

SED sub commands in KSH not working for me

I am using SED to edit a file (called file) the file contains the word "ERROR" and I want to use SED to: 1. Search for text "ERROR" If found, 2. Append new line with text "hoi" I tried: sed 's/ERROR/ a\hoi' file sed 's/ERROR/ a\ hoi' file I get all the time the error sed:... (7 Replies)
Discussion started by: Alex400
7 Replies

5. UNIX for Dummies Questions & Answers

Calling commands with ksh

Hi, I am not able to run below command on linux, it however works on solaris. If anyone knows the reason and a solution for it can you please let me know ? Linux ----- $> ksh 'echo hi' ksh: echo hi: No such file or directory $> which ksh /usr/bin/ksh Solaris ------ $> ksh 'echo... (2 Replies)
Discussion started by: krishnaux
2 Replies

6. Shell Programming and Scripting

Stringing Multiple commands together in KSH

I am trying to to this findCDZfile=`ls -at `find /opt/apps/busobj/bobj/bobje/data/ -name CDZ*.tmp`` and it doesn't seem to like me - is there a special escape character I need to use? (2 Replies)
Discussion started by: cpare
2 Replies

7. Shell Programming and Scripting

KSH variable containing piped commands

Hi, I am trying to execute a bunch of piped command which are stored in a variable, but only one command executed at a time, and rest of the pipes, commands and their arguments are considered as argument to the very first command. Can you please help me in this? bash-2.05$ cat test.sh... (1 Reply)
Discussion started by: prashant.ladha
1 Replies

8. Shell Programming and Scripting

ssh commands in ksh question

Is there a way to shorten these commands? because this script asks for a password 3 times scp -p /usr/local/bin/${script_name} ${servername$iy]}://usr/local/bin/ ssh ${servernames} /usr/local/bin/${script_name} ssh ${servernames} rm -f /usr/local/bin/${script_name} Basically, I'm creating a... (3 Replies)
Discussion started by: pdtak
3 Replies

9. UNIX for Dummies Questions & Answers

ksh substring commands

I am trying to get various portions of strings in my script, but am getting a substitution error. I followed the syntax that was described when I goggled this, but I can't get anything to work. #! /bin/ksh/ hello="adklafk;afak" #hello=${hello:3} hello=${$hello:3} happy="hey" echo... (1 Reply)
Discussion started by: anderssl
1 Replies

10. Shell Programming and Scripting

ksh GUI commands

I have a few scripts that i would like to make into GUI's. Are there scripting commands to make GUI's if so where can i get the list of commands and what they do or if anyone has an example of it. Anything will help, thanks (1 Reply)
Discussion started by: daltonkf
1 Replies
Login or Register to Ask a Question