Computing.Net > Forums > Unix > Shell script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shell script

Reply to Message Icon

Name: viv_2300
Date: March 15, 2005 at 17:27:37 Pacific
OS: Unix
CPU/Ram: unknown
Comment:

The following script perhaps uses awk and system commands

Write a simple shell script to do the following.
a) Read a set of commands specified in a file cmd.txt
b) Execute them one by one, save the output.
c) After all the command executions are complete, print the outputs properly formatted to show which output belongs to which command. Also show the return status of each command.

Vivek



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 15, 2005 at 21:19:57 Pacific
Reply:

I don't think you'll get much help with home work without at least showing some effort. What do you have so far?



0

Response Number 2
Name: viv_2300
Date: March 16, 2005 at 05:07:56 Pacific
Reply:

I am able to proceed this far

grep "" cmd.txt | sh -v > output

This reads a set of commands specified in a file cmd.txt, Executes them one by one, saves the output.

Vivek


0

Response Number 3
Name: nails
Date: March 16, 2005 at 09:02:28 Pacific
Reply:

Why don't you read the file a line at a time and execute each command redirecting the output to a file:

#!/bin/ksh

while read cmds
do
eval "$cmds >> output.file"
done < mycmds.txt



0

Response Number 4
Name: snackhound
Date: March 20, 2005 at 17:49:14 Pacific
Reply:

I'm not the original poster of this question. But I do not quite understand the last sollution. If you have the time can you explain it.

Thanks in advance


0

Response Number 5
Name: nails
Date: March 21, 2005 at 14:39:22 Pacific
Reply:

Hi:

Be glad to. All of the valid unix commands are listed, one per line, in file mycmds.txt.
The while loop reads mycmds.txt one line at a time. I build a command string from each line of input and redirect the ouput appending it to output.file with >>.

The command string is an argument to the eval command. When the eval command executes, the argument is treated as input to the shell, i.e. ksh in this case, and the resulting commands as defined in the string, execute.

Regards,

Nails


0

Related Posts

See More



Response Number 6
Name: Jc
Date: March 25, 2005 at 00:56:17 Pacific
Reply:

To find the return status of each command - $?


www.finepick.com the 100% FREE Online Classifieds (Chennai)

Jc


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Shell script

Shell Scripting www.computing.net/answers/unix/shell-scripting/8475.html

Variables in Shell SCripting www.computing.net/answers/unix/variables-in-shell-scripting/6020.html

shell script to uninstall java www.computing.net/answers/unix/shell-script-to-uninstall-java-/5976.html