using awk remotely


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using awk remotely
# 1  
Old 10-10-2008
using awk remotely

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

Code:
# 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

Code:
# 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
# 2  
Old 10-10-2008
try this:
Code:
rsh remote-server "df -k | grep sd | grep -v boot | awk '{print $3}'"

# 3  
Old 10-10-2008
Or maybe this might help,

Code:
rsh remote-server <<'EOF'

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

EOF

... And awk has its own search capabilities.
# 4  
Old 10-10-2008
yea awk has its own search capability but grep is much faster than awk..
this is my personal experienceSmilie
# 5  
Old 10-13-2008
I tried the double quote option and I got this

Code:
# 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!

Quote:
Originally Posted by rubin
Or maybe this might help,

Code:
rsh remote-server <<'EOF'

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

EOF

... And awk has its own search capabilities.


unfortunately I got this

Code:
# 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 ?

Last edited by hcclnoodles; 10-13-2008 at 06:21 AM..
# 6  
Old 10-13-2008
Yes:

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

# 7  
Old 10-13-2008
Quote:
Originally Posted by radoulov
Yes:

Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run yes/no script remotely

I have this script in server2 # cat /root/yesno.sh #!/bin/bash read -p "are you sure?" -n 1 -r if $ ]]; then echo "" echo "YES" else echo "NO" fi # sh /root/yesno.sh are you sure?y YES (5 Replies)
Discussion started by: anil510
5 Replies

2. Solaris

SSH Remotely

Hello. I am trying to ssh and run a script from a remote computer. These computers will be both Windows and MACs. I am using Solaris 8 and what I have tried is: using putty ssh user@ip_address (remote command) /folder/folder/filename.sh The issue here is that the user profile has not... (3 Replies)
Discussion started by: jkmtm
3 Replies

3. Solaris

user not connecting remotely

hi , I have created a user using useradd command in solaris 10 , when i connect to user oracle remotely from xmanager it is not connecting any idea did we have assign some extra privileges to connect remotely from xmanager. Thanks in advance (5 Replies)
Discussion started by: zeeshan047
5 Replies

4. Solaris

Set up new T5220 remotely

I have a new T5220 racked at our remote office and the guys who racked it does not know how to configure the SP on the system .. is there any way i can do it remotely ? (1 Reply)
Discussion started by: fugitive
1 Replies

5. Emergency UNIX and Linux Support

Shutdown all systems remotely

Hi, I am a sysadmin. During long weekends i need to turn off all machines in my lab. Is it possible to shutdown systems using ip address without using ssh. i read somewhere that shutdown -m "IPADDR" may work. However it seems its a windows specific command. So my question is how do i... (11 Replies)
Discussion started by: vickylife
11 Replies

6. Shell Programming and Scripting

Untar remotely

I need to upload tar or zip files to a unix server than unzip or untar them remotely. Any suggestions on the easiest way to do the remote untar or unzip? For example does someone know of a cgi script or something? Thanks -jz (3 Replies)
Discussion started by: jwzumwalt
3 Replies

7. Shell Programming and Scripting

Remotely executing awk command

ssh user@machine awk '{ split ($1,ar,"!");print ar}' samp >samp1 Error: Unmatched '. However on <machine> awk '{ split ($1,ar,"!");print ar}' samp >samp1 executes successfully. Any suggestions. (1 Reply)
Discussion started by: bishweshwar
1 Replies

8. Shell Programming and Scripting

if statement remotely

I need to rsh to many machines and run an " if statement' that checks the versions of the OS and if up to date it tee -a to a file called "uptodate"..then if not update, it tee -a to file called "notuptodate" on my machine the command that checks the version is cat /etc/version. now the output... (1 Reply)
Discussion started by: dxrmroue
1 Replies

9. UNIX for Advanced & Expert Users

Using CD drive remotely !

hi, could anyone tell me that how can i use a remote CD drive for installing solaris , cause my local Drive has peroblem. tell me the steps one by one. Rgrds, nikk:confused: (6 Replies)
Discussion started by: nikk
6 Replies

10. UNIX for Dummies Questions & Answers

Remotely login to one from another?

NT CONSULTANT IS NEAR TOTAL UNIX NEWBIE! Please help! I would like detailed info about how to remotely connect a PC running win'98 that is not on a local network to a unix server which is locally networked to other PCs? Would like to know how to: Move files back and forth? Mount... (2 Replies)
Discussion started by: Kagor
2 Replies
Login or Register to Ask a Question