Logging Remote SSH command (cannot log a java output)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logging Remote SSH command (cannot log a java output)
# 1  
Old 08-04-2010
Logging Remote SSH command (cannot log a java output)

Hi all

I'm creating a script that runs a few commands on some boxes and everything can be logged EXCEPT the java -version command, there doesn't seem to be any output...

Can anyone help explain why this does not work? Do I need to do something extra to append the output from the java -version command to a file on the machine that I am running the script?

Thanks!

Code:
SSH_CMD=/usr/bin/ssh
USER=root
for _host in ${LIST_HOSTS}
do
        ${SSH_CMD} ${USER}@${_host} hostname | tee -a results.txt
        ${SSH_CMD} ${USER}@${_host} 'java -version'
        ${SSH_CMD} ${USER}@${_host} 'uname -a' |tee -a results.txt
        ${SSH_CMD} ${USER}@${_host} 'prtdiag -v | grep -i OBP' |tee -a results.txt
        echo "\n" | tee -a results.txt
done


Last edited by Scott; 08-04-2010 at 02:20 PM.. Reason: Code tags, please...
# 2  
Old 08-04-2010
Hi.

On my system:

Code:
/Users/scott $ java -version > /dev/null
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)

This tells me that the version information is written somewhere else (actually standard error), so, try:
Code:
${SSH_CMD} ${USER}@${_host} 'java -version 2>&1' | tee -a results.txt


Last edited by Scott; 08-04-2010 at 02:34 PM..
# 3  
Old 08-04-2010
That is VERY interesting!

And it worked! Thank you Smilie

Does anyone know why that the java output would be considered STDER (my wild guess is that the programmers who worked on java had the output go to SDTERR? )
# 4  
Old 08-04-2010
Quote:
Originally Posted by Keepcase
(my wild guess is that the programmers who worked on java had the output go to SDTERR? )
The words "head", "the", "on", "nail" and "hit" spring to mind!

But it doesn't really surprise me that they did it differently, although I'm sure they had their reasons Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

Getting SSH Output From Remote to Local Session?

Hi everyone, after about 2 days of scratching my head on this one, I'm finally ready to punt this and ask for some actual help. Here's the situation. We have 1 server, that runs multiple VM's. To gain access to those VM's we ssh from host01 to the other vm hosts. For example when we first log... (4 Replies)
Discussion started by: Lost in Cyberia
4 Replies

3. Shell Programming and Scripting

SSH - remote output locally

The code below works ok, however; I need to output the results to a local variable the_path="/mnt/back/hang" ssh -T -i /home/buddy/.ssh/id_rsa buddy@ginger << EOF find ${the_path} -name "*.jpg" | wc -l > ## output to local variable exit EOF (3 Replies)
Discussion started by: squrcles
3 Replies

4. Shell Programming and Scripting

Remote command in variable using ssh

Hi, I've an issue in a shell script: I'm opening an ssh connection to a remote server, then I want to store the result of a ls command in a variable, but it doesn't work: the ls is done on the local machine. ssh user@server << EOF ls # works as expected (ls is done remotely) test=`ls` # the... (1 Reply)
Discussion started by: seloum57
1 Replies

5. UNIX for Advanced & Expert Users

Not logging ftp connections in /var/adm/wtmpx file (in last command output)

Hi all, I have F5 load balancer on my system and checking service status by opening an ftp session in every 30 seconds. These ftp sessions are being logged in /var/adm/wtmpx and filling up the file. when i run the last command most of the output is this ftp session. I was wondering if there is a... (1 Reply)
Discussion started by: cepxat
1 Replies

6. AIX

Remote Script command logging question

I've noticed that when running a script that connects to a number of our servers (to essentially run batch commands) that the commands aren't logged in the user's .sh_history or .bash_history files. Is there a place where this is logged (assuming the script itself isn't doing the logging and I'm... (3 Replies)
Discussion started by: kneemoe
3 Replies

7. UNIX for Dummies Questions & Answers

Automatic logging (capture screen output) of telnet/ssh sessions on a Solaris node

Hi I am working in Solaris 10 and I want to monitor logs for every telnet/ssh session that tries to connect to the server. I need these logs to be generated in a file that I can fetch using ftp. I am a new user and a stepwise detail will be great BR saGGee (3 Replies)
Discussion started by: saggee
3 Replies

8. Solaris

How to invoke remote java program from ssh

How can i invoke java program from MC1, when I connect remotely to execute can I set classpath etc. ____________ <-------------->____________________ |..................|<-------------->|...............................| |..................|<-------------->|...............................|... (2 Replies)
Discussion started by: vishnu559
2 Replies

9. UNIX for Dummies Questions & Answers

Logging Command Line and Output in Unix

Hi, This might be a bit stupid question, but what command to use to create like a session which logs the command line, and output on to the screen? Basically, a log to a file, where I can review what I had install, uninstall, etc. Thank you (4 Replies)
Discussion started by: kittoinc
4 Replies

10. UNIX for Advanced & Expert Users

SSH and command logging

Hi all... I've completed the task of deploying SSH over my 400 servers. I don't know if i'm right or wrong, but ssh doesn't do any command-logging, does it? Is there a app i can use to log all commands passed ( besides the usual .sh_history), whith no modification possible by the user, and how... (2 Replies)
Discussion started by: penguin-friend
2 Replies
Login or Register to Ask a Question