Ksh: run commands from pipe


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ksh: run commands from pipe
# 1  
Old 10-14-2014
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:

Code:
 echo "print Hello World!"| ksh

What is the "best" command at the end of the pipe to execute the commands that come down the pipe?
# 2  
Old 10-14-2014
Try this instead of pipe

Code:
echo 'print Hello World' >/dev/null  2>&1

meaning redirect both output and errors to /dev/null
# 3  
Old 10-14-2014
Quote:
Originally Posted by Akshay Hegde
Try this instead of pipe

Code:
echo 'print Hello World' >/dev/null  2>&1

meaning redirect both output and errors to /dev/null
??? ... that's not what I asked for. Was I that unclear?
# 4  
Old 10-14-2014
Quote:
Originally Posted by Akshay Hegde
Try this instead of pipe

Code:
echo 'print Hello World' >/dev/null  2>&1

meaning redirect both output and errors to /dev/null
Hello Akshay Hegde/Cochise,

There is no meaning for using >/dev/null 2>&1 in case of echo. We can use this command if we are running any script and we want to see output if that script is storing it in any output file, also it will avoid errors too while execution of script too. There this command can be useful.

./script.ksh >/dev/null 2>&1


Thanks,
R. Singh
# 5  
Old 10-14-2014
Quote:
Originally Posted by Cochise
??? ... that's not what I asked for. Was I that unclear?
I am sorry, what kind of commands you are creating ? its bit unclear to me, whether you are trying to create commands which can be executed on shell ? is so you are on right path you can ksh, sh etc.
# 6  
Old 10-14-2014
ksh is "best" if you want to use ksh.
sh is "best" if you want to use sh.
zsh is "best" if you want to use zsh.

etc.

But why bother? Why not just run the command, instead of printing it? Shell-within-shell or eval bruteforcing usually means something else was forgotten along the way.

Last edited by Corona688; 10-14-2014 at 03:56 PM..
# 7  
Old 10-15-2014
For better understanding of my problem, here is the long story:

I have a large log file, that has some lines like this:
Code:
skipping: /usr/bin/chuser "gecos=ipsec;MDE0M819;;F" ipsec (TESTMODE)
skipping: /usr/bin/chuser "gecos=nobody;MDE0M819;;F" nobody (TESTMODE)
skipping: /usr/bin/chuser "gecos=perfmgr;MDE0M819;;F" perfmgr (TESTMODE)

The lines may occur multiple times.

I want to find these lines, remove duplicates, strip off "skipping:" and "(TESTMODE)" and then execute the remainining chuser command.

What I have built is this:
Code:
grep 'chuser "gecos=' modify.LOG|sort|uniq|sed 's/skipping: //; s/ (TESTMODE)//'|ksh

This works and is what I asked for.

New question: I would like to have the command string displayed on the terminal before it is send to ksh for execution.
Is there a smarter and shorter way than doing it in a do loop like below?

Code:
grep 'chuser "gecos=' modify.LOG|sort|uniq|sed 's/skipping: //; s/ (TESTMODE)//'|while read line;do print - $line;ksh "$line";done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

How to run commands with pipe from text file?

Hello, I have standard loop while read -r info; do command $info done < info in info text file I have multiple commands each on line that I want to execute. When I used them in console they worked, but not with this loop. This is one of the commands in info file: grep... (4 Replies)
Discussion started by: adamlevine
4 Replies

2. Shell Programming and Scripting

Pipe or combine output of three awk commands

What is the correct syntax to pipe or run three awk commands? Basically, using the output of the first awk as input in the second. Then using the output of the second awk in the third. Thank you :). awk 'FNR==NR {E; next }$3 in E {print $3, $5}' panel_genes.txt RefSeqGene.txt > update.txt |... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. 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

4. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

5. UNIX for Advanced & Expert Users

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?. echo "ABC process started on `date`" some code.. echo... (12 Replies)
Discussion started by: engineer
12 Replies

6. UNIX for Dummies Questions & Answers

Checking return value of commands in pipe

Hi, I am wondering how I can check the return value of all commands in a pipe such as gzip -dc file.gz | sort -u > output.txt If I run this sequence in bash and check $?, I get the return status from sort. But I want to know if the initial gzip failed. Similarly for longer pipe chains,... (6 Replies)
Discussion started by: btherl
6 Replies

7. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

8. UNIX for Dummies Questions & Answers

Cannot run commands

It would be helpful if someone could help me out here. The problem I have been having is that I cannot run some commands which are valid - whenever I try to run the command I get the message "command not found". Now, if I run the same command as root it executes. These commands do not have to be... (5 Replies)
Discussion started by: BigTool4u2
5 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