Reading file from remote system and work on it locally


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading file from remote system and work on it locally
# 8  
Old 03-22-2011
Hi again!

I have made some modifications to my script, and it displays fairly OK, but I have some issues with the first value soemtimes being a longer string then other value's. Then my display is messed up.

Code looks like this:

Code:
#!/bin/sh
# Usage: script [IP] [user] [filename]

ARGS=3

if [ $# -ne $ARGS ]
then
    echo "$0:Error, missing or too many arguments!"
    echo "Usage: $0 IP user filename"
    exit 1
fi

IPADRESS=$1
USERNAME=$2
FILENAME=$3

get_data()
{
    ssh $USERNAME@$IPADRESS "cat $FILENAME" | awk 'BEGIN{ FS=OFS="," } { print $2"\t\t"$4"\t"$9"\t"$11 }'
}

while true
do
    clear
    echo "Last updated: \c"; date --utc
    echo "Value2\Value4\Value9\t\t\Value11"
    echo "-----------------------------------------------------------------"
    get_data
    sleep 600
done

This is just to make it look more pretty (I guess the inf loop is not optimal either). The data is retrieved well as is, but handy to be able to get an easy overview of the data by displaying it properly.

I have used tabulators to get the desired positions, and this works fine execpt on the occations were the lengt of Value2 is different (the other values do not change as much, value4 might be 2 or 3 in lenght, value9 and value11 is the same all the time). So my question is what canI do to make sure the values are dispalyed propely? E.g. I want to have something that looks like this for all lenghts of values:
Code:
Desription             Desription              Desription            Desription
Value2                 Value4                  Value9                Value11
Value2                 Value4                  Value9                Value11
Value2                 Value4                  Value9                Value11

# 9  
Old 03-22-2011
Use printf in awk. like below
Code:
printf "%-20s\t%-10s\t%-10s\t%-10s\n",$2,$4,$9,$11

This User Gave Thanks to pravin27 For This Post:
# 10  
Old 03-22-2011
Ah! nice, thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read file input in while loop does not work on AIX system

I'm working on Aix 6.1 and using ksh shell. The below works fine on Linux bash or ksh shell . while IFS= read -r dirpath ; do echo "Hi" done <<<"$var" However, any such while loop that reads the input from file or variable using <<< fails on Aix system with the below error: Below... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Ssh remote command doesn't work from script file

I have 10 application servers in a distributed architecture generating their own application logs. Each server has application utility to continuously tail the log. for example following command follows tails and follows new logfiles as they are generated server1$ logutility logtype When I run... (8 Replies)
Discussion started by: indianya
8 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

Editing a file on remote server using shell script locally

Hi Scott, My previous post was not for any school or college projects. I am currently working with a IT company (Cannot provide more details than this). I am trying to implement the below script in my day-to-day work, Apologies for the confusion in previous post :). My question remains same... (4 Replies)
Discussion started by: Nishant Ladiwal
4 Replies

5. Shell Programming and Scripting

Editing a file on remote server using shell script locally

Hi All, I have below requirements for my project: 1. Building a shell script which connects to a remote server 2. running script on local machine as user 'A' 3. connecting to server using user 'B' with password 4. login with a powerbroker role 'P' (asks for same password as 'B') on that... (1 Reply)
Discussion started by: Nishant Ladiwal
1 Replies

6. Shell Programming and Scripting

Reading file from remote host?

flamingo:~ jnojr$ ssh -t macbook sudo -v Password: Connection to macbook closed. flamingo:~ jnojr$ ssh -t macbook sudo cat /etc/cma.conf | grep CMABuildNumber <CMABuildNumber>2918</CMABuildNumber> Connection to macbook closed. flamingo:~ jnojr$ ssh -t macbook sudo -k Connection to macbook... (3 Replies)
Discussion started by: jnojr
3 Replies

7. UNIX for Advanced & Expert Users

Using remote rsync, but copy locally?

I'm looking to use rsync to compare remote files and to copy the diff to a local directory, rather than transfer over the net. The net connection is not fast enough to transfer these files (~1.8TB) and I'd like to sneakernet them instead. Possible? (4 Replies)
Discussion started by: dfbills
4 Replies

8. UNIX and Linux Applications

invoke remote graphical application..and display locally

Hi, I want to invoke(run) a graphical application remotely, and the display should be in remote itself. (no X redirect).i want to do this through ssh. like if i login to a remote machine and run firefox it should display there itself. how can i do this..? (2 Replies)
Discussion started by: madhusudankh
2 Replies

9. UNIX for Dummies Questions & Answers

how to mount a file system of a remote machine to local file system

Hi friends, In my case, there are serveral PCs running Linux in a LAN. I would like to to mount the directory /A_river of machine-A to the file system of another machine machine-B so that I can access files in that directory. I do not know how to do this. The situation is complicated by... (2 Replies)
Discussion started by: cy163
2 Replies

10. Filesystems, Disks and Memory

reading unix file system from windows

I found a more appropriate section to post my question. Thanks! (0 Replies)
Discussion started by: cneill
0 Replies
Login or Register to Ask a Question