Banner causes scp to fail from script but not command line.
Hi,
We have an interesting issue which is similar to the one in this thread, but that never provided a full answer. - Ohh apparently I can't post URLs till I have 5 posts, sorry.
We have a simple script that copies files from one shelf to the other. Both shelves have an ssh banner defined. When I run the script the scp to the remote shelf fails however if does not when the same command is run from the command line. When I pipe the output to a file, the error output displays the banner from the remote shelf.
Piping the error output to a file solves the problem and the scp works fine, however I don't understand why and I was wondering if anyone could explain. We have quite a few places in the code where the output is not currently piped to /dev/null (stderr) and I really want to understand the cause of the problem so that I know whether I need to correct all of them or just ones in certain formats/shells or indeed if it is a config problem?
The code I am running is as follows (I have removed any parts that could be company sensitive (e.g. <remote shelf ip> if not the actual code in this line but does work):
When I run the scp with the -v option, this is the output I get (fjmfjf is the remote shelf banner - a pretty rubbish banner I'll admit, it has been like that for years though):
If anyone could through some light on why this is happening it would be greatly appreciated. From my google investigations, I think it is something to do with the banner text being incorporated into the ssh command but that's about it.
Yeah sorry that is what I mean, I'm not very good at scripting yet so get my terminology a bit mixed up.
Could you possibly explain what you mean be: "fd 2 of the batch run is messed up. Interactively, it is the tty."
---------- Post updated 08-03-11 at 12:50 PM ---------- Previous update was 08-02-11 at 11:56 PM ----------
Hi again,
One of the lovely people from work who is actually good at their job has explained your answer and that does indeed seem the most likely explanation as the file that calls this script behaves slightly oddly and doesn't have any paths set up (I think because it is one of the first things run when the system starts up).
Thanks for the help, do you know if there is a way to specify for a who file where the stderr output should be directed to in case anyone in future forgets to redirect it? If not I will just update the comment at the top of the script to inform them of the need to do so.
Yes, having a .profile or env file to run first is always a good idea, so it runs like interactive in cron or other non-interactive milieu. I used to test using "ssh localhost command args" to see how it runs without a tty or built env.
If fd 2 was closed, nobody can enjoy writing to stderr or fd 2 until it is replaced with an open fd.
Short overview of files, fd, FD, FILE*, stdin, stderr, stdout. Programs written in languages such as C wake up with already established symbols stdin, stdout, stderr: FILE*, which are inside the process with buffers, for stderr set to 0 buffer, using fd # 0, 1 and 2, respectively. A fd is just an integer offset to an array in the Kernel Process Area, of pointers to actual FD in the kernel resulting from open(), socket(), pipe(), accept(). Thus, the same FD can be under many fd # in many processes. All those processes may have FILE* buffers, so it is a danger of scrambled lines if they all write (to the internal buffer) and do not fflush() the FILE* buffer to the fd with every line (an available option). Similarly, shared input can get read into a buffer by command 1 and not be found by command 2 reading a shared fd. This is why the 'line' command was coded -- reads one line from fd and stops. Since stderr is for errors, it is not buffered, and not a good place for volume. Exit() gracefully closes all FILE*, flushing them before close(). Excess input read into buffers is discarded, since you cannot push data back into a FD, generally. (You can push 1 byte back into a FILE*, but this within one process!)
A process can even open a file and send the pointer to another process to install into that process FD* array, which some web servers do to distribute incoming TCP connections to an army of child web servers. The master just listens, accepts and sends the connection FD to a child over a local pipe or socket. Of course, you cannot send a FD off host, different kernel, so I am not sure how clusters deal with this!
In shell, the inheritance of fd is great, and the subshell is a great way to use it. All the commands in (...) inherit the same input, output and error FD unless they are piped or redirected. You can pipe and redirect the whole (...) once for all. You can concatenate the output of many commands. This is both robust and fast, since nothing is actually happening but the sharing of common FD. For instance, if you want to sort lines 2-N of a huge file, do not run all lines through any command, just do this:
Hi guys can i get banner equivalent command in linux.
I am using
Linux xcclx0619.target.com 2.6.18-308.11.1.el5xen #1 SMP Fri Jun 15 16:19:17 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux (1 Reply)
:wall:
Is there a way to prevent the banner from displaying from the remote host when using scp? I see from the man pages that the '-o' option passes args to ssh and I've tried several variations of:
scp -o "-q" file remotehost:
Anybody got this to work?
Thanks in Advance (3 Replies)
Hi,
I has the following command in the script. This command works fine if I execute on command prompt. If I run the script, this is not working as expected (deleting CR).
tr -d "\015" < ${FilePath}/${FileName} > ${FilePath}/${File_Prefix}.csv
I could not figure out whats... (6 Replies)
Hi,
I am logging in into an UNIX environment with my user id and password.
I want to display my name there , each time I login into the environment,
for which I can use the banner command.
Which file should I add the banner command to , so that I will get the desired result?
Regards,... (7 Replies)
Iam a MCA student having some doubts about
1) different disk related commands
2) Banner command
3) Different file related commands
4) set eb (where it is used) (1 Reply)
hello,
I am using banner command in my shell.I used :-
The problem is that the output is printed in 3 separate lines.I want to display it in a single line.If the size is not enough then at least 2 words should come in the same line. Can you tell me what is the option in banner that would help... (4 Replies)
hi,
When i execute banner command the output is being displayed as
banner:command not found
When ever i give yum install banner the output is
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Parsing package install arguments
Nothing to do
what... (8 Replies)
Hey all,
I want to use the banner/echo command to write messages on different console windows.
I knew that before, but I completely forget how to do it ! I just remenber that /dev/pts/# is the number of the window. and it's useful.
It would be great if someone knows how to solve my... (4 Replies)