Sponsored Content
Full Discussion: Remove % from a variable
Top Forums Shell Programming and Scripting Remove % from a variable Post 302553583 by KevinGod on Thursday 8th of September 2011 02:53:18 AM
Old 09-08-2011
Data Remove % from a variable

I have the following sh file which I originally wrote for HP Unix(which worked great)... but df is different in AIX (HP doesn't have a % in df -k), So I need to remove the % for $x at the moment I'm getting 68% I need it to be 68 so my script complete.

Any help would be welcome.. I'm sure this is a simple thing that slipped my mind..Smilie

Code:
#!/bin/ksh
# This script can be used to warn the users that the file system is getting full
#
# Below is set to monitor all the file systems mounted and report to RECEIVER
#
# Usage: as a cron entry for best use.
#set -x
RECEIVER=bja@blank.co.za,gk@blank.co.za,bki@blank.co.za
y=90
# Exclude list of unwanted monitoring, if several partions then use "|" to separate the list
EXCLUDE_LIST="/opt/IBM/TPM|/opt/IBM/SCM|/opt/IBM/ITM"
#LIST=`cat /etc/fstab|grep -v ^#|awk '{print $2}'|grep -vxE "${EXCLUDE_LIST}"`
#LIST=`cat /etc/fstab|grep -v ^#|awk '{print $2}'`
for fs in `df |awk '{ print $NF }'|grep -vxE "${EXCLUDE_LIST}"`
do
     #echo fs=$fs
     x=`df -k $fs |sed -n " p"| awk '{ print $4 }'`
     echo $x
     #echo $y
     if [ $x -gt $y ]
     then
          message="File System $fs on `hostname` is $x% used."
          #echo $subject
          echo $message | mailx -s "`hostname` - File System Full Warning !!!" $RECEIVER
     fi
done


Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks. Also refrain from overly use of font formattings as it makes editing a post very awful. Check your PMs.

Last edited by zaxxon; 09-08-2011 at 05:09 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable has spaces around the string, need to remove them

Hi all, I'm a newbie to the Linux world and I got a couple of shell script questions: (1) How do combine two variables and make it equal to a third variable? For example, I got a variable $A=FirstName, $B=LastName, and I want to combine the variable into one variable so when you echo the final... (4 Replies)
Discussion started by: mikey20
4 Replies

2. Shell Programming and Scripting

Remove non numeric values from a variable

Hello all, I am working on a basic script but need a little help. Issue: I am running a SQL Query using sqlplus and a shell script. I have the output of the statement stored as variable $A. $A is set to "other text here 45678754 other text here". I need to strip all text except that numeric... (13 Replies)
Discussion started by: ownedthawte
13 Replies

3. UNIX for Dummies Questions & Answers

Remove characters from string variable

I am running a script where one of the variables (the month and year) is input at the command line. What I would like to do is chop off the last few characters of that string to create a new variable, while maintaining the old one. The script is run like this: ./pull_station_v4.csh KYWST... (3 Replies)
Discussion started by: TheSMan5
3 Replies

4. Shell Programming and Scripting

How to remove the first character on a string in a variable

Hi all, Does anyone know how to code in ksh that will remove the first character in a string variable and replace that variable without the first character? Example: var1=ktest1 will become var1=test1 var2=rtest2 will become var2=test2 Need help please. (10 Replies)
Discussion started by: ryukishin_17
10 Replies

5. Shell Programming and Scripting

How to remove trailing spaces from a variable?

I am getting a value from a csv file using CUT command, however the command extracting the records with trailing spaces. I am using the result into a sql session to fetch data, because of the trailing spaces the sql session is unable to fetch any data. Please let me know, how to remove this... (2 Replies)
Discussion started by: mady135
2 Replies

6. Shell Programming and Scripting

PERL : Remove spaces in a variable

I have a variable I want to remove the spaces in between. The output should be How can this be done Any help will be appreciated. Thanks in advance (1 Reply)
Discussion started by: irudayaraj
1 Replies

7. Shell Programming and Scripting

How to remove new line from variable?

I have following codes: ~$ var_1="ABC" ~$ echo $var_1 | wc -m 4 ~$ echo -n $var_1 | wc -m 3 ~$ var_2=`echo -n $var_1` ~$ echo $var_2 ABC ~$ echo $var_2 | wc -m 4 ~$ I would suppose the last command ~$ echo $var_2 | wc -m would give 3; but apparently, var_2 still has the new line... (5 Replies)
Discussion started by: littlewenwen
5 Replies

8. Shell Programming and Scripting

Remove appending 0 from file variable

Dear All, i have filename RYK3201_032001002.pdf and i am using below command to get a file file_name1=$(echo $file_name | cut -d "_" -f2 | cut -d "." -f1 | cut -c -6) and then file_name2=${NewFile_NAME}_$file_name1 now the value of file_name1 will be 032001 i want to file_name1... (5 Replies)
Discussion started by: yadavricky
5 Replies

9. UNIX for Dummies Questions & Answers

Remove newline char from variable

I have a file ABC.DAT with 2 columns avaialble Data format : XYZ!$#$!120 XXZ!$#$!1000 YYZ!$#$!104 While running the following code : FILE_COUNTER=1; RECORD_CN_FILE_COUNT=$((`wc -l ABC.DAT| cut -f1 -d' '`)); while do FILE_NAME=`cat ABC.DAT.DAT| head -$FILE_COUNTER |tail -1 | awk -F... (1 Reply)
Discussion started by: Nikhil Gautam
1 Replies

10. Shell Programming and Scripting

Remove the \r \n from the variable

I a have a delimited file that has a 2 column which I need to read and pull out both columns from the file.Now the while pulling out the second column and storing in a variable I get a \r\n charachter embedded in the output when an od -c is run.How can I remove the \r\n columns from the file. ... (3 Replies)
Discussion started by: Nikhil Gautam
3 Replies
faxrm(1)						       mgetty+sendfax manual							  faxrm(1)

NAME
faxrm - remove fax jobs queued by faxspool(1) SYNOPSIS
faxrm [-i] [job-ids...] DESCRIPTION
Remove job(s) from the fax queue set up by faxspool(1). faxrm removes queued fax jobs. Call with a list of job-IDs to remove specific jobs. Call with no job IDs to be asked interactively about all jobs you own (if run by root, all jobs). For job-id, use the strings returned by faxq(1) (e.g. F000015), without the ``/JOB'' exten- tion. If you are not the owner of the fax job (as per the 'user xyz' statement inside the JOB file), you are not allowed to remove the fax job. Only root is permitted to remove another user's faxes. If the job is locked (most likely because sendfax(8) is active sending it), faxrm doesn't attempt to remove it. Instead, it prints a warn- ing message on stderr and goes on to the next job. EXAMPLES
faxrm F000005 F000033 OPTIONS
-i (interactive mode) Tells faxrm to ask for confirmation before removing the job (UNIMPLEMENTED). BUGS
faxrm doesn't return diagnostic exit codes yet. SEE ALSO
faxrunq(1), faxrunq(8), faxspool(1), faxq(1), faxqueue(5) AUTHOR
faxrm is Copyright (C) 1993-2002 by Gert Doering, <gert@greenie.muc.de>. greenie 23 Nov 02 faxrm(1)
All times are GMT -4. The time now is 08:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy