# using awk remotely

**URL:** <https://community.unix.com/t/using-awk-remotely/215916>\
**Category:** Shell Programming and Scripting\
**Created:** [October 10, 2008, 12:06pm UTC](https://community.unix.com/t/using-awk-remotely/215916 "2008-10-10T12:06:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hcclnoodles](https://community.unix.com/letter_avatar/hcclnoodles/32/6_449c533f586939b6e5f246632a46421f.png) [@hcclnoodles](https://community.unix.com/u/hcclnoodles)\
**Post date:** [October 10, 2008, 12:06pm UTC](https://community.unix.com/t/using-awk-remotely/215916/1 "2008-10-10T12:06:10Z")

</div>

Hi there

I am trying to add up the disk space used on a remote linux box but am falling at the first hurdle i.e isolating the 'space used' column with df -k on the remote box

if i run this, i get the df -k output as expected

```nohighlight
# rsh remote-server 'df -k|grep sd|grep -v boot' 
/dev/sda3 8254272 1672956 6162020 22% /
/dev/sdb4 140258988 13405152 119729012 11% /data
/dev/sda4 123648020 32828 117334180 1% /data1 

```

which is fine, however I want to isolate the third column, so that i can add use some additional logic to add the values to give me a total space used by that box

so i tried

```nohighlight
# rsh remote-server 'df -k|grep sd|grep -v boot|awk {print $3} '
awk: cmd. line:2: (END OF FILE)
awk: cmd. line:2: parse error

```

I tried using cut, but setting the delimiter to " " (ie space) it messes up all the columns

does anybody have any idea how i can get around this ?

any help would be great

---

<div class="post-metadata">

**Author:** ![avronius](https://community.unix.com/letter_avatar/avronius/32/6_449c533f586939b6e5f246632a46421f.png) [@avronius](https://community.unix.com/u/avronius)\
**Post date:** [October 10, 2008, 12:19pm UTC](https://community.unix.com/t/using-awk-remotely/215916/2 "2008-10-10T12:19:32Z")

</div>

try this:

```nohighlight
rsh remote-server "df -k | grep sd | grep -v boot | awk '{print $3}'"

```

---

<div class="post-metadata">

**Author:** ![rubin](https://community.unix.com/user_avatar/community.unix.com/rubin/32/743_2.png) [@rubin](https://community.unix.com/u/rubin)\
**Post date:** [October 10, 2008, 1:57pm UTC](https://community.unix.com/t/using-awk-remotely/215916/3 "2008-10-10T13:57:30Z")

</div>

Or maybe this might help,

```nohighlight
rsh remote-server <<'EOF'

   df -k | awk '/sd/ && !/boot/ { print $3 }'

EOF

```

... And awk has its own search capabilities.

---

<div class="post-metadata">

**Author:** ![vidyadhar85](https://community.unix.com/user_avatar/community.unix.com/vidyadhar85/32/997_2.png) [@vidyadhar85](https://community.unix.com/u/vidyadhar85)\
**Post date:** [October 10, 2008, 8:34pm UTC](https://community.unix.com/t/using-awk-remotely/215916/4 "2008-10-10T20:34:56Z")

</div>

yea awk has its own search capability but grep is much faster than awk..  
this is my personal experience:)

---

<div class="post-metadata">

**Author:** ![hcclnoodles](https://community.unix.com/letter_avatar/hcclnoodles/32/6_449c533f586939b6e5f246632a46421f.png) [@hcclnoodles](https://community.unix.com/u/hcclnoodles)\
**Post date:** [October 13, 2008, 4:44am UTC](https://community.unix.com/t/using-awk-remotely/215916/5 "2008-10-13T04:44:12Z")

</div>

I tried the double quote option and I got this

```plaintext
# rsh remote-server "df -k | grep sd | grep -v boot | awk '{print $3}'"
/dev/sda3 8254272 1672772 6162204 22% /
/dev/sdb4 140258988 12922912 120211252 10% /data_store
/dev/sda4 123648020 32828 117334180 1% /data_store1

```

i.e. it didnt print column 3 on its own!

> [@rubin](#):
>
> Or maybe this might help,
> 
> ```plaintext
> rsh remote-server <<'EOF'
> 
> df -k | awk '/sd/ && !/boot/ { print $3 }'
> 
> EOF
> 
> ```
> 
> ... And awk has its own search capabilities.

unfortunately I got this

```plaintext
# rsh remote-server <<'EOF'
> df -k | awk '/sd/ && !/boot/ { print $3 }'
> EOF
tcgetattr: Inappropriate ioctl for device
ioctl I_FIND ttcompat: Inappropriate ioctl for device

```

any other suggestions ?

---

<div class="post-metadata">

**Author:** ![radoulov](https://community.unix.com/user_avatar/community.unix.com/radoulov/32/489_2.png) [@radoulov](https://community.unix.com/u/radoulov)\
**Post date:** [October 13, 2008, 6:27am UTC](https://community.unix.com/t/using-awk-remotely/215916/6 "2008-10-13T06:27:06Z")

</div>

Yes:

```nohighlight
rsh host 'df -k | awk "/sd/ && !/boot/ { print \$3 }"'

```

---

<div class="post-metadata">

**Author:** ![hcclnoodles](https://community.unix.com/letter_avatar/hcclnoodles/32/6_449c533f586939b6e5f246632a46421f.png) [@hcclnoodles](https://community.unix.com/u/hcclnoodles)\
**Post date:** [October 13, 2008, 6:40am UTC](https://community.unix.com/t/using-awk-remotely/215916/7 "2008-10-13T06:40:19Z")

</div>

> [@radoulov](#):
>
> Yes:
> 
> ```plaintext
> rsh host 'df -k | awk "/sd/ && !/boot/ { print \$3 }"'
> 
> ```

thats fantastic

now i just need to find a way of adding them up, thanks again for all your help guys

---

<div class="post-metadata">

**Author:** ![radoulov](https://community.unix.com/user_avatar/community.unix.com/radoulov/32/489_2.png) [@radoulov](https://community.unix.com/u/radoulov)\
**Post date:** [October 13, 2008, 6:44am UTC](https://community.unix.com/t/using-awk-remotely/215916/8 "2008-10-13T06:44:58Z")

</div>

```nohighlight
rsh host '
  df -k | 
    awk "/sd/ && !/boot/ { t += \$3; print \$3 }  
      END { print \"Total:\", t }"
      '

```

---

<div class="post-metadata">

**Author:** ![hcclnoodles](https://community.unix.com/letter_avatar/hcclnoodles/32/6_449c533f586939b6e5f246632a46421f.png) [@hcclnoodles](https://community.unix.com/u/hcclnoodles)\
**Post date:** [October 13, 2008, 10:15am UTC](https://community.unix.com/t/using-awk-remotely/215916/9 "2008-10-13T10:15:51Z")

</div>

wow, thank you very much
