Sponsored Content
Top Forums Shell Programming and Scripting Reading UNIX commands from file and redirecting output to a file Post 302537334 by rahulparo on Thursday 7th of July 2011 10:40:32 PM
Old 07-07-2011
Lightbulb Reading UNIX commands from file and redirecting output to a file

Hi All

I have written the following script:
Code:
#!/bin/ksh
while read cmdline
do 
  echo `$cmdline`
  pid="$cmdline"
done<commands.txt

===========
commands.txt contains:
Code:
ps -ef | grep abc | grep xyz |awk '{print $2};

My objective is to store the o/p of the command in a variable and do ceratin operations on it. It works fine if i just ls but not working with pipe...

Last edited by Franklin52; 07-08-2011 at 03:42 AM.. Reason: Please use code tags for code and data samples, thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting output of a command to a file

Hi We are having a requirement where one shell script, say a.sh (which uses Java and connects to Oracle database using JDBC) keeps on running everytime. I created a wrapper (to check whether a.sh is running and if not then to start it) and scheduled it in the crontab. Now all the output from... (3 Replies)
Discussion started by: ankitgoel
3 Replies

2. Shell Programming and Scripting

Redirecting command output as well as commands

I have a Bourne Shell script that is normally run as a background job and redirects it's output to a file internally (using exec >>); I use "set -x" to capture each command which provides me with a nice shell execution log if it all goes to pieces. I now also need to be able to also run this as... (4 Replies)
Discussion started by: AncientCoder
4 Replies

3. Shell Programming and Scripting

Redirecting output of Make to file

Hi, I am unable to get this script to work as desired. Basically, if an argument "log" is sent into the script, it outputs the result of the Make to a file output.log. However, if the argument is not passed, I want the output to be just put on screen (no redirection). See code snippet below. #... (3 Replies)
Discussion started by: srujan45
3 Replies

4. Shell Programming and Scripting

Redirecting output to file

Hi, Below is the whole string which is to be redirected to the new file. su - oracle -c "exp $user/$pass file=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.log tables=table1,table2 statistics=none" ... (3 Replies)
Discussion started by: milink
3 Replies

5. UNIX for Dummies Questions & Answers

redirecting the script output to more than 1 file

Hi, I want to redirect my script output to more than one file without printing the result to the screen. How to do that? ex: echo "hi" >> a.txt b.txt cat a.txt hi b.txt :confused: (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

6. Solaris

How can I output all previous Unix commands in Solaris to a file??

Hello friends: I login to solaris with a username/Password and I can see quite a lot of previous I use dbefore, it accumulates a lot, I hope to output them into a Command.txt file as reference, not copy/paste 1 by 1, is there any way I can collect all commands in batch then put into a file, ... (3 Replies)
Discussion started by: sunnysunnysunny
3 Replies

7. UNIX for Dummies Questions & Answers

Redirecting the multiple commands output to single file

Hi, I am new to shell scripting and have a question. I would like to redirect the output of multple commands to single file, From what I read from the bash manpage and from some searching it seems it cannot be done within the shell except setting up a loop. Is it? I am running all clearcase... (1 Reply)
Discussion started by: saku
1 Replies

8. UNIX for Dummies Questions & Answers

Help with redirecting output to an HTML file

I'm very new to shell scripting and am practicing how to write a script, then redirect the output into an HTML file, and then email both the script and the HTML file to myself. I have created a script called sysinfo_page, and thought it would have redirected the output into the sysinfo_page.html... (3 Replies)
Discussion started by: braing
3 Replies

9. Homework & Coursework Questions

Help with redirecting output to an HTML file

1. The problem statement, all variables and given/known data: I'm having trouble redirecting the output of my sysinfo_page script into my sysinfo_page.html file. The task at hand is to be able to email both the html file and the script to myself. I'm assuming that the html should appear as a web... (8 Replies)
Discussion started by: braing
8 Replies

10. Shell Programming and Scripting

Redirecting output to file

Hi, I have created script which redirect the output to file.I am able to get the output in file but not in the format. Output :Content of the log which have 10 -15 lines. Actal :Line1 ..Line 2Line3 Line4 Line 5 Expected:Line1 Line 2 Line3 Please... (7 Replies)
Discussion started by: karthik771
7 Replies
cmdline(n)						Command line and option processing						cmdline(n)

__________________________________________________________________________________________________________________________________________________

NAME
cmdline - Procedures to process command lines and options. SYNOPSIS
package require Tcl 8.2 package require cmdline ?1.3.1? ::cmdline::getopt argvVar optstring optVar valVar ::cmdline::getKnownOpt argvVar optstring optVar valVar ::cmdline::getoptions arglistVar optlist ?usage? ::cmdline::getKnownOptions arglistVar optlist ?usage? ::cmdline::usage optlist ?usage? ::cmdline::getfiles patterns quiet ::cmdline::getArgv0 _________________________________________________________________ DESCRIPTION
This package provides commands to parse command lines and options. ::cmdline::getopt argvVar optstring optVar valVar This command works in a fashion like the standard C based getopt function. Given an option string and a pointer to an array or args this command will process the first argument and return info on how to proceed. The command returns 1 if an option was found, 0 if no more options were found, and -1 if an error occurred. argvVar contains the name of the list of arguments to process. If options are found the list is modified and the processed arguments are removed from the start of the list. optstring contains a list of command options that the application will accept. If the option ends in ".arg" the command will use the next argument as an argument to the option. Otherwise the option is a boolean that is set to 1 if present. optVar refers to the variable the command will store the found option into (without the leading '-' and without the .arg extension). valVar refers to the variable to store either the value for the specified option into upon success or an error message in the case of failure. The stored value comes from the command line for .arg options, otherwise the value is 1. ::cmdline::getKnownOpt argvVar optstring optVar valVar Like ::cmdline::getopt, but ignores any unknown options in the input. ::cmdline::getoptions arglistVar optlist ?usage? Processes the set of command line options found in the list variable named by arglistVar and fills in defaults for those not speci- fied. This also generates an error message that lists the allowed flags if an incorrect flag is specified. The optional usage-argu- ment contains a string to include in front of the generated message. If not present it defaults to "options:". optlist contains a list of lists where each element specifies an option in the form: flag default comment. If flag ends in ".arg" then the value is taken from the command line. Otherwise it is a boolean and appears in the result if present on the command line. If flag ends in ".secret", it will not be displayed in the usage. ::cmdline::getKnownOptions arglistVar optlist ?usage? Like ::cmdline::getoptions, but ignores any unknown options in the input. ::cmdline::usage optlist ?usage? Generates and returns an error message that lists the allowed flags. optlist is defined as for ::cmdline::getoptions. The optional usage-argument contains a string to include in front of the generated message. If not present it defaults to "options:". ::cmdline::getfiles patterns quiet Given a list of file patterns this command computes the set of valid files. On windows, file globbing is performed on each argu- ment. On Unix, only file existence is tested. If a file argument produces no valid files, a warning is optionally generated (set quiet to true). This code also uses the full path for each file. If not given it prepends the current working directory to the filename. This ensures that these files will never conflict with files in a wrapped zip file. The last sentence refers to the pro-tools. ::cmdline::getArgv0 This command returns the "sanitized" version of argv0. It will strip off the leading path and removes the extension ".bin". The latter is used by the pro-apps because they must be wrapped by a shell script. EXAMPLES
set options { {a "set the atime only"} {m "set the mtime only"} {c "do not create non-existent files"} {r.arg "" "use time from ref_file"} {t.arg -1 "use specified time"} } set usage ": MyCommandName [options] filename ... options:" array set params [::cmdline::getoptions argv $options $usage] if { $params(a) } { set set_atime "true" } set has_t [expr {$params(t) != -1}] set has_r [expr {[string length $params(r)] > 0}] if {$has_t && $has_r} { return -code error "Cannot specify both -r and -t" } elseif {$has_t} { ... } This example, taken (and slightly modified) from the package fileutil, shows how to use cmdline. First, a list of options is created, then the 'args' list is passed to cmdline for processing. Subsequently, different options are checked to see if they have been passed to the script, and what their value is. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category cmdline of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
argument processing, argv, argv0, cmdline processing, command line processing cmdline 1.3.1 cmdline(n)
All times are GMT -4. The time now is 12:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy