Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all, So I have an interesting question for all you knowledgeable forum'ers I have 8 Linux boxes running Websphere server, and I want to grab logs from all the ...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    11

    [SOLVED] Remote and local execution in ``

    Hi all,

    So I have an interesting question for all you knowledgeable forum'ers I have 8 Linux boxes running Websphere server, and I want to grab logs from all the machines, perform grep on them and upload all the logs to one main node. In order to do that, I decided to use ssh execution of the in-line script to get this done, eg. on main node (say p01), I run the following command:

    userone@p01:ssh p08 "yesterday=`date +%y.%m.`$((`date +%d`-1));echo $yesterday;/bin/hostname>/home/userone/host_$yesterday;echo hello$yesterday;cd /proj/WebSphere/wcs/prd1a/logs/server1;for f in `ls -tr SystemOut*`; do grep "Test" $f > /home/userone/SystemOutMain_$yesterday.log; done;"

    And what I have is:
    ksh: syntax error: `SystemOut_08.11.18_16.24.01.log' unexpected

    Now the interesting part: there is no file called SystemOut_08.11.18_16.24.01.log on the remote machine, this one is from local machine. The question is: why is that? Is the script in `` executed locally? How to do the same on remote machine, that is how to loop over REMOTE directory in the script? Thanks very much.

  2. #2
    Just Joined!
    Join Date
    Nov 2008
    Posts
    11
    Found out - yes the `ls -tr` executed locally... How to inject remote files into the loop? Thanks.

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    So yes, that is all executed locally. What you're trying to do is going to be rather difficult in a single SSH command. What I would recommend is putting a script on each of your hosts that does the work and pushes the results to the main node. Now you can use a loop to SSH into each box and run that script. This will be far simpler.
    DISTRO=Arch
    Registered Linux User #388732

  4. #4
    Just Joined!
    Join Date
    Nov 2008
    Posts
    11
    Hi Cabhan,
    Thanks for the hint - still trying to avoid putting this script onto all target nodes - here is what I;ve come up with so far:

    ssh p08 "yesterday=`date +&#37;y.%m.`$((`date +%d`-1));ls -tr /proj/WebSphere/wcs/prd1/logs/server1/SystemOut_$yesterday* > /home/userone/ls.out;while read LINE; do grep -v 'Test' $LINE >> /home/userone/grep.out; done < /home/userone/ls.out"

    but still the grep produces empty output and the result file contains 7 empty lines ($LINE not getting set?) When I run this snippet on target machine it works as required - produces the grep output properly.

  5. #5
    Just Joined!
    Join Date
    Nov 2008
    Posts
    11
    Worked after escaping the $LINE:

    ssh p08 "yesterday=`date +&#37;y.%m.`$((`date +%d`-1));ls -tr /proj/WebSphere/wcs/prd1/logs/server1/SystemOut_$yesterday* > /home/userone/ls.out;while read LINE; do grep -v 'Test' \$LINE >> /home/userone/grep.out; done < /home/userone/ls.out"

Posting Permissions

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