Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
I am working on Shell script but on Solaris server (/bin/ksh is default) and not able to redirect the Std Err and Std Output to a file..following is my code ...
  1. #1
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114

    How can we redirect std err and std ouput in KSH

    I am working on Shell script but on Solaris server (/bin/ksh is default) and not able to redirect the Std Err and Std Output to a file..following is my code

    ssh hostname | grep "omega" /home/ >& test.log

    nothing is going in test.log
    Switched to Scripting

  2. #2
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    Try this:
    Code:
    ssh hostname | grep "omega" /home/ 1> test.log 2>&1

  3. #3
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    still not writing in a file
    Switched to Scripting

  4. #4
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    Quote Originally Posted by jaigs_27 View Post
    still not writing in a file
    Have you considered the possibility that you're not getting any output at all?

  5. #5
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    test.log file has to be created at runtime and I am able to see error message on the screen but it should store in to the test.log.

    error message was "connection refused"
    Switched to Scripting

  6. #6
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    Quote Originally Posted by jaigs_27 View Post
    error message was "connection refused"
    That's output of the ssh command. It's failing before you can even get to directing the output to a logfile. The command I gave you will direct standard out and standard error of the grep command to test.log.

  7. #7
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    Ohhh sorry misunderstood.

    But is there any way so that I can store that output too in a log file?
    Switched to Scripting

  8. #8
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    I guess you could try the following:
    Code:
    ssh hostname 1> test.log 2>&1 | grep "omega" /home/ 1>> test.log 2>&1
    to get all error and output from both commands into the log but I'm not sure if that will work. I don't have ssh installed on the machine I test ksh with so I can't test it. Maybe one of the scripting gurus will chime in.

  9. #9
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    Now that I think about it, my last recommendation won't work as the output will be written to the log file. Do you have to authenticate to this machine or is it public key auth?

  10. #10
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Quote Originally Posted by jaigs_27
    ssh hostname | grep "omega" /home/ >& test.log
    What is it you're expecting this to do? i.e. Explain your intentions.

    As written: ssh'ing to a hostname (which is interactive, BTW)... piping the output to grep to capture a pattern... then /home/ is tacked on for some reason.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...