df command for listing 90% + dirs and hostname condition

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support df command for listing 90% + dirs and hostname condition
# 1  
Old 02-13-2012
df command for listing 90% + dirs and hostname condition

Code:
 df -k | grep -v  dcs |grep -v Filesystem| awk -F" " '{if(substr($5,0,length($5)-1)>87)print $5" " $6}' >> sms.txt

1) Is it the correct way to list all the filesystems > 90%
2) Is there any way to print hostname in this command ? The hostname should get printed in sms.txt file only when there exists filesystems > 90%.
If there is no file system > 90 % hostname should NOT get printed in sms.txt file.
# 2  
Old 02-13-2012
try this.

Code:
 
h=$(hostname);df -k | awk -v h="$h" '!/dcs/ && NR>1 {if(substr($5,0,length($5)-1)>87)print h" "$5" " $6}' >> sms.txt

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 02-13-2012
thanks itkamaraj but i am getting

awk: syntax error near line 1
awk: bailing out near line 1


Quote:
Originally Posted by itkamaraj
try this.

Code:
 
h=$(hostname);df -k | awk -v h="$h" '!/dcs/ && NR>1 {if(substr($5,0,length($5)-1)>87)print h" "$5" " $6}' >> sms.txt

# 4  
Old 02-13-2012
can you post the command you tried.
This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 02-13-2012
Hi itkamaraj,
I tried following
1.typing following command at command prompt

Code:
 h=$(hostname);df -k | awk -v h="$h" '!/dcs/ && NR>1 {if(substr($5,0,length($5)-1)>87)print h" "$5" " $6}' >> sms.txt

2.same command in sh script file.
3.same command in bash script file.

I also tried changing h=$(hostname) to h=`hostname` but I am getting same error in all above cases..
error
awk: syntax error near line 1
awk: bailing out near line 1

FYI I am using Solaris
uname -v
Generic_122300-60

Thanks,
Ajay


Quote:
Originally Posted by itkamaraj
can you post the command you tried.
# 6  
Old 02-13-2012
use nawk instead of awk
This User Gave Thanks to itkamaraj For This Post:
# 7  
Old 02-14-2012
Thanks itkamaraj this is working but when i connect to the another server using ssh then hostname it takes is actually previous server ...
e.g.

Code:
ssh userid@servername
h=`hostname`;df -k | nawk -v h="$h" '!/dcs/ && NR>1 {if(substr($5,0,length($5)-1)>88)print h" "$5" " $6}' >> sms.txt

Above code should display servername in the ssh command but it is displaying the servename from where i am running this script.

Please advise.
Thanks,
Ajay

Quote:
Originally Posted by itkamaraj
use nawk instead of awk
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Looking for command line to find dirs based on size and date

Hi, My first time on this site, please excuse me if I've come to the wrong forum. I'm fairly new to Unix/Linux and hoping you can help me out. I'm looking for a command line that will return a list of directories that are larger than 50M and older than 2 days. I thought it may be... (6 Replies)
Discussion started by: Wisconsingal
6 Replies

2. Shell Programming and Scripting

if condition to check the hostname (unix)

I want to know the if condition in checking the hostname in unix and then running a cron job (all in a single line) Thanks (2 Replies)
Discussion started by: prash358
2 Replies

3. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

4. UNIX Desktop Questions & Answers

hostname in command prompt

Hello, all. Running 11.04. Is there a way that, in an ssh or telnet session, that hostname will not appear in the command prompt? Not logged in yet, so not seeking a user shell environment. I just want to see something like 'login>', not 'ubuntu login>'. ---------- Post updated at 07:50 PM... (3 Replies)
Discussion started by: mfearer
3 Replies

5. Red Hat

Hostname command issue

Hi All, I am using redhat Linux 5.2.2 on vmware. I have created VM Machine using kickstart & rest 10 machines i created using vmware cloning. On the base machine which i installed from kickstart its showing FQDN using hostname --fqdn but cloned machines are showing hosts name i have chnaged... (1 Reply)
Discussion started by: ajaincv
1 Replies

6. UNIX for Dummies Questions & Answers

**HELP** how to do a listing of dirs and all sub dirs only

I am trying to get a listing of ALL directories only under /export (as an example). I can get all the dirs directly under /export but I need any sub dirs under those dirs. I've looked (here and google) but can not find anything that works (4 Replies)
Discussion started by: bbraml
4 Replies

7. Shell Programming and Scripting

Not correct processing of “\ “ in names of dirs inside shell script (tar command - system backup scr

Hello, Recently, I've started with shell scripting, and decided to write a script for my system backup using tar. When I was dealing with tar execution inside shell script I found this, inside shell we have the following code: tar $TAR_PARAMS $ARCHIVE_FILE $EXCLUDE $BACKUP_STARTwith... (6 Replies)
Discussion started by: ilnar
6 Replies

8. AIX

Command last displays wrong hostname

I faced an interesting problem on my AIX servers. When I checked last logins with command last I saw that hostnames are wrong. Let say, I made login from workstation xxxxx and with the command last I saw: root pts/2 yyyyy 5 jan 15:38 still logged in Ping xxxxx and ping... (3 Replies)
Discussion started by: giovanni
3 Replies

9. Shell Programming and Scripting

Find command and pruning .dirs

I'm sure this has been asked before but I couldn't find it with the search. I have a script that looks for files and then moves to another location for further processing. My problem is I can't seem to prune the .s* directories. It doesn't break anything just wanted a cleaner process. Here... (4 Replies)
Discussion started by: jcalisi
4 Replies

10. Solaris

How to display hostname in command prompt

Anyone know How to configure solaris 8 to display hostname in command prompt , everytime when you open a terminal screen . (3 Replies)
Discussion started by: civic2005
3 Replies
Login or Register to Ask a Question