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:
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:
#!/bin/sh
su - $1 -c "ssh -q -n $2 cat $3"
Which returns the login header followed by the file contents:
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:
#!/bin/sh
su - $1 -c "ssh -q -n $2 cat $3 >/dev/null"
I only see the header:
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:
#!/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?