ssh error


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users ssh error
# 8  
Old 05-06-2010
How about ...

Code:
[house@leonov] df -h .
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda4             375G  140G  236G  38% /home
[house@leonov] df -h . | tail -1 | awk -F ' ' '{print $5}' | sed 's/\%//'
38

# 9  
Old 05-06-2010
Quote:
Originally Posted by apsprabhu
Hi

now another problem has come up.

inside the ssh iam using the following command
Code:
 df -h . |tail -1 |cut -d'%' -f1 |awk '{print $NF}'

this should ideally give only the use%. however its displaying me the entire like like below,

Code:
                       48G   43G  5.3G  89

Please help.
Hi.

My guess would be that the shell is trying to evaluate $NF - which evaluates to nothing, leaving just print (which prints the whole line).

Try:
Code:

 df -h . |tail -1 |cut -d'%' -f1 |awk '{print \$NF}'

# 10  
Old 05-06-2010
MySQL

Code:
df -h . |tail -1 |cut -d'%' -f1 |awk '{print $4}'

# 11  
Old 05-06-2010
scottn is right


Code:
[root@localhost ~]# df -h . |tail -1 |cut -d'%' -f1 |awk '{print $NF}'
57

[root@localhost ~]# ssh localhost "df -h . |tail -1 |cut -d'%' -f1 |awk '{print $NF}'"
root@localhost's password: 
/dev/sda5              29G   16G   13G  57

[root@localhost ~]# ssh localhost "df -h . |tail -1 |cut -d'%' -f1 |awk '{print \$NF}'"
root@localhost's password: 
57

@ygemici
your solution wont work either, because of the unmasked $ in awk
Code:
[root@localhost ~]# ssh localhost << EOF
> df -h . |tail -1 |cut -d'%' -f1 |awk '{print $4}'
> EOF
Pseudo-terminal will not be allocated because stdin is not a terminal.
root@localhost's password: 
/dev/sda5              29G   16G   13G  57

# 12  
Old 05-10-2010
Thanks experts, still i'm in problem.

Now
Code:
" df -h . |tail -1 |cut -d'%' -f1 |awk '{print \$NF}' "

gives the desired result, however if I use that code inside a if condition (listed below) it is not working properly.


Code:
if [ `df -h . |tail -1 |cut -d'%' -f1 |awk '{print \$NF}'` -ge 85 ]; then
echo -e "File system is  above 85% full, hence removing the below files..."
find . -name "*.log.gz" -mtime +10
#find . -name "*.log.gz" -mtime +10  -exec rm -f {} \;
echo -e "File system is 100% full, hence compressing the below files..."
find . -name "*.log" -mtime +7
#find . -name "*.log" -mtime +7  -exec gzip {} \;

As the above if statement didn't work,control is not coming inside the if condition. When i tried to use the below variable in if statement, it also fails. when i do echo of $fs_usage, it displays nothing.

Code:
fs_usage=`df -h . |tail -1 |cut -d'%' -f1 |awk '{print \$NF}'`


I'm really trired with this cript. Is there any other way to do some operation (cleanup operation) based on the filesystem usage in ssh?

Last edited by apsprabhu; 05-10-2010 at 04:57 PM.. Reason: amend
# 13  
Old 05-17-2010
Please help

Experts,

Please help me on this.
# 14  
Old 05-17-2010
I would start by losing the backticks... they really are nothing but trouble (as a general rule STOP using them, PERIOD - anywhere - forever! Smilie)

Change:
Code:
if [ `df -h . |tail -1 |cut -d'%' -f1 |awk '{print \$NF}'` -ge 85 ]; then

to:
Code:
if [ \$(df -h . |tail -1 |cut -d'%' -f1 |awk '{print \$NF}') -ge 85 ]; then

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error with script for ssh

Hi, I'm getting error while getting output of home directories for multiple servers. Could anyone please help; (using HP-UX; shell=ksh) SERVERLIST=serverlist.txt OUTPUTLIST=output.txt for host in $(cat ${SERVERLIST}) do ssh $(host) "`hostname`;`echo $HOME`" > ${OUTPUTLIST} done... (9 Replies)
Discussion started by: sam_bd
9 Replies

2. Shell Programming and Scripting

Ssh command error

Hello, I have simple ssh command which is throwing "syntax error: `(' unexpected" error. Below is the command. Could someone please advise on whats wrong with command. #!/bin/bash ssh user@host "ENDJOB JOB(I5OSDRV)" I have tried `,'. but no luck. Thanks. (4 Replies)
Discussion started by: s_linux
4 Replies

3. Shell Programming and Scripting

Error in SSH output.

Hi All, I am using below command in a shell script. ssh -q RemoteUser@RemoteServer "/export/sctipt/test.ksh" It is executing succesfully but the below is the output getting displayed. tset: standard error: Invalid argument Can you please help me in understanding below. ... (8 Replies)
Discussion started by: Girish19
8 Replies

4. Red Hat

Ssh error

ssh -q <remote_server> <command> is not working for only one remote server. From the source, we are able to connect other servers using the above command but one. All the servers are in same network and no selinux/iptables enabled. The verbose output has the following message - debug1:... (4 Replies)
Discussion started by: atanubanerji
4 Replies

5. Cybersecurity

SSH syntax error

I have been asked to look at a problem with implementing SSH on an HP-UX server which a colleague has set up. Users connect through PuTTY. When I try to establish a connection I see the following message: Usage: -ssh host Options: -l user Log in using this user name. -n ... (6 Replies)
Discussion started by: j_wealleans
6 Replies

6. UNIX for Dummies Questions & Answers

ssh-keygen error

Hi, I using ssh-keygen for passwordless authenciation firstly and I am following these steps mentioned below... 1) Login to pngpcdb1 using your user/pass 2) type 'bash' (without quotes) 3) ssh-keygen #generates private and public key. 4) copy this private key to the location of your sftp... (1 Reply)
Discussion started by: karan2597
1 Replies

7. Ubuntu

ssh error in Ubuntu 9.10

I 'm getting following error when i do #ssh localhost or # ssh ip ssh: cannot connect to localhost at port 22: Address family not supported by protocol. what could be the reason for this .. i 'm new to ubuntu and having hard time getting the VM online on network (4 Replies)
Discussion started by: fugitive
4 Replies

8. UNIX for Advanced & Expert Users

ssh error: Error reading response length from authentication socket

Hi - I am getting the error `Error reading response length from authentication socket' when I ssh from my cluster to another cluster, and then back to my cluster. It doesn't seem to affect anything, but it's just annoying that it always pops up and tends to confuse new users of the cluster. I... (1 Reply)
Discussion started by: cpp6f
1 Replies

9. Linux

SSH upload error

I am trying to upload a file using SSH . it gives me error "Encounteted 1 errors during the transfer" WHere do I see the error ? why am i getting it ? thanks :) (1 Reply)
Discussion started by: upirate
1 Replies

10. UNIX for Advanced & Expert Users

ssh connection error

I am trying to get my CVS client to connect to the repository over ssh. ssh works - I can quite happily log on but when I use the client - which incidentally is eclipse 2.1.3 on Windows using plink/puTTY as an external connection method - I get the following error in /var/log/secure: error:... (2 Replies)
Discussion started by: Jdogg
2 Replies
Login or Register to Ask a Question