Sponsored Content
Top Forums Shell Programming and Scripting How to ignore STDERR when nesting commands? Post 302312283 by Smiling Dragon on Thursday 30th of April 2009 09:33:58 PM
Old 04-30-2009
Question How to ignore STDERR when nesting commands?

I have a pel script running as root that needs to read the contents of a file on a remote system, I have an ssh trust relationship as a particular user but not as root.

I then need to write back out to that file again to change it's content a bit.

On the surface this seemed really easy but I'm getting tangled up in all the layers required to actually do this.

I'm tryint to do the following:
Code:
su - <username of this side trust relationship> -c \"ssh <username of far-side trust>@<target server> cat <filename>\"

This seems to work pretty well but it's including the login banner at the top of the "file" returned and I can't seem to get it to ignore it.

I've tried including '2> /dev/null' at various points in the line to no avail.

In order to get to the bottom of this, I've abstracted that part out into a shell script called 'remote-cat.sh:
Code:
#!/bin/sh
su - $1 -c "ssh -q -n $2 cat $3"

Which returns the login header followed by the file contents:
Code:
bash-3.00# ./remote-cat.sh username otheruser@remotehost ace.cfg.text
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
Started interactive bash shell
<AceConfig>
   <LU62>
      <Locale>ENG</Locale>
   ...

If I change my script to be:
Code:
#!/bin/sh
su - $1 -c "ssh -q -n $2 cat $3 >/dev/null"

I only see the header:
Code:
bash-3.00# ./remote-cat.sh username otheruser@remotehost ace.cfg.text
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
Started interactive bash shell
bash-3.00#

But if I change the script to use 2> /dev/null:
Code:
#!/bin/sh
su - $1 -c "ssh -q -n $2 cat $3 2>/dev/null"

I just get the header and text combined again like before.

So, where am I going wrong here? Or is there better way to do this in perl without having to do all the su, ssh, cat rubbish?
 

10 More Discussions You Might Find Interesting

1. Programming

stderr

in fprint(stderr, "lkjalsdi\n"); what does stderr mean? thanks (1 Reply)
Discussion started by: dell9
1 Replies

2. Shell Programming and Scripting

how to ignore control commands

hi, while we writing shell script, i want to ignore interrupts likes - "control + C" or "control + \" coz I just print out the message. how can i do this? thanks min (3 Replies)
Discussion started by: myoeminn
3 Replies

3. UNIX for Dummies Questions & Answers

zip nesting empty folders

I'm using the following command to zip a project file, but when it finishes, the resulting zip file contains all the directories above the file I wanted zipped, myapp.app, each one empty until you get to the actual app. zip -r myapp.app.zip ... (0 Replies)
Discussion started by: groundlevel
0 Replies

4. UNIX for Dummies Questions & Answers

Isn't a shell found on a beach? Need help nesting if's or loops.

As of a week ago i thought a shell was somthing found on a beach. I'm a virgin when it comes to scripting and i'm having a really bad time here. What i need to do is prompt for a group number grep the /etc/groups to get the GID and name if it exists i want to prompt the user for... (3 Replies)
Discussion started by: switchkill
3 Replies

5. Google Chrome OS

Case Nesting

sdfdefgsrg (2 Replies)
Discussion started by: frankycool
2 Replies

6. Shell Programming and Scripting

BASH Varible nesting and user input

Well, I think I've managed to take two different issues and conglomerate them into and embarrasing mess. #!/bin/bash # Set some variables dir1=/path/that/isnt/variable/$variabledir/dir/ dir2=/path/that/isnt/variable/$variabledir/important/"$variabledir"-subdirectory/path/ echo "Gimme... (7 Replies)
Discussion started by: karlp
7 Replies

7. UNIX for Dummies Questions & Answers

how to get stderr

Hello I try to store stderr into a variable, then if this var is not empty i send an email and stop my script. I think my problem is due of "<$dump" into my command line. my bad command line (see samples below on this post) if ! $returnedStr ; then echo ERROR READING DUMP: ... (8 Replies)
Discussion started by: giova
8 Replies

8. Shell Programming and Scripting

Nesting backticks

I'm trying to make a dialog window that prints the output of grep that takes the output of find. Unfortunately my nested backticks don't work. Here is the dialog window: dialog --stdout --title "test" --backtitle "test" --msgbox "Test:\n `grep -l "${tablica}" `find $string``" 16 60I think I... (2 Replies)
Discussion started by: Starting_Leaf
2 Replies

9. Shell Programming and Scripting

Bash - Nesting if statement in for loop

I have the basic command written in bash for element in 1 2 do if ]; then set el = "t" else set el = "p" fi done but i get the following error syntax error near unexpected token `for' ` for element in 1 2' What should i do differently? (3 Replies)
Discussion started by: ncwxpanther
3 Replies

10. Shell Programming and Scripting

Issue nesting variables in csh.

The variables given are already defined ($file1-$file3, $obsid1-$obsid3, and $n=3). When I go to run the code, the terminal outputs "Missing }." I believe the error is with the nesting of variables. It would save a lot of time getting this while loop working. set i = 1 while (${i} <=... (5 Replies)
Discussion started by: ojdefdidit
5 Replies
SSH-KEYSIGN(8)						    BSD System Manager's Manual 					    SSH-KEYSIGN(8)

NAME
ssh-keysign -- ssh helper program for host-based authentication SYNOPSIS
ssh-keysign DESCRIPTION
ssh-keysign is used by ssh(1) to access the local host keys and generate the digital signature required during host-based authentication with SSH protocol version 2. ssh-keysign is disabled by default and can only be enabled in the global client configuration file /etc/ssh/ssh_config by setting EnableSSHKeysign to ``yes''. ssh-keysign is not intended to be invoked by the user, but from ssh(1). See ssh(1) and sshd(8) for more information about host-based authen- tication. FILES
/etc/ssh/ssh_config Controls whether ssh-keysign is enabled. /etc/ssh/ssh_host_dsa_key, /etc/ssh/ssh_host_rsa_key These files contain the private parts of the host keys used to generate the digital signature. They should be owned by root, read- able only by root, and not accessible to others. Since they are readable only by root, ssh-keysign must be set-uid root if host- based authentication is used. SEE ALSO
ssh(1), ssh-keygen(1), ssh_config(5), sshd(8) HISTORY
ssh-keysign first appeared in OpenBSD 3.2. AUTHORS
Markus Friedl <markus@openbsd.org> BSD
May 31, 2007 BSD
All times are GMT -4. The time now is 01:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy